diff --git a/docs/hermodr-extraction-plan.md b/docs/hermodr-extraction-plan.md index 2a1d59b..fdcd47f 100644 --- a/docs/hermodr-extraction-plan.md +++ b/docs/hermodr-extraction-plan.md @@ -2,14 +2,31 @@ ## Objective -Hermodr is the Eve-to-browser lowering bridge. It should subscribe to accepted -Verse state, render surfaces to browsers, carry operator intent back to the -providers that own the consequence, and — new — emit a surface as static bytes -for audiences that are not Verse participants. +Hermodr is the Eve-to-browser lowering bridge. It should resolve providers +through Odin's directory, subscribe to those providers for their state, render +their surfaces to browsers, carry operator intent back to the provider that owns +the consequence, and — new — emit a surface as static bytes for audiences that +are not Verse participants. -It currently also runs its own provider ingress and its own acceptance store, -which makes it a second Odin. This plan cuts that authority, moves the daemon -into its own repository, and adds static lowering as a second output mode. +It currently runs its own provider ingress and its own state store instead. This +plan deletes that, moves the daemon into its own repository, and adds static +lowering as a second output mode. + +## What Odin is + +Odin is a rendezvous organ. It tells you what state is available, what schemas +speak it, and where to reach it. It does not tell you what the state is, and it +is not in the data path. + +A provider owns its state and serves it. Odin owns the directory. A consumer +resolves through the directory and then talks to the provider. + +Hermodr's command path already works this way. `findProviderCommandRoute` looks +a route up in the catalog and then publishes the command to the provider's own +advertised endpoint. Erycina's surface says the same thing from the other side: +`discoveryOwner: "Odin"`, while `canonicalSurfaceUri` points at +`cultmesh://asgard.starfire.erycina/eve/operator/surface` — Odin tells you where, +you go ask Erycina. ## Current mechanism @@ -18,184 +35,189 @@ Hermodr lives in Odin as Node inside a Rust repository: `src/hermodr-daemon.cjs` (191), four PowerShell lifecycle scripts, and a persona avatar. Eve holds the browser-side consumer at `web/hermodr-provider-catalog.mjs`. -It requires five modules from `src/odin/` totalling 1,042 lines. -`src/odin-coordinator.cjs` requires eight modules from that same directory, so -`src/odin/` is a shared Node layer, not Hermodr's private library. - ### The intent path is already correct -`POST /hermodr/commands/eve` accepts a body, resolves a `cultmesh://` target -either from the body or from the provider catalog, wraps it as +`POST /hermodr/commands/eve` is generic across providers. It resolves a +`cultmesh://` target from the body or from the provider catalog, wraps intent as `gamecult.eve.command.v1`, stamps `publishedBy: "hermodr-browser-lowering"`, -publishes it as a command document to the provider's advertised route, and -returns a receipt. It is generic across providers and it does not decide -outcomes. This path is kept as-is. +publishes to the provider's advertised route, and returns a receipt. Eve's client +passes `commandSink: publishCommandIntent` into the renderer and refuses any +response that is not a correlated `gamecult.eve.command_receipt.v1` in state +`reconciled`. + +This path is kept unchanged. It is also the reference for what the state path +should look like. ### The state path is the defect -`main()` constructs its own `OdinLivePublicationSource` — an in-process `Map` -carrying both the read side (`latest`, `watch`, `watchLifecycle`) and the write -side (`accept`, `withdraw`). It then opens its own provider-session ingress, -bound to its own address with its own session token, and feeds accepted -documents into that private store. `HermodrStateStreamRegistry` watches that -store and pushes lifecycle events to browsers. +`main()` constructs an `OdinLivePublicationSource` — an in-process `Map` with a +read side (`latest`, `watch`, `watchLifecycle`) and a write side (`accept`, +`withdraw`). It opens its own provider-session ingress, bound to its own address +with its own session token, and feeds accepted documents into that private +store. `HermodrStateStreamRegistry` watches the store and pushes lifecycle +events to browsers. -So providers publish directly to Hermodr, Hermodr decides what is accepted, and -browsers see Hermodr's private view. Odin's coordinator holds a separate -instance of the same class over the same providers with no reconciliation. Which -view is correct depends on where a provider happened to bind. +So providers publish their state directly into Hermodr, and Hermodr decides what +it holds. A surface reaches a browser only if its provider binds to Hermodr, +which makes a required ingress out of something named a bridge. -A surface reaches a browser only if its provider binds to Hermodr. Hermodr is -therefore a required ingress wearing the name of a bridge. +The class is called `OdinLivePublicationSource` and lives in `src/odin/`. Odin +does not use it. Neither the coordinator nor any Odin test references it, and +the same is true of `provider-session-ingress.cjs`. This is Hermodr's own state +machinery wearing Odin's name and filed under Odin's shared modules, which is +why it reads as though Odin sanctioned it. ### The loop does not close The command path was added after the fact, on discovering the original bridge -was entirely non-interactive. It was added well: Eve's browser client passes -`commandSink: publishCommandIntent` into the renderer, controls dispatch through -it, and it refuses any response that is not a correlated -`gamecult.eve.command_receipt.v1` in state `reconciled`. +was entirely non-interactive. It was added well, but to one leg only, and the +rest still assumes a viewer. -But it was added to one leg only, and the shape of the rest still assumes a -viewer. Intent leaves correctly, over CultMesh, to the provider that owns the -consequence. The consequence then returns as newly published provider state — -and that state reaches the browser only through Hermodr's private ingress. So a -provider must publish to Odin for the Verse to be correct and to Hermodr for the -operator to see their own action land. +Intent leaves correctly, to the provider that owns the consequence. The +consequence returns as newly published provider state — and that reaches the +browser only through Hermodr's private ingress. A provider must therefore +publish twice: once wherever the Verse expects it, and once into Hermodr, so the +operator can see their own action land. -This is the core design issue, and it is not that Hermodr is missing a write -path. Intent goes out the right door and consequence comes back through the -wrong one. Cutting the acceptance authority is what closes the loop: once the -state leg is a CultMesh subscription to Odin-accepted state, a command's effect -returns by the same route as every other change, and the round trip is -genuinely bidirectional rather than two half-connected paths. +The core issue is not a missing write path. Intent goes out the right door and +consequence comes back through the wrong one. Deleting the ingress is what +closes the loop: once state arrives by subscription to the provider, a command's +effect returns by the same route as every other change. The client already carries the seed of the static case. `publishCommandIntent` checks `liveHermodr` and, when absent, logs the intent instead of posting it. -Static lowering should make that degradation explicit and visible rather than -silent, per the negative check below. ## Invariants -- Odin owns provider ingress, acceptance, and discovery. There is one accepted - view of Verse state. -- Providers own consequence. A command is a request; the provider decides. -- Hermodr owns the browser edge: session, transport, lowering, and the relay of - intent. It owns no accepted state. +- A provider owns its state and serves it. Nothing else holds it as truth. +- Odin owns the directory: what exists, what schema, where. Never the data path. +- Hermodr owns the browser edge: session, transport, lowering, relay of intent. + It holds projections with sequence numbers, never truth. - A lowering runtime cannot make something true by rendering it. -- Static output carries no back-channel, and must not pretend otherwise. +- Static output carries no back-channel and must not pretend otherwise. ## Authority map -**Owner.** Odin owns provider-session ingress, live-publication acceptance and -withdrawal, and the provider catalog. +**Owner.** Each provider owns its own state, its surface document, and its +command routes. Odin owns provider discovery, schema awareness, and route +advertisement. -**Inputs to Hermodr.** Odin-accepted state over CultMesh; provider-advertised -surface documents; provider-advertised command routes; browser requests. +**Inputs to Hermodr.** Odin's catalog, to resolve providers and routes. Provider +subscriptions, for state. Browser requests. -**Outputs.** Lowered surfaces to browsers; live state streams; typed -`gamecult.eve.command.v1` documents published to provider command routes; -receipts; and static artifacts. +**Outputs.** Lowered surfaces; live state streams; typed +`gamecult.eve.command.v1` documents published to provider routes; receipts; +static artifacts. -**Derived, not owner.** Everything Hermodr holds about provider state becomes a -projection with a sequence number. Its staleness marks are display facts, not -withdrawal decisions. +**Derived, not owner.** Everything Hermodr holds about provider state is a +projection carrying a sequence number. Its staleness marks are display facts, +not withdrawal decisions. -**Forbidden writers.** Hermodr may not call `accept()` or `withdraw()`. It may -not bind a provider session. It may not author a command as itself; every -command carries the originating operator identity and is stamped as relayed. +**Forbidden writers.** Hermodr may not accept or withdraw a publication. It may +not bind a provider session. It may not author a command as itself. Odin may not +become a state relay; if a consumer can read state *from* Odin, the directory +has become the data path. -**Shared paths.** Live lowering and static lowering must render from the same -surface graph through the same composition primitive. If the two diverge -visually, the static path is wrong, not the graph. +**Shared paths.** State resolution and command routing must use the same +catalog lookup. Live and static lowering must render from the same surface graph +through the same composition primitive; if they diverge visually, the static +path is wrong, not the graph. ## Intended change -1. Hermodr subscribes to Odin-accepted state over CultMesh instead of running - ingress. `HermodrStateStreamRegistry` survives untouched: it only consumes +1. Delete the ingress and the private store. Hermodr resolves a provider through + the catalog, exactly as the command path already does, and subscribes to that + provider for state. +2. `HermodrStateStreamRegistry` survives untouched. It consumes only `source.forProvider(id).watchLifecycle(schemaId, recordKey, cb)`, which is - already a narrow port. Replace what sits behind that port with a CultMesh + already a narrow port. Replace what sits behind that port with a provider subscription client and every stream, sequence number, and browser keeps working. -2. Extract the daemon to `GameCult/Hermodr`. -3. Add static lowering as a library with a CLI entry point. +3. Extract the daemon to `GameCult/Hermodr`. +4. Add static lowering as a library with a CLI entry point. ## Cut line -Deleted from Hermodr: +Deleted outright: - the `OdinLivePublicationSource` construction and every write into it -- `createProviderSessionIngress` and the `--provider-session-bind` and +- `createProviderSessionIngress`, and the `--provider-session-bind` and `--provider-session-token` options -- `src/odin/live-publication-source.cjs` and - `src/odin/provider-session-ingress.cjs` as Hermodr dependencies; both stay in - Odin, which is their real owner -Moved out of Odin: +Leaves Odin with Hermodr, because Odin never used it: + +- `src/odin/live-publication-source.cjs` and + `src/odin/provider-session-ingress.cjs`, both referenced only by + `hermodr-daemon.cjs` and `test/hermodr-live-publication.test.cjs`. They are + misfiled Hermodr code, not shared Odin modules. If the subscription client + fully replaces them, they are deleted rather than moved. +- `src/odin/utils.cjs` (68 lines), also Hermodr-only. Copy the handful of + helpers actually used; do not extract a utility library. + +Moved out of Odin, for its own reasons: - `src/odin/idunn-rudp.cjs` (324 lines) follows Idunn to `GameCult/Idunn` as a - published health-client contract. Odin and Hermodr then both consume it from - its owner rather than each carrying a copy. + published health-client contract. Genuinely shared — the coordinator and a + health test use it too — so both consume it from its owner rather than each + carrying a copy. Resolved, not copied: -- `src/odin/documents.cjs` (536 lines) survives as a decode contract. It must - become a published shared package. Forking it creates two definitions of the - same wire format, which is the failure this plan exists to remove. -- `src/odin/utils.cjs` (68 lines) is generic helpers. Copy the handful Hermodr - uses, or fold them into the shared package. Do not extract a utility library. +- `src/odin/documents.cjs` (536 lines) is the only true shared dependency, used + by the coordinator, Hermodr, and two discovery tests. It survives as a decode + contract and must become a published package. Forking it creates two + definitions of one wire format, which is the failure this plan exists to + remove. ## Subtraction budget -Hermodr loses its ingress, its acceptance store, and two of its five Odin -imports. Odin loses the Node daemon, its four lifecycle scripts, and -`idunn-rudp.cjs`. One shared document package appears. Net: one process's worth -of duplicated acceptance authority removed, one package added, one repository -added. +Hermodr loses its ingress and its state store. Odin loses the Node daemon, four +lifecycle scripts, three misfiled Hermodr modules, and `idunn-rudp.cjs`. One +shared document package appears. Net: a duplicate acceptance authority deleted, +`src/odin/` reduced from fourteen modules to ten, one package added, one +repository added. The static lowering library is the only genuinely new surface. It earns its keep by making public storefronts hostable without a mesh, a runtime, or a daemon — -which is the difference between a founding creator being able to self-host and -not. +the difference between a founding creator being able to self-host and not. ## Build budget -Node only; no Rust targets change. Odin's Rust crates are untouched. The new -repository is one package with a test target. Static lowering adds a CLI binary -to that same package, not a second package. +Node only; no Rust targets change. Odin's crates are untouched. The new +repository is one package with a test target, and static lowering adds a CLI +entry to that same package rather than a second package. ## Phases **Phase 1 — Idunn RUDP client.** Move `src/odin/idunn-rudp.cjs` to the Idunn repository and consume it from there. Independent of everything else, correct -regardless of whether Hermodr ever moves, and shrinks the surface first. +regardless of whether Hermodr ever moves. -**Phase 2 — Cut the authority, in place.** Before moving any files. Replace the -private source with a CultMesh subscription behind the existing port, delete the -ingress, delete the options. Hermodr still lives in Odin at this point and must -still serve browsers correctly. If this phase cannot pass its checks, the -extraction is not ready. +**Phase 2 — Delete the ingress, in place.** Before any file moves. Replace the +private store with a provider subscription behind the existing port, delete the +ingress and its options. Hermodr still lives in Odin here and must still serve +browsers correctly. If this cannot pass its checks, the extraction is not ready. -**Phase 3 — Publish the document contract.** `documents.cjs` becomes a shared -package consumed by both Odin and Hermodr. +**Phase 3 — Publish the document contract.** `documents.cjs` becomes a package +consumed by both Odin and Hermodr. -**Phase 4 — Extract.** Move the daemon, state stream, tests, and lifecycle -scripts to `GameCult/Hermodr`. MIT, matching the rest of the chain, so a -self-hosting creator may actually run it. +**Phase 4 — Extract.** Move the daemon, state stream, tests, lifecycle scripts, +and the Hermodr-only modules to `GameCult/Hermodr`. MIT, matching the rest of the +chain, so a self-hosting creator may actually run it. -**Phase 5 — Static lowering.** Library plus CLI in the new repository. It must -be runnable without starting the daemon; requiring the daemon reintroduces the -dependency static lowering exists to remove. +**Phase 5 — Static lowering.** Library plus CLI in the new repository, runnable +without starting the daemon. Requiring the daemon reintroduces the dependency +static lowering exists to remove. ## Verification Positive: -- A surface published only to Odin reaches a browser through Hermodr. This - fails today and is the point of the work. +- A provider that publishes only to its own advertised address reaches a browser + through Hermodr. This fails today and is the point of the work. - Live state streams keep their sequence numbers, and stale and reconnected transitions still fire across a provider restart. -- A browser command still reaches its provider and returns a receipt. +- A browser command still reaches its provider and returns a correlated receipt. - Static output of a surface renders equivalently to the live lowering of the same graph. @@ -205,23 +227,23 @@ Negative, and these are the ones that prove the authority moved: gone, not merely unused. - Starting Hermodr with the removed ingress options fails loudly rather than silently ignoring them. -- With Hermodr running and Odin stopped, browsers see stale state and no new - acceptances. Hermodr must not paper over Odin's absence by accepting - publications itself. -- Two Hermodr instances against one Odin show the same accepted state. Today - they would not. +- With Odin stopped, Hermodr cannot resolve providers it has not already + resolved, but existing provider subscriptions keep delivering. If stopping + Odin stops live state, Odin is in the data path and this plan failed. +- Nothing reads state *from* Odin. A consumer able to do so proves the directory + became a relay. +- Two Hermodr instances against the same provider show the same state. - Static output contains no command controls that appear operable. A dead button in a static page is a lie about a back-channel that does not exist. ## Open questions for the operator 1. **`documents.cjs` ownership.** Published from Odin, or promoted into CultLib - beside the other typed contracts? It is a wire format two services share, + beside the other typed contracts? It is a wire format several services share, which argues for CultLib, but Odin authors it. 2. **Ephemeral view state.** Expanded panels, unsent field contents, optimistic - pending states. Client-side today by omission rather than decision. Leaving - it client-side is defensible; it should be a decision. -3. **Static lowering and identity.** A live surface knows who is viewing. A + pending states. Client-side today by omission rather than decision. +3. **Static lowering and identity.** A live surface knows who is viewing; a static artifact does not. Either static surfaces are public-only, or the lowering takes an audience parameter and emits per-audience artifacts. Public-only is smaller and covers the storefront.