Hermodr leaves Odin
Hermodr is a browser lowering, not an all-seer organ. It lived here as Node inside a Rust repository, sharing a module directory with the coordinator, and until this week it ran its own provider ingress and accepted publications into a private store. The ingress went first on purpose: extracting it beforehand would have relocated a second acceptance authority and called that progress. Removed: the daemon, its provider subscription source and state stream, both test files, four lifecycle scripts, the persona avatar, the hermodr:start script, and src/odin/utils.cjs, whose only remaining consumer was Hermodr and which it used for one of six functions. src/odin/ falls from fourteen modules to eleven. The CommonJS surface falls from sixteen files to twelve. What is left is the coordinator, the Rust organs, and two adapters declaring contracts other repositories own. The plan document stays as the record of what left and why. Phase 5, static lowering, is Hermodr's business now. 5 tests pass, syntax check clean over twelve files. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
parent
20bacabf7c
commit
3f22fd1d76
13 changed files with 20 additions and 2173 deletions
File diff suppressed because it is too large
Load diff
|
|
@ -1,154 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
// Provider state subscription for the browser lowering.
|
||||
//
|
||||
// Hermodr previously ran its own provider-session ingress and accepted
|
||||
// publications into a private store, which made it a required ingress rather
|
||||
// than a bridge: a surface reached a browser only if its provider bound to
|
||||
// Hermodr specifically. Providers own their state. Odin publishes where to find
|
||||
// it. This source resolves a provider through the catalog and reads that
|
||||
// provider directly, exactly as the command path already routes intent.
|
||||
//
|
||||
// It presents the same narrow port the previous store did -
|
||||
// forProvider(id) -> { latest, watch, watchLifecycle } - so
|
||||
// HermodrStateStreamRegistry, its sequence numbers, and its stale/reconnected
|
||||
// transitions are untouched.
|
||||
//
|
||||
// readDocument is injected. That keeps the polling and lifecycle semantics
|
||||
// testable without a live Verse, and keeps CultMesh transport out of this file.
|
||||
|
||||
const DEFAULT_POLL_INTERVAL_MS = 2_000;
|
||||
|
||||
class ProviderSubscriptionSource {
|
||||
constructor(readDocument, options = {}) {
|
||||
if (typeof readDocument !== "function") {
|
||||
throw new Error("Provider subscription source requires a readDocument(providerId, schemaId, recordKey) function.");
|
||||
}
|
||||
this.readDocument = readDocument;
|
||||
this.pollIntervalMs = Number.isFinite(options.pollIntervalMs) && options.pollIntervalMs > 0
|
||||
? options.pollIntervalMs
|
||||
: DEFAULT_POLL_INTERVAL_MS;
|
||||
this.setInterval = options.setInterval || setInterval;
|
||||
this.clearInterval = options.clearInterval || clearInterval;
|
||||
this.onError = options.onError || (() => {});
|
||||
this.entries = new Map();
|
||||
this.sequence = 0;
|
||||
}
|
||||
|
||||
forProvider(providerId) {
|
||||
return {
|
||||
latest: (schemaId, recordKey) => this.latest(providerId, schemaId, recordKey),
|
||||
watch: (schemaId, recordKey, callback) => this.watch(providerId, schemaId, recordKey, callback),
|
||||
watchLifecycle: (schemaId, recordKey, callback) => this.watchLifecycle(providerId, schemaId, recordKey, callback),
|
||||
};
|
||||
}
|
||||
|
||||
async latest(providerId, schemaId, recordKey) {
|
||||
const value = await this.readDocument(providerId, schemaId, recordKey);
|
||||
if (value === undefined || value === null) {
|
||||
throw new Error(`Provider ${providerId} published no ${schemaId}:${recordKey}.`);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
watch(providerId, schemaId, recordKey, callback) {
|
||||
return this.watchLifecycle(providerId, schemaId, recordKey, (event) => {
|
||||
if (event.kind !== "withdrawn") callback(event.value);
|
||||
});
|
||||
}
|
||||
|
||||
watchLifecycle(providerId, schemaId, recordKey, callback) {
|
||||
const key = keyOf(providerId, schemaId, recordKey);
|
||||
let entry = this.entries.get(key);
|
||||
if (!entry) {
|
||||
entry = {
|
||||
providerId,
|
||||
schemaId,
|
||||
recordKey,
|
||||
listeners: new Set(),
|
||||
value: undefined,
|
||||
present: false,
|
||||
timer: null,
|
||||
polling: false,
|
||||
};
|
||||
this.entries.set(key, entry);
|
||||
entry.timer = this.setInterval(() => { this.poll(key); }, this.pollIntervalMs);
|
||||
if (typeof entry.timer?.unref === "function") entry.timer.unref();
|
||||
}
|
||||
|
||||
entry.listeners.add(callback);
|
||||
if (entry.present) {
|
||||
callback({ kind: "snapshot", sequence: ++this.sequence, value: entry.value });
|
||||
}
|
||||
// First listener on a cold entry still needs a value without waiting a full
|
||||
// interval. Subsequent listeners piggyback on the shared poll.
|
||||
this.poll(key);
|
||||
|
||||
let released = false;
|
||||
return () => {
|
||||
if (released) return;
|
||||
released = true;
|
||||
entry.listeners.delete(callback);
|
||||
if (entry.listeners.size === 0) {
|
||||
this.clearInterval(entry.timer);
|
||||
this.entries.delete(key);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
async poll(key) {
|
||||
const entry = this.entries.get(key);
|
||||
if (!entry || entry.polling) return;
|
||||
entry.polling = true;
|
||||
try {
|
||||
let value;
|
||||
try {
|
||||
value = await this.readDocument(entry.providerId, entry.schemaId, entry.recordKey);
|
||||
} catch (error) {
|
||||
// A read failure is not a withdrawal. The provider may be restarting,
|
||||
// and claiming withdrawal would let a transport hiccup look like the
|
||||
// provider retracting state it still holds.
|
||||
this.onError(error, { providerId: entry.providerId, schemaId: entry.schemaId, recordKey: entry.recordKey });
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.entries.has(key)) return;
|
||||
|
||||
const missing = value === undefined || value === null;
|
||||
if (missing) {
|
||||
if (entry.present) {
|
||||
entry.present = false;
|
||||
entry.value = undefined;
|
||||
this.emit(entry, { kind: "withdrawn", sequence: ++this.sequence, reason: "withdrawn" });
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (entry.present && equivalent(entry.value, value)) return;
|
||||
|
||||
const kind = entry.present ? "update" : "snapshot";
|
||||
entry.present = true;
|
||||
entry.value = value;
|
||||
this.emit(entry, { kind, sequence: ++this.sequence, value });
|
||||
} finally {
|
||||
entry.polling = false;
|
||||
}
|
||||
}
|
||||
|
||||
emit(entry, event) {
|
||||
for (const listener of entry.listeners) listener(event);
|
||||
}
|
||||
}
|
||||
|
||||
function keyOf(providerId, schemaId, recordKey) {
|
||||
if (!String(providerId || "").trim() || !String(schemaId || "").trim() || !String(recordKey || "").trim()) {
|
||||
throw new Error("Provider subscription requires providerId, schemaId, and recordKey.");
|
||||
}
|
||||
return `${providerId}\u001f${schemaId}\u001f${recordKey}`;
|
||||
}
|
||||
|
||||
function equivalent(left, right) {
|
||||
return JSON.stringify(left) === JSON.stringify(right);
|
||||
}
|
||||
|
||||
module.exports = { ProviderSubscriptionSource, DEFAULT_POLL_INTERVAL_MS };
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
class HermodrStateStreamRegistry {
|
||||
constructor(source) { this.source = source; this.entries = new Map(); }
|
||||
acquire(selection, listener) {
|
||||
const key = `${selection.schemaId}\u001f${selection.recordKey}`;
|
||||
let entry = this.entries.get(key);
|
||||
if (!entry) {
|
||||
entry = { listeners: new Set([listener]), sequence: 0, stale: false, unsubscribe: null };
|
||||
entry.unsubscribe = this.source.forProvider(selection.providerId).watchLifecycle(selection.schemaId, selection.recordKey, event => {
|
||||
const type = event.kind === "withdrawn" ? "stale" : entry.stale ? "reconnected" : event.kind;
|
||||
entry.stale = type === "stale";
|
||||
const lowered = { type, sequence: ++entry.sequence, source: selection,
|
||||
...(event.value === undefined ? {} : { value: event.value }),
|
||||
...(event.reason ? { reason: event.reason } : {}) };
|
||||
for (const subscriber of entry.listeners) subscriber(lowered);
|
||||
});
|
||||
this.entries.set(key, entry);
|
||||
} else {
|
||||
entry.listeners.add(listener);
|
||||
}
|
||||
let released = false;
|
||||
return () => {
|
||||
if (released) return;
|
||||
released = true;
|
||||
entry.listeners.delete(listener);
|
||||
if (entry.listeners.size === 0) { entry.unsubscribe(); this.entries.delete(key); }
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { HermodrStateStreamRegistry };
|
||||
|
|
@ -1,68 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
const fs = require("fs");
|
||||
|
||||
function parseArgs(argv) {
|
||||
const parsed = {};
|
||||
for (let index = 0; index < argv.length; index += 1) {
|
||||
const arg = argv[index];
|
||||
if (!arg.startsWith("--")) continue;
|
||||
const key = arg.slice(2);
|
||||
const next = argv[index + 1];
|
||||
if (!next || next.startsWith("--")) {
|
||||
parsed[key] = true;
|
||||
} else {
|
||||
parsed[key] = next;
|
||||
index += 1;
|
||||
}
|
||||
}
|
||||
return parsed;
|
||||
}
|
||||
|
||||
function parseObjectDocument(label) {
|
||||
return {
|
||||
parse(value) {
|
||||
if (!value || typeof value !== "object") {
|
||||
throw new Error(`${label} must be an object`);
|
||||
}
|
||||
return value;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function positiveNumber(value, fallback) {
|
||||
const number = Number(value);
|
||||
return Number.isFinite(number) && number > 0 ? number : fallback;
|
||||
}
|
||||
|
||||
function stableId(value) {
|
||||
return String(value).toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
|
||||
}
|
||||
|
||||
function clampNumber(value, min, max) {
|
||||
if (!Number.isFinite(value)) return min;
|
||||
return Math.max(min, Math.min(max, Math.round(value)));
|
||||
}
|
||||
|
||||
function tailTextFile(filePath, maxBytes) {
|
||||
const stat = fs.statSync(filePath);
|
||||
const length = Math.min(stat.size, maxBytes);
|
||||
const buffer = Buffer.alloc(length);
|
||||
const fd = fs.openSync(filePath, "r");
|
||||
try {
|
||||
fs.readSync(fd, buffer, 0, length, stat.size - length);
|
||||
} finally {
|
||||
fs.closeSync(fd);
|
||||
}
|
||||
|
||||
return buffer.toString("utf8");
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
clampNumber,
|
||||
parseArgs,
|
||||
parseObjectDocument,
|
||||
positiveNumber,
|
||||
stableId,
|
||||
tailTextFile,
|
||||
};
|
||||
Loading…
Reference in a new issue