Skip to content

refactor(api): run notesd's JSON-RPC on lodge kit's jsonrpc runtime - #56

Merged
bketelsen merged 79 commits into
mainfrom
m4/kit
Oct 19, 2026
Merged

bketelsen merged 79 commits into
mainfrom
m4/kit

Conversation

@bketelsen

@bketelsen bketelsen commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

notesd's JSON-RPC runtime now comes from lodge's kit (kit/jsonrpc, kit/rpctest) at d74fbcc1a0d1, the head of the draft frostyard/lodge#4, instead of notes' own copies. The generated contract is unchanged: api/zz_generated.go, tools/rpcgen, the schemas and the app are untouched (lodge ADR-0012: the kit shares the runtime, not the generator).

Go: +170 / −719 (net −549). The runtime files (api/{api,client,conn}.go, internal/rpcserver, internal/rpctest) go from 692 lines removed to 141 added.

What moved to the kit

  • api/api.go: Error, Event, EventEnvelope and handlerFunc are now aliases of the kit's types.

    • Router embeds jsonrpc.Router[Caller, ErrorCode]. RouterOptions.Admit refuses writes under a read scope (mayWrite), so a write called under a read scope still answers methodNotFound.
    • decodeParams calls jsonrpc.DecodeParams.
    • The generated handlers still check the vault a scoped call names (inScope).
  • api/client.go: Client embeds jsonrpc.Client[ErrorCode]. Dial stays notes' own.

  • api/conn.go: callers, scope and identity stay. ConnFrom wraps the kit's Conn, and Notify(Event) sends the envelope. WithConn had no users left, so it is deleted.

  • internal/rpcserver: framing, the gate on rpc.hello, concurrent dispatch, panic recovery, oversized replies, the peer check and the private socket are the kit's now. listen_unix.go is deleted. What remains is notes' own:

    • rpc.hello: the caller and the session's identity and content key;
    • rpc.ping;
    • events.subscribe: OnClose and AfterReply → Conn.Go, the per-caller event filter, and dropping a subscriber that lags;
    • each connection's identity.

    Server.Listen is jsonrpc.Listen with notesd's logger, so rejected peers are still logged. notesd now calls srv.Listen after New.

  • internal/rpctest: its socket, serving goroutine and 5 s stop now come from kitrpctest.Serve, and DialAs uses Run.Pipe.

    • Options embeds kitrpctest.Options[api.Services]. Its Services hook replaces the Note/Hub/Sync/LogDomain fields, at the four call sites that set them.
    • socket_unix.go is deleted.
  • Tests: the rpcserver tests run on Run.Dial and Run.Pipe, which wait for the served connection at cleanup; before, a goroutine ran until the test's context ended. The wire rules, the caller kinds, events resuming after reconnect, the private socket (open directory, live socket), repeated hello, per-caller events, panics and huge replies are all still pinned here.

Behavior

The wire behavior is unchanged: the same 16 MiB limit, 32 calls in flight, notReady before hello, internal answers to a panic, and methodNotFound for a caller the method doesn't admit. The private socket keeps its semantics: dir 0700, socket 0600, a stale socket replaced, the same uid only.

The messages still name notesd, through the kit's ClientOptions{Name: "notesd"} and ListenOptions{Name: "notesd"}:

  • a second notesd says notesd is already listening on PATH;
  • the client's own errors read notesd: connection closed, write to notesd: … and notesd: malformed message: ….

Tests pin the first two. The one change is that api: connection closed is now notesd: connection closed.

Docs

ADR-0026 (Proposed) now records that the runtime is the kit's and links lodge ADR-0012. design/overview.md and AGENTS.md's map say which parts stay notes' own. The ADR-0012 link points at lodge main, so it resolves once lodge#4 merges.

Pin

github.com/frostyard/lodge/kit v0.0.0-20261019051939-d74fbcc1a0d1 is a commit on lodge#4's branch (kit/extract). If that branch is rebased before it merges, repin to the merged commit.

Changes in the kit since 9de93d8, where the simulation ran:

  • 8ce0a6a changes only off-Linux code: lodgeapp.ErrUnsupported, and kittest and rpctest skip there;
  • d74fbcc adds the name options, which change only error text.

Gates

  • make check;
  • -race on api, rpcserver, lodgeapp, mcpserver, hub and notesctl;
  • make sync-sim with SIM_SEEDS=2: seeds 1 and 2, each 10,000 steps stepwise and concurrent, plus the regressions, passed in 18.5 min. It ran on 9de93d8; make check ran again at d74fbcc.

🤖 Generated with Claude Code

bketelsen and others added 30 commits October 18, 2026 22:58
A method may list callers that narrow its domain's, and be marked
writes. Both reach the Go router and the TypeScript tables
(METHOD_CALLERS, WRITES), and the reference shows them. agent joins
the caller kinds; a method an agent may call names its vault in a
required int vaultId, which the generated handler checks against the
connection's scope (ADR-0026, plan 0006 Phase 2).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- schema: callers and writes marks as specs/lodge-app.md lists them;
  rpc.ping, rpc.hello's caller and identity, hub.setURL and
  hub.status's url, log.hub and sync.relocate.
- api: CallerAgent, Identity and Scope. Router.Dispatch refuses a
  method marked writes under a read scope, and a scoped call that
  names another vault answers notFound, as for no vault.
- rpcserver: ServeConn takes the connection's identity; rpc.hello
  reports it. The engine records a session's writes as editor,
  "<node> (web)", and an agent's as agent, its token's name,
  whatever the params say.
- hub: the recorded URL (migration 0004), log.hub, and POST
  /sync/hub's relocation proof, an HMAC keyed with the token's hash.
- syncer: a device follows log.hub at each connection, and
  sync.relocate keeps a new URL only when the hub there proves itself.
- tests: every method as each caller kind, every note method under
  another vault and a read scope, every writing method's attribution,
  and relocation against a relay, a wrong hub, a URL that differs and a
  forged proof.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
MockOptions.caller makes the mock refuse what notesd refuses a browser
inside lodge (METHOD_CALLERS), report the session's login and node from
rpc.hello, answer rpc.ping, and name a session's writes "<node> (web)",
for the web app's tests (plan 0006 Phase 2).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
sync-protocol.md gains POST /sync/hub, log.hub, sync.relocate,
hub.setURL and hub.status's url, and the rule that a device follows
log.hub at each connection; lodge-app.md says what hub.setURL accepts
and POST /sync/hub's 400 and 413; plan 0006 records the overnight
build.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Task card T-0084, implemented by the executor model and verified by taskrun.
The loop can be syncing again by the time the test reads sync.status
after its quiet point.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The development gateway's blob handler becomes internal/blobhttp, with
the limits lodge's content route needs: one range per request (416
otherwise), a range cut to MaxRange, a whole answer up to MaxWhole
(413 past it), and ?download=1's Content-Disposition.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
internal/lodgeapp builds the kit's server for notes (plan 0006 Phase 3,
docs/specs/lodge-app.md): /health with notesd's version and RPC major,
/api as caller session named by lodge's headers, /content/blobs/ with
its headers and limits, and the hub's sync routes under /device/, where
lodge's peer headers only name a pending pairing's node. lodge/kit is
pinned to 38f7be7. -hub now refuses an address that is not loopback.

Tests run over a real socket with kittest: lodge's rules (the peer
check, one caller per path, forged callers), a session that reads,
writes as its node and gets events, the blob limits at and past 8 and
64 MiB, and a device that pairs, pulls and pushes through /device/.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
packaging/lodge/app.json is lodge-app.md's manifest; a socket unit gives
lodge's group /run/lodge/apps/notes.sock, the service runs notesd -lodge
as frostnotes with its data in /var/lib/frostnotes, and sysusers.d
declares frostnotes in lodge-apps. M6 packages them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
internal/mcpserver's Handler serves MCP's Streamable HTTP transport with
one server per session, built from its token's scope: the scope's vault,
and under a read scope only the read tools. Each session's tools reach
notesd over an in-process connection of caller agent bound to the scope
(lodgeapp.Agent), which the engine enforces; its writes are the token's.
lodge/kit's mcpsession binds sessions to their token and scope (another
token's request is 404, a scope that does not parse 403), keeps 8 per
token, evicting the least recently used, and ends them after an idle
hour; the session's notesd connection closes with it (plan 0006 Phase 4,
docs/specs/mcp.md#through-lodge).

Tests use the SDK's HTTP client over the socket with lodge's headers.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
make web-build runs vite build --mode web into build/web with the base
/app/notes/ and icon.svg for lodge's rail; make lodge-app lays out
build/lodge/apps/notes with the manifest at this version. main.tsx starts
the web build from lodge/main.tsx and every other build from desktop.tsx,
so neither bundle carries the other's code. index.html's viewport has
viewport-fit=cover. @frostyard/lodge-client is pinned to lodge's
5ee27a1 (plan 0006 Phase 5).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- lodge/main.tsx: connectLodge({app: "notes"}), then connectApi() to
  lodge's apiURL(), with files by hash from contentURL("blobs/…").
- connectApi pings every 30 s while the page is visible, at once when it
  is shown, and drops a connection whose ping is unanswered for 10 s.
- Session can back off (1 s doubling to 30 s with jitter, the web app's)
  and tries at once when the page is shown, the browser is back online,
  or the frame becomes visible.
- LodgeBridge reports the active note's route (/<vault>/<path>) and
  context, opens the frame's route on load and the shell's navigate, a
  missing note opening the quick switcher, and follows the shell's theme
  while the Theme preference is System; web links go to lodge's open.
- A session sees what it may call: no sync state, and a vault manager
  that opens vaults but neither adds nor removes them.
- The web build's local storage keys start with notes:.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
lodge-client refuses a route over 2,048 characters; the bridge reports
the vault's route instead. docs: make lodge-app in app.md, and plan
0006's status.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…first

A system service has no Secret Service session, so frostnotes.service
sets FROSTNOTES_SECRETS=file. Phase 7 stops and disables the M2 hub's
unit before enabling frostnotes.service: both use /run/frostnotes.
Found deploying the overnight build beside the trial hub.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…oad it

Inside lodge, a PDF or any file the app does not show inline offers Open
in new tab, its content URL through lodge's open, and Download, the same
URL with ?download=1, where a browser will not show a file in a sandboxed
page (docs/design/app.md#in-a-browser).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Below 600 CSS pixels (the frame's width inside lodge), the main window
drops the ribbon, the title bar row, tab strips, splits and the status
bar (docs/specs/ui.md#narrow-windows, ADR-0027):

- the workspace draws the active group's active tab under a narrow view
  header: Open left sidebar, the title, Reading or Editing view, More
  options, Open right sidebar;
- the sidebars are drawers over the dimmed workspace, 84% of the width
  and at most 450, closed by a tap outside, Escape, or opening a note;
- a bottom bar of six 44-pixel buttons, above the bottom safe area:
  back, forward, the quick switcher, new tab, the tabs (the tab list),
  and the Menu (the ribbon's actions and Settings).

The swipe gestures, the tab switcher's full screen, the editing toolbar,
bottom-sheet menus, long presses and touch sizes at any width are still
to come, as cards over Obsidian's measures.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
On a hub (hub.status answers with an ID), Settings has a Hub section
(docs/specs/ui.md#in-a-browser, design/hub.md#hub-settings-in-the-app):
the hub's ID and the URL devices use, each device with when it paired
and was last seen and Revoke (after asking), and each pending pairing
with the node lodge named and the notesctl command that approves it on
the hub's machine. A session may list and revoke, never approve. The
settings dialog gains a button control; the mock a small hub domain.

The web build registers no zoom commands: zoom is the browser's.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Pasting or dropping a file into an editor, or Attach file, uploads it
  with note.upload (at most 10 MB) under the vault's attachment folder
  and a free name (a nameless pasted image is Obsidian's "Pasted image
  YYYYMMDDHHmmss.png"), and inserts ![[name]] at the cursor, the path
  when the name is not unique, a markdown image without wikilinks.
- The commands the phone toolbar needs: undo, redo, internal link,
  embed, tag, attach file, set heading (a menu), blockquote, bullet and
  numbered lists, indent and unindent.
- A narrow window shows the editing toolbar in the bottom bar's place
  while an editor has the focus, docked to the on-screen keyboard (the
  visual viewport's bottom); a tap keeps the editor's focus
  (docs/specs/ui.md#narrow-windows).

Checked in the loopback stand-in for lodge: a pasted PNG reached the
vault and showed from the content origin.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…en, when narrow

In a narrow window (docs/specs/ui.md#narrow-windows) a menu is a sheet
from the bottom, the whole width, items 44 high, above the bottom safe
area; the quick switcher and the palette take the whole width from the
top safe area, without their key hints; Settings fill the screen. A
coarse pointer makes prompt rows 44 high at any width.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A touch that rests 500 ms without moving opens the menu a right click
opens at its point, and its click is swallowed; the editor keeps its own
long press for selecting text (docs/specs/ui.md#narrow-windows). In a
narrow window a swipe that starts within 24 pixels of a screen edge and
moves 50 inward opens that side's drawer, and a swipe back toward its
edge closes it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The bottom bar's Tabs opens a full-screen list of the group's tabs
(docs/specs/ui.md#narrow-windows): each with its title and folder, a tap
to activate it, and Close at its right; New tab and Close all at its
foot; Done or Escape dismisses it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
From the security review of the overnight build: a device moved to the
URL its hub recorded and sent its token there on the next connection, so
a mistyped notesctl hub url, or a hub database someone changed, could
collect every device's token. follow now checks the host at that URL
with the relocation proof first, as sync.relocate does (shared as
proven), and stays otherwise. Also: hub URLs keep their host in lower
case, so URLs SameURL calls the same are equal strings; POST /sync/hub
logs at debug; lodge-app.md says what the endpoint reveals and what the
proof's key allows.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…mits

From the security review: http.ServeContent answers whole when If-Range
does not match, so Range: bytes=0-0 with a stale If-Range fetched a
blob of any size in one response, past lodge-app.md's 8 and 64 MiB. A
blob never changes under its hash, so the handler drops If-Range.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
bketelsen and others added 5 commits October 19, 2026 00:17
scripts/move-hub-behind-lodge.sh is plan 0006 Phase 7's move, run as
root on the hub's machine after the trial: a dry run by default that
checks lodge, the frostnotes user and units, the trial's notesd.service
and data, and the vault's CIFS mount, then with --apply --url stops the
trial unit, copies its data directory whole into /var/lib/frostnotes,
sets the mount's uid=/gid= to frostnotes, checks a write on the share,
starts the lodge socket and service, records the hub URL and reloads
lodge. The overnight deployment's test data goes aside, never merged;
any other state is refused before anything changes. Everything moved
or edited is backed up with a manifest that --rollback reads; the
rollback refuses once the hub's log has moved (devices synced through
lodge) unless --force.

scripts/move_test.go runs it against a staged root with stub commands:
the dry run, eleven refusals, apply and rollback round-trips, a failed
step, and the rollback's guard.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
An M2 notesctl found on PATH would fail at step 6, after the services
had started; the check now refuses it before anything changes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The framing, the rpc.hello gate, concurrent dispatch, panics, oversized
replies, the router's caller kinds, the client and the private socket
are lodge/kit/jsonrpc's now (lodge ADR-0012), pinned at 8ce0a6afce0d;
notes keeps its generated contract, caller kinds, scope, identities,
rpc.hello, rpc.ping and events.subscribe. The router refuses writes
under a read scope through the kit's Admit hook. internal/rpctest runs
on kit/rpctest (Serve, Pipe, Options[api.Services]); the four tests
that served a fake domain use its Services hook. listen_unix.go and
socket_unix.go go; Go is 549 lines shorter.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Bumps lodge/kit to d74fbcc1a0d1, whose ClientOptions and ListenOptions
take a name: a second notesd says "notesd is already listening on
PATH" again, and the client's own errors read "notesd: connection
closed". Tests pin both. AGENTS.md's map no longer calls lodgeapp the
kit's only importer.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@bketelsen
bketelsen changed the base branch from m4/move to main October 19, 2026 13:42
@bketelsen
bketelsen merged commit 565a0ea into main Oct 19, 2026
7 of 8 checks passed
@frostyard-machines
frostyard-machines deleted the m4/kit branch October 26, 2026 00:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant