Organize marquee into stanza and Stonks bursts

This commit is contained in:
Meta Vens 2026-06-07 04:48:25 +01:00
commit c3a021f96f
4 changed files with 42 additions and 17 deletions

View file

@ -34,6 +34,7 @@ const stateBuilder = createStateBuilder({
layoutStore,
observationFreshSeconds: config.observationFreshSeconds,
observationLogPath: config.observationLogPath,
stonksBurstSize: config.stonksBurstSize,
stonksStateUrl: config.stonksStateUrl,
});

View file

@ -28,6 +28,7 @@ function buildConfig(argv) {
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 stonksBurstSize = Math.max(1, Number(args.stonksBurstSize || 8));
const defaultInterfaceBindingStores = [
path.join(repoRoot, "..", "VoidBot", ".voidbot", "status", "cultmesh", "voidbot-swarm-state.cc"),
path.join(repoRoot, "..", "Bifrost", ".bifrost", "provider-advertisement.cc"),
@ -54,6 +55,7 @@ function buildConfig(argv) {
repoRoot,
seedDeckUrls,
stateDir,
stonksBurstSize,
stonksStateUrl,
surfaceKey: "surface:gamecult.network.status",
};

View file

@ -22,12 +22,12 @@ const textDocumentSetDefinition = defineDocumentType({
},
});
async function buildMarqueeText({ interfaces, textDocumentStorePath, stonksStateUrl }) {
const [securities, poetry] = await Promise.all([
async function buildMarqueeText({ interfaces, textDocumentStorePath, stonksBurstSize = 8, stonksStateUrl }) {
const [securities, stanzas] = await Promise.all([
stonksSegments({ interfaces, stonksStateUrl }),
poetrySegments(textDocumentStorePath),
poetryStanzas(textDocumentStorePath),
]);
return interweave(securities, poetry).join(" / ");
return stanzaBurstTape(stanzas, securities, stonksBurstSize).join(" / ");
}
async function stonksSegments({ interfaces, stonksStateUrl }) {
@ -60,7 +60,7 @@ async function stonksSegmentsFromSnapshot(stonksStateUrl) {
}
}
async function poetrySegments(textDocumentStorePath) {
async function poetryStanzas(textDocumentStorePath) {
if (!textDocumentStorePath || !fs.existsSync(textDocumentStorePath)) return [];
try {
const cache = CultCache.builder()
@ -69,22 +69,44 @@ async function poetrySegments(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);
return array(documentSet?.documents).flatMap(documentStanzas);
} catch {
return [];
}
}
function interweave(securities, poetry) {
function documentStanzas(document) {
const stanzas = [];
let stanza = [];
for (const line of array(document?.lines)) {
if (isStanzaMarker(line)) {
pushStanza(stanzas, stanza);
stanza = [];
continue;
}
const text = array(line).join(" / ").replace(/\s+/g, " ").trim();
if (text) stanza.push(text);
}
pushStanza(stanzas, stanza);
return stanzas;
}
function pushStanza(stanzas, stanza) {
if (stanza.length) stanzas.push(stanza.join(" / "));
}
function stanzaBurstTape(stanzas, securities, burstSize) {
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]);
const stonkBurstSize = Math.max(1, Number(burstSize) || 8);
const stanzaList = stanzas.length ? stanzas : [];
const securityList = securities.length ? securities : [];
const cycles = Math.max(stanzaList.length, securityList.length ? Math.ceil(securityList.length / stonkBurstSize) : 0);
for (let index = 0; index < cycles; index += 1) {
if (stanzaList.length) output.push(stanzaList[index % stanzaList.length]);
for (let offset = 0; offset < stonkBurstSize && securityList.length; offset += 1) {
output.push(securityList[(index * stonkBurstSize + offset) % securityList.length]);
}
}
return output;
}

View file

@ -17,7 +17,7 @@ const { buildMarqueeText } = require("./marquee.cjs");
const { buildPendingSurface, buildSurface } = require("./surface.cjs");
const { stableId } = require("./utils.cjs");
function createStateBuilder({ cachePath, gamecultTextDocumentStorePath, interfaceDiscovery, layoutStore, observationFreshSeconds, observationLogPath, stonksStateUrl }) {
function createStateBuilder({ cachePath, gamecultTextDocumentStorePath, interfaceDiscovery, layoutStore, observationFreshSeconds, observationLogPath, stonksBurstSize, stonksStateUrl }) {
let version = 0;
function buildPendingState(message) {
@ -52,7 +52,7 @@ function createStateBuilder({ cachePath, gamecultTextDocumentStorePath, interfac
]);
const interfaceById = new Map(discoveredInterfaces.map((entry) => [entry.providerId, entry]));
const interfaces = [...interfaceById.values()];
const marqueeText = await buildMarqueeText({ interfaces, textDocumentStorePath: gamecultTextDocumentStorePath, stonksStateUrl });
const marqueeText = await buildMarqueeText({ interfaces, textDocumentStorePath: gamecultTextDocumentStorePath, stonksBurstSize, 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");