Repository navigation
feat(kit): extract the apps' JSON-RPC runtime into kit/jsonrpc and kit/rpctest - #4
Merged
Merged
Conversation
The private socket needs it too. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Extracted from frostnotes' and frostmail's api runtime and rpcserver, generic over each app's generated ErrorCode and caller kind, so the apps' generated code sits on it unchanged: - Server: line framing, gating on the hello, concurrent dispatch, a panic answering internal, a reply over the message limit answering internal, and Conn for hello, notifications, AfterReply, Go and OnClose; - Router: caller kinds per method, an Admit hook for writes under a read scope, methodNotFound alike for all three; - Client, DecodeParams, the event envelope, and Listen for the private socket (same uid only). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Serve on a temporary private socket, Dial, Pipe a connection served as another caller, Stop; Options[S] carries frostmail's Services hook. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
tools/rpcgen and frostmail's Windows pipe stay in the apps; the roadmap, overview and map say so. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Oct 19, 2026
Brings in the Linux-only app socket fix (845a109). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
ListenWith(path, ListenOptions{Name: "notesd"}) says "notesd is already
listening on PATH", and NewClientWith(conn, ClientOptions{Name}) says
"notesd: connection closed", "write to notesd: …" and so on, as the
apps' own copies did. Listen and NewClient keep today's text. Additive
only.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #1 (
kit/new). This PR is the rest of roadmap Phase 1: the RPC machinery frostnotes and frostmail share moves into the kit. I compared frostnotes atm4/tabswitcher(4babfb7) with frostmail atlodge/desktop-app(6b85307).What's in the kit now
kit/jsonrpc, the runtime, generic over each app's ownErrorCode(C) and caller kind (K):Server[C]: line framing (16 MiB), gating on the hello (rpc.hello, run inline so a pipelined call sees the connection ready), concurrent dispatch (32 in flight). A panic answersinternal("request panicked" is logged with the method and stack), and a reply over the limit answersinternal.Servetakes a per-connection context hook, andServeConntakes connections that lodge's/apior a gateway already authenticated.Conn, reached withConnFrom(ctx):SetReady/Client,Notify,AfterReply,Go,OnCloseandClose. This covers what each app's rpcserver did by hand forrpc.helloandevents.subscribe.Router[K, C]: callers per method, plus anAdmithook (notes refuseswritesunder a read scope with it). An unknown method, a caller the method doesn't admit, and a refusal all answermethodNotFoundalike.Client[C],DecodeParams[C],Error[C],Frame[C], the event envelope, andListen.Listenmakes the private socket (dir 0700, socket 0600, stale socket replaced, same uid only), and it is Linux only.kit/rpctest:Serveon a temporary private socket,Dial,Pipe(a connection served as another caller) andStop.Options[S]holds frostmail'sServices func(*S)hook. Building the engine stays in each app's own rpctest.ADR-0012 (Proposed):
tools/rpcgenand frostmail's Windows pipe stay in the apps. The two generators differ in what a schema means:writesand thevaultIdrule;Because the runtime is generic, neither generator changes.
The test app's
/apinow runs onjsonrpc, behindlodgeapp, and is called with the kit's client throughkittest.Proof that adoption is mostly deletions
I rebuilt each app's hand-written
apiruntime andinternal/rpcserveron the kit in a scratch module. Each sat next to that app's real, unmodifiedzz_generated.goandinternal/events, and both compile and vet. frostmail's scope tests pass. The files are in the coordination notes folder (kit-extract-adoption/) for the app sessions to start from.api/api.go+client.gointernal/rpcserver/server.goapi/api.go+client.gointernal/rpcserver/server.goMigration note (what an app changes)
go get github.com/frostyard/lodge/kit@<this SHA>.api/api.go:type ErrorCode int; the generated constants andStringstill name it;type Error = jsonrpc.Error[ErrorCode], andErrorfcallsjsonrpc.Errorf;type Event = jsonrpc.Event,type EventEnvelope = jsonrpc.EventEnvelope, andNewEnvelopecalls the kit's;type Router struct{ *jsonrpc.Router[Caller, ErrorCode] }, where notes'KisCallerand mail's isCallerKind;NewRouterbuilds it withRouterOptions{Caller: …}. Notes also passesAdmit: !rt.Writes || mayWrite(ctx);handle(…), which callsr.Handle(method, jsonrpc.Route{…}). Mail passesCallers: methodCallers[method];decodeParamscallsjsonrpc.DecodeParams[ErrorCode];api/client.go:type Client struct{ *jsonrpc.Client[ErrorCode] }, andNewClientwrapsjsonrpc.NewClient[ErrorCode];Frame,MaxMessageSize,EventBuffer,EventMethodandErrEventsOverflowalias the kit's;Dial;Call.api/conn.go: keepConn, the callers, scope and identity.ConnFromfalls back tojsonrpc.ConnFrom(ctx)wrapped as aConn, whoseNotify(Event)sends an envelope.internal/rpcserver:Newmakesjsonrpc.NewServer[api.ErrorCode](ServerOptions{Hello: "rpc.hello"});ServeandServeConnput the caller and a small per-connection state in the context;Hellocallsjsonrpc.ConnFrom(ctx).SetReady(p.Client);SubscriberegistersOnClose(sub.Close)andAfterReply(→ Conn.Go(sub.Run → Conn.Notify));ListenandcheckPeerbecomejsonrpc.Listen(path, log), and frostmail keepslisten_windows.go.internal/rpctest:rpctest.Servefor the socket, the goroutine and the stop with its 5 s bound;run.PipeforDialAs;rpctest.Options[api.Services]and callo.Edit(&services)beforeNewRouter. That is frostmail's form. Notes replaces its per-domain fields with it.Not changed:
zz_generated.go,tools/rpcgen, the schemas and the frontends;api.Xused outsideapi/.Two client error strings no longer name the daemon: write and malformed-message. The connect error, in
Dial, keeps its name.Gates
make checkandmake race crosspass in both modules. The repocheck import rule still holds:kit/imports neither tailscale nor lodge internals.🤖 Generated with Claude Code