Publish canonical Stonks poetry marquee

This commit is contained in:
Meta Vens 2026-06-07 00:13:01 +01:00
commit 2518dc0b10
9 changed files with 167 additions and 42 deletions

View file

@ -29,10 +29,12 @@ const interfaceDiscovery = createInterfaceDiscovery({
});
const stateBuilder = createStateBuilder({
cachePath: config.cachePath,
gamecultTextDocumentStorePath: config.gamecultTextDocumentStorePath,
interfaceDiscovery,
layoutStore,
observationFreshSeconds: config.observationFreshSeconds,
observationLogPath: config.observationLogPath,
stonksStateUrl: config.stonksStateUrl,
});
let meshNodePromise = null;

View file

@ -26,6 +26,8 @@ function buildConfig(argv) {
.filter(Boolean);
const observationLogPath = args.observationLogPath || path.join(repoRoot, "..", "Mimir", "artifacts", "runtime", "periwinkle-cultmesh-sensors.out.log");
const observationFreshSeconds = Number(args.observationFreshSeconds || 120);
const gamecultTextDocumentStorePath = args.gamecultTextDocumentStorePath || path.join(repoRoot, "..", "VoidBot", ".voidbot", "private", "gamecult-text-documents.cc");
const stonksStateUrl = args.stonksStateUrl || "http://127.0.0.1:8802/market/state";
const defaultInterfaceBindingStores = [
path.join(repoRoot, "..", "VoidBot", ".voidbot", "status", "cultmesh", "voidbot-swarm-state.cc"),
path.join(repoRoot, "..", "Bifrost", ".bifrost", "provider-advertisement.cc"),
@ -41,6 +43,7 @@ function buildConfig(argv) {
return {
args,
cachePath,
gamecultTextDocumentStorePath,
host,
interfaceBindingStores,
intervalMs,
@ -51,6 +54,7 @@ function buildConfig(argv) {
repoRoot,
seedDeckUrls,
stateDir,
stonksStateUrl,
surfaceKey: "surface:gamecult.network.status",
};
}

133
src/odin/marquee.cjs Normal file
View file

@ -0,0 +1,133 @@
"use strict";
const fs = require("fs");
const {
CultCache,
SingleFileMessagePackBackingStore,
defineDocumentRegistry,
defineDocumentType,
} = require("cultcache-ts");
const { httpGet } = require("./utils.cjs");
const textDocumentSetDefinition = defineDocumentType({
type: "gamecult.text_document_set",
global: true,
schema: {
parse(value) {
if (!value || typeof value !== "object") {
throw new Error("gamecult.text_document_set must be an object");
}
return value;
},
},
});
async function buildMarqueeText({ interfaces, textDocumentStorePath, stonksStateUrl }) {
const [securities, poetry] = await Promise.all([
stonksSegments({ interfaces, stonksStateUrl }),
poetrySegments(textDocumentStorePath),
]);
return interweave(securities, poetry).join(" / ");
}
async function stonksSegments({ interfaces, stonksStateUrl }) {
const fromInterface = stonksSegmentsFromInterfaces(interfaces);
if (fromInterface.length) return fromInterface;
return stonksSegmentsFromSnapshot(stonksStateUrl);
}
function stonksSegmentsFromInterfaces(interfaces) {
const stonks = interfaces.find((entry) => String(entry.providerId || "").toLowerCase() === "stonks.market");
const explicit = String(stonks?.surface?.root?.props?.marqueeText || "").trim();
return splitSegments(explicit).slice(0, 16);
}
async function stonksSegmentsFromSnapshot(stonksStateUrl) {
if (!stonksStateUrl) return [];
try {
const snapshot = JSON.parse(await httpGet(stonksStateUrl, 1200));
const quotes = [...array(snapshot.crypto), ...array(snapshot.equities)]
.slice(0, 16)
.map(quoteText)
.filter(Boolean);
const warnings = [
snapshot?.sources?.equities?.ok === false ? "EQUITIES SOURCE ERROR" : "",
snapshot?.sources?.crypto?.ok === false ? "CRYPTO SOURCE ERROR" : "",
].filter(Boolean);
return [...quotes, ...warnings];
} catch {
return [];
}
}
async function poetrySegments(textDocumentStorePath) {
if (!textDocumentStorePath || !fs.existsSync(textDocumentStorePath)) return [];
try {
const cache = CultCache.builder()
.withRegistry(defineDocumentRegistry(textDocumentSetDefinition))
.withGenericStore(new SingleFileMessagePackBackingStore(textDocumentStorePath))
.build();
await cache.pullAllBackingStores();
const documentSet = cache.getGlobal(textDocumentSetDefinition);
return array(documentSet?.documents)
.flatMap((document) => array(document.lines))
.filter((line) => !isStanzaMarker(line))
.map((line) => array(line).join(" / ").replace(/\s+/g, " ").trim())
.filter(Boolean);
} catch {
return [];
}
}
function interweave(securities, poetry) {
const output = [];
const count = Math.max(securities.length, poetry.length);
for (let index = 0; index < count; index += 1) {
if (securities[index]) output.push(securities[index]);
if (poetry[index]) output.push(poetry[index]);
}
return output;
}
function splitSegments(text) {
return String(text || "")
.split(/\s+\/\s+/)
.map((segment) => segment.replace(/\s+/g, " ").trim())
.filter(Boolean);
}
function quoteText(item) {
if (!item?.symbol) return "";
const price = item.price == null ? "N/D" : `$${formatNumber(item.price)}`;
const change = item.change24h == null ? "" : ` ${item.change24h >= 0 ? "+" : ""}${Number(item.change24h).toFixed(2)}%`;
const volume = item.volume24h ?? item.volume;
const volumeText = volume == null ? "" : ` vol ${formatCompact(volume)}`;
return `${item.symbol} ${price}${change}${volumeText}`;
}
function formatNumber(value) {
const number = Number(value);
if (!Number.isFinite(number)) return "N/D";
if (Math.abs(number) >= 1000) return number.toFixed(0);
if (Math.abs(number) >= 1) return number.toFixed(2);
return number.toFixed(4);
}
function formatCompact(value) {
const number = Number(value);
if (!Number.isFinite(number)) return "N/D";
return Intl.NumberFormat("en", { notation: "compact", maximumFractionDigits: 1 }).format(number);
}
function isStanzaMarker(line) {
const parts = array(line);
return parts.length === 1 && String(parts[0]).trim().toLowerCase() === "[stanza]";
}
function array(value) {
return Array.isArray(value) ? value : [];
}
module.exports = {
buildMarqueeText,
};

View file

@ -13,10 +13,11 @@ const {
remoteServices,
systemdState,
} = require("./probes.cjs");
const { buildMarqueeText } = require("./marquee.cjs");
const { buildPendingSurface, buildSurface } = require("./surface.cjs");
const { stableId } = require("./utils.cjs");
function createStateBuilder({ cachePath, interfaceDiscovery, layoutStore, observationFreshSeconds, observationLogPath }) {
function createStateBuilder({ cachePath, gamecultTextDocumentStorePath, interfaceDiscovery, layoutStore, observationFreshSeconds, observationLogPath, stonksStateUrl }) {
let version = 0;
function buildPendingState(message) {
@ -51,6 +52,7 @@ function createStateBuilder({ cachePath, interfaceDiscovery, layoutStore, observ
]);
const interfaceById = new Map(discoveredInterfaces.map((entry) => [entry.providerId, entry]));
const interfaces = [...interfaceById.values()];
const marqueeText = await buildMarqueeText({ interfaces, textDocumentStorePath: gamecultTextDocumentStorePath, stonksStateUrl });
const interfaceSummary = interfaces.map((entry) => `${entry.providerId}:${entry.state}`).join(", ");
const voidBotDashboard = interfaceById.get("voidbot.swarm") || dashboardUnavailable("voidbot.swarm", "discovery", "not discovered");
const mimirLiveStats = interfaceById.get("mimir.live.stats") || dashboardUnavailable("mimir.live.stats", "discovery", "not discovered");
@ -110,7 +112,7 @@ function createStateBuilder({ cachePath, interfaceDiscovery, layoutStore, observ
detail: entry.capabilities.join(", "),
})),
providerCatalog: providerAdvertisements,
surface: buildSurface({ observedAt, docker, adb, hosts, yggdrasilServices, verses, interfaces, observations, layout: layoutStore.readLayout() }),
surface: buildSurface({ observedAt, docker, adb, hosts, yggdrasilServices, verses, interfaces, observations, layout: layoutStore.readLayout(), marqueeText }),
};
}

View file

@ -4,7 +4,7 @@ const { analyzeElementTree, fullscreenLayoutIntent, mergeLayoutIntent } = requir
const { observationPane } = require("./observations.cjs");
const { stableId } = require("./utils.cjs");
function buildSurface({ observedAt, docker, adb, hosts, yggdrasilServices, verses, interfaces, observations, layout }) {
function buildSurface({ observedAt, docker, adb, hosts, yggdrasilServices, verses, interfaces, observations, layout, marqueeText = "" }) {
const activeInterfaces = interfaces.filter((entry) => entry?.surface?.root);
const activeObservationStreams = observations.streams.filter((entry) => entry.state === "active");
return {
@ -18,7 +18,7 @@ function buildSurface({ observedAt, docker, adb, hosts, yggdrasilServices, verse
title: "Odin Provider Catalog",
observedAt,
summary: `${activeInterfaces.length} Eve surfaces / ${activeObservationStreams.length} live streams`,
marqueeText: marketMarqueeText(interfaces),
marqueeText,
layout: fullscreenLayoutIntent("odin.providers", -100),
presentation: {
theme: "bifrost-pride",
@ -92,33 +92,6 @@ function stonksHasOverviewSignal(root, text) {
return /\b(Market pulse|BITCOIN|ETHEREUM|SOLANA|DOGECOIN|equities|crypto|vol|request traffic|source health)\b/i.test(text);
}
function marketMarqueeText(interfaces) {
const stonks = interfaces.find((entry) => String(entry.providerId || "").toLowerCase() === "stonks.market");
const root = stonks?.surface?.root;
if (!root) return generalMarqueeText(interfaces);
const explicit = String(root.props?.marqueeText || "").trim();
if (explicit) return explicit;
return surfaceText(root)
.split(/\r?\n/)
.map((line) => line.trim())
.filter((line) => /\b(BITCOIN|ETHEREUM|SOLANA|DOGECOIN|[A-Z0-9.]{2,}\s+\$|vol|request|equities|crypto|Stooq|CoinGecko)\b/i.test(line))
.slice(0, 24)
.join(" / ");
}
function generalMarqueeText(interfaces) {
return interfaces
.filter((entry) => entry?.surface?.root && entry.state === "active")
.flatMap((entry) => surfaceText(entry.surface.root)
.split(/\r?\n/)
.map((line) => line.trim())
.filter(Boolean)
.map((line) => `${entry.title || entry.providerId}: ${line}`))
.filter((line) => !/\b(unavailable|not discovered|playing:\s*none|queue:\s*empty)\b/i.test(line))
.slice(0, 24)
.join(" / ");
}
function spotiverseHasOverviewSignal(root, text) {
const status = String(root.props?.status || "").toLowerCase();
if (status === "warn" && /\brate limit\b/i.test(text)) return false;

View file

@ -25,6 +25,7 @@ function handleHttp(req, res, getCurrentState, getHealth) {
if (req.url === "/eve/deck/providers") {
res.writeHead(200, { "content-type": "application/json" });
res.end(JSON.stringify({
marqueeText: String(currentState?.surface?.root?.props?.marqueeText || ""),
providers: providerCatalogFromState(currentState),
}));
return;
@ -179,6 +180,7 @@ function odinCatalogState(currentState) {
props: {
title: "Odin Providers",
summary: `${providers.length} provider surfaces discovered`,
marqueeText: String(currentState?.surface?.root?.props?.marqueeText || ""),
},
children: providers.map((provider) => ({
id: `provider-${stableSurfaceId(provider.id)}`,