Skip to content

feat: the kit's new pieces and @frostyard/lodge-client (roadmap Phase 1) - #1

Merged
bketelsen merged 11 commits into
mainfrom
kit/new
Oct 19, 2026
Merged

bketelsen merged 11 commits into
mainfrom
kit/new

Conversation

@bketelsen

Copy link
Copy Markdown
Contributor

The new pieces of roadmap Phase 1: kit/ (the nested module github.com/frostyard/lodge/kit) and client/ (@frostyard/lodge-client), as app-contract.md and lodge-client.md specify them. The extraction of rpcserver, router and rpctest from the apps is not part of this PR.

Draft, not for merging tonight: the apps pin commits on kit/new, and the gateway's PR stacks on it.

kit/

  • kit/lodgeapp, the app-socket server:
    • LoadEnv: LODGE_ROOT, with LODGE_UID or the app's own uid in development, and user lodge in production.
    • Env.Listen: socket activation (LISTEN_FDS, and FileDescriptorName=<id> when there are several), or a new /run/lodge/apps/<id>.sock with mode 0660 (group lodge in production). A passed socket that is not a Unix socket is refused.
    • Accept closes any peer that is not lodge's uid (SO_PEERCRED) before reading from it.
    • Server: each path admits one caller kind. A request with no caller, a malformed or repeated one, the wrong kind, or an unknown path gets 403. GET /health needs no caller.
    • /api reaches the app as a net.Conn of line-delimited JSON-RPC over the WebSocket (coder/websocket, 16 MiB frames, no compression). Apps plug in the ServeConn they already have.
    • Caller, ParseCaller and SetHeaders cover D1's four identity headers, Lodge-Session, Lodge-Token and Lodge-Scope. The percent-encoding is RFC 3986.
  • kit/manifest: Parse, Validate and Load(dir) for app.json, D6's contentLinks included. lodge loads manifests with the same type.
  • kit/mcpsession: wraps any MCP Streamable HTTP handler.
    • It binds each session to its token name and scope at initialize, and answers 404 on a mismatch.
    • It keeps at most 8 sessions per token name. Past that, it evicts the least recently used one with a DELETE to the inner handler.
    • It ends a session after an hour idle.
  • kit/kittest: plays lodge's side over a socket in a temp root (Start, Attach, Do, Get, Health, DialAPI). It uses the development build's identity. CheckRules runs the contract's socket rules, and kit/internal/testapp passes them.
  • Gates: every make gate now runs in both modules. A new internal/repocheck rule fails if kit/ imports tailscale.com or any lodge package outside kit/.

client/

  • The app half: connectLodge, apiURL, contentURL, route, context, open, openSwitcher, storageKey, on and history. It includes the capture-phase shortcut listener. Outside a frame it replaces the page with the app's canonical URL.
  • The shell half (@frostyard/lodge-client/shell):
    • one port per frame, with origin and source checks;
    • init in answer to ready, with navigates queued until then;
    • mismatched and unresponsive (10 s) frames;
    • resolveOpen for the open message.
  • Shipped as TypeScript source, with no runtime dependencies and no build step. That lets it work as a pnpm git dependency in a subdirectory: github:frostyard/lodge#<sha>&path:client.
  • Toolchain: dev/nsl/provision.sh sets up the nsl lodge machine with Node 24.21.0, pinned and checksum-checked, and pnpm 12.10.1 through corepack. make client-check runs Biome, tsc and Vitest there, and the new client CI job runs the same.

Spec changes, alongside the code

  • app-contract.md:
    • a new contentLinks manifest row (D6);
    • an /api frame MAY end with one newline. The kit sends one, because the apps' current frontends split on \n.
  • lodge-http.md: the content policy for contentLinks apps. The gateway implements it.
  • AGENTS.md: the map now lists the kit's packages.

Verification

  • make check, make race cross and make client-check all pass (54 Vitest tests).
  • go get github.com/frostyard/lodge/kit@38f7be7 works from a scratch module.
  • In the nsl machine, a scratch pnpm consumer installed the client from GitHub at 5ee27a1 with &path:client. It typechecks with frostnotes' strict tsconfig and builds with Vite 8.

🤖 Generated with Claude Code

bketelsen and others added 9 commits October 18, 2026 23:05
manifest.Parse, Validate and Load check app.json against
app-contract.md's table, including D6's contentLinks.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Env and Listen: LODGE_ROOT and LODGE_UID, socket activation, or a new
  socket at /run/lodge/apps/<id>.sock with mode 0660;
- the peer check (SO_PEERCRED) before anything is read;
- the Lodge-* caller, parsed and checked into the request's context,
  with SetHeaders for lodge's side;
- each path admitting one caller kind, and GET /health without one;
- GET /api as a net.Conn of JSON-RPC lines over coder/websocket, so an
  app plugs in its existing ServeConn.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Binds each session at initialize to Lodge-Token and Lodge-Scope, answers
404 on a mismatch, keeps 8 per token name with least-recently-used
eviction, and ends a session idle for an hour.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
kittest.Start serves an app on a socket in a temp root; Do, Get,
Health and DialAPI talk to it as lodge would; CheckRules checks the
contract's socket rules. A test app passes them.

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

The kit is a nested module (kit/go.mod), so make verify, race and cross
now run in each module. internal/repocheck fails when a file of kit/
imports tailscale.com or lodge outside kit/.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- connectLodge posts ready and resolves on init, with apiURL, contentURL,
  route, context, open, openSwitcher, storageKey, on and a history driven
  by route and navigate; outside a frame it replaces the page with the
  canonical URL;
- the shortcut listener catches the init chord in the capture phase and
  posts shortcut;
- createShell keeps one port per frame: origin and source checks, init
  on ready, queued navigates, mismatched and unresponsive frames, and
  resolveOpen for the open message;
- every message is checked and copied before use.

It ships as TypeScript source, so pnpm can take it as a git dependency in
a subdirectory with no build step. It builds and tests in the nsl lodge
machine (dev/nsl/provision.sh, make client-check) and in CI.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Frames become lines and lines frames, a closed browser ends reads, binary
and oversized frames end the connection, and a passed deadline closes it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
An idle session, and what the app holds for it, stayed while no MCP
request came (security review N7). Sessions now also sweeps every Every
(a minute by default) until Close.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Off Linux the peer check (SO_PEERCRED) fails closed, so an app socket
could only drop every connection, which apps' tests saw as "connection
forcibly closed" on Windows. Now lodgeapp.Env.Listen and Server.Serve
return ErrUnsupported there, and kittest.Start and Attach skip their
test. Tests guarded by GOOS check both.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@bketelsen
bketelsen marked this pull request as ready for review October 19, 2026 13:18
@bketelsen
bketelsen merged commit fdef731 into main Oct 19, 2026
3 checks passed
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