The TypeScript SDK's state reaches the runtime, a narrowed watch only its keys (novox/hq ADR 0201)

This commit is contained in:
jochen
2026-10-04 02:48:10 +02:00
parent 1adfcad88e
commit 29c24a2367
3 changed files with 59 additions and 0 deletions
+13
View File
@@ -0,0 +1,13 @@
// A module that keeps state through the SDK (novox/hq ADR 0201): it watches its servers as it is
// imported, and writes each change it is handed to STATE_LOG; one tool registers a server.
import { appendFileSync } from "node:fs";
import { state } from "@novox/mesh-sdk/state";
import { registerModuleTools } from "@novox/mesh-sdk/tools";
const servers = state("servers");
await servers.watch((c) => appendFileSync(process.env.STATE_LOG, `${c.current ? "was" : "now"} ${c.op} ${c.key}\n`));
await servers.watch((c) => appendFileSync(process.env.STATE_LOG, `narrow ${c.op} ${c.key}\n`), { key: "anchor.*" });
appendFileSync(process.env.STATE_LOG, "current\n");
registerModuleTools("sdkkeeper", () => [
{ name: "register", description: "put a server", input: {}, run: async (a) => servers.put(a.key, { url: a.url }) },
]);
+5
View File
@@ -0,0 +1,5 @@
#!/usr/bin/env node
// The launcher the builder writes beside an entrypoint (novox/hq ADR 0193), for state-sdk.mjs.
import { serveRegisteredOverStdio } from "@novox/mesh-sdk/stdio";
await import("./state-sdk.mjs");
await serveRegisteredOverStdio();