Pack Eve surfaces from nested signal

This commit is contained in:
Meta Vens 2026-06-04 03:04:46 +01:00
commit f301830491
4 changed files with 216 additions and 43 deletions

View file

@ -178,6 +178,16 @@ The canonical contract lives in
Odin persists operator layout intent as `odin.interface_layout.v1` under `scratch/odin/interface-layout.json` for the current Starfire body. The durable CultMesh document should replace this local file once the layout schema is promoted. Layout intents name the provider id and request focus, move, resize, or visibility changes; renderers are input devices for those intents, not local layout owners.
Odin now derives dense top-level layout intent from each provider's retained
`surface.root` tree: element count, leaf count, branch count, depth, text-cell
pressure, and list-like branches. Provider explicit preferred sizes are capped
at the Odin wrapper boundary unless the current intent is fullscreen, so stale
layout files cannot keep empty panels huge. The renderer should use
`props.tree`, `props.layout.signalWeight`, and `props.packing` to allocate space
to nested signal, then recursively lower provider children. Flattening a
provider surface into one log/list is a compatibility failure when the retained
tree has children.
## Current Observation Surface
Odin tails Mimir's normalized observation JSONL at `E:\Projects\Mimir\artifacts\runtime\periwinkle-cultmesh-sensors.out.log` by default. It accepts the typed CultMesh records `mimir.eve_sensor_observation.v1` and `mimir.eve_media_observation.v1`, keeps only the latest record for each `(deviceId, streamId, kind)`, and publishes those summaries as `observation-stream` nodes inside `odin.allseer`. Streams are considered active for 120 seconds by default so a compact dashboard refresh does not turn a briefly quiet sensor into false red noise.

View file

@ -198,28 +198,86 @@ function legacySurfaceFromNodes(state, manifest = null) {
title,
providerId,
compatibility: "legacy-dashboard-nodes",
},
children: nodes.map((node) => ({
id: String(node.id || node.label || "node"),
kind: "pane",
props: {
title: String(node.label || node.id || "node"),
status: String(node.health || ""),
providerId: node.providerId || providerId,
command: node.command || "",
endpoint: node.endpoint || "",
layout: {
density: "dense",
viewportMode: "nested-scroll",
layoutStrategy: "legacy-node-groups",
preferredWidth: 96,
preferredHeight: 24,
minWidth: 36,
minHeight: 8,
},
children: [
textElement(`${node.id || node.label || "node"}-kind`, `kind: ${node.kind || "node"}`),
textElement(`${node.id || node.label || "node"}-health`, `health: ${node.health || "unknown"}`),
node.endpoint ? textElement(`${node.id || node.label || "node"}-endpoint`, `endpoint: ${node.endpoint}`) : null,
].filter(Boolean),
})),
},
children: legacyNodeGroups(nodes, providerId),
},
assets: [],
};
}
function legacyNodeGroups(nodes, providerId) {
const groups = new Map();
for (const node of nodes) {
const kind = String(node.kind || "node");
const health = String(node.health || "unknown");
const key = `${kind}:${health}`;
if (!groups.has(key)) {
groups.set(key, { kind, health, nodes: [] });
}
groups.get(key).nodes.push(node);
}
return [...groups.values()]
.sort((left, right) => left.kind.localeCompare(right.kind) || left.health.localeCompare(right.health))
.map((group) => ({
id: `legacy-group-${stableLegacyId(providerId, group.kind, group.health)}`,
kind: "group",
props: {
title: `${group.kind} / ${group.health}`,
count: group.nodes.length,
density: "dense",
},
children: group.nodes
.sort((left, right) => String(left.id || left.label || "").localeCompare(String(right.id || right.label || "")))
.map((node) => legacyNodeElement(node, providerId)),
}));
}
function legacyNodeElement(node, providerId) {
const id = String(node.id || node.label || "node");
const title = String(node.label || node.id || "node");
const facts = [
compactFact(id, "kind", node.kind || "node"),
compactFact(id, "health", node.health || "unknown"),
node.providerId ? compactFact(id, "provider", node.providerId || providerId) : null,
node.endpoint ? compactFact(id, "endpoint", node.endpoint) : null,
node.command ? compactFact(id, "command", node.command) : null,
].filter(Boolean);
return {
id,
kind: "card",
props: {
title,
status: String(node.health || ""),
providerId: node.providerId || providerId,
command: node.command || "",
endpoint: node.endpoint || "",
density: "compact",
},
children: facts,
};
}
function compactFact(ownerId, name, value) {
return textElement(`fact-${stableLegacyId(ownerId, name, value)}`, `${name}: ${value}`);
}
function stableLegacyId(...parts) {
return parts
.map((part) => String(part || "x").trim().toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, ""))
.filter(Boolean)
.join("-") || "x";
}
function textElement(id, text) {
return {
id: String(id),

View file

@ -47,10 +47,10 @@ function createLayoutStore(layoutPath) {
function defaultLayoutFor(entry, interfaces) {
const index = Math.max(0, interfaces.findIndex((candidate) => candidate.providerId === entry.providerId));
const intent = surfaceLayoutIntent(entry);
const preferredHeight = positiveNumber(intent.preferredHeight, entry.providerId === "voidbot.swarm" ? 16 : 10);
const minHeight = positiveNumber(intent.minHeight, 8);
const preferredWidth = positiveNumber(intent.preferredWidth, 96);
const minWidth = positiveNumber(intent.minWidth, 48);
const preferredHeight = positiveNumber(intent.preferredHeight, entry.providerId === "voidbot.swarm" ? 18 : 12);
const minHeight = positiveNumber(intent.minHeight, 6);
const preferredWidth = positiveNumber(intent.preferredWidth, 72);
const minWidth = positiveNumber(intent.minWidth, 36);
const priority = Number.isFinite(intent.priority) ? intent.priority : index;
return {
tileId: stableId(entry.providerId || "interface"),
@ -64,8 +64,10 @@ function defaultLayoutFor(entry, interfaces) {
minHeight,
preferredWidth,
preferredHeight,
density: intent.density || "adaptive",
viewportMode: intent.viewportMode || "adaptive",
density: intent.density || "dense",
viewportMode: intent.viewportMode || "nested-scroll",
signalWeight: intent.signalWeight || 1,
tree: intent.tree || null,
};
}
@ -93,21 +95,27 @@ function mergeLayoutIntent(existing, entry, interfaces) {
: defaultLayoutFor(entry, interfaces);
const intent = surfaceLayoutIntent(entry);
const fallback = defaultLayoutFor(entry, interfaces);
const denseTree = isDenseLayoutStrategy(intent.layoutStrategy);
const minWidth = positiveNumber(intent.minWidth, positiveNumber(base.minWidth, fallback.minWidth));
const minHeight = positiveNumber(intent.minHeight, positiveNumber(base.minHeight, fallback.minHeight));
const preferredWidth = positiveNumber(intent.preferredWidth, positiveNumber(base.preferredWidth, fallback.preferredWidth));
const preferredHeight = positiveNumber(intent.preferredHeight, positiveNumber(base.preferredHeight, fallback.preferredHeight));
const desiredW = Math.max(1, Math.min(4, Math.ceil(preferredWidth / 72)));
const desiredH = Math.max(1, Math.min(4, Math.ceil(preferredHeight / 12)));
return {
...base,
minWidth,
minHeight,
preferredWidth: Math.max(positiveNumber(base.preferredWidth, preferredWidth), preferredWidth),
preferredHeight: Math.max(positiveNumber(base.preferredHeight, preferredHeight), preferredHeight),
h: Math.max(positiveNumber(base.h, fallback.h), Math.ceil(preferredHeight / 12)),
w: Math.max(positiveNumber(base.w, fallback.w), Math.ceil(preferredWidth / 96)),
preferredWidth,
preferredHeight,
h: denseTree && intent.viewportMode !== "fullscreen" ? desiredH : Math.max(positiveNumber(base.h, fallback.h), desiredH),
w: denseTree && intent.viewportMode !== "fullscreen" ? desiredW : Math.max(positiveNumber(base.w, fallback.w), desiredW),
priority: Number.isFinite(intent.priority) ? Math.min(Number(base.priority ?? intent.priority), intent.priority) : base.priority,
density: intent.density || base.density || fallback.density,
viewportMode: intent.viewportMode || base.viewportMode || fallback.viewportMode,
layoutStrategy: intent.layoutStrategy || base.layoutStrategy || fallback.layoutStrategy,
signalWeight: intent.signalWeight || base.signalWeight || fallback.signalWeight || 1,
tree: intent.tree || base.tree || fallback.tree || null,
};
}
@ -117,12 +125,100 @@ function surfaceLayoutIntent(entry) {
const layout = root.layout && typeof root.layout === "object" ? root.layout : {};
const props = root.props && typeof root.props === "object" ? root.props : {};
const propLayout = props.layout && typeof props.layout === "object" ? props.layout : {};
return { ...propLayout, ...layout };
const tree = analyzeElementTree(root);
const derived = denseTreeLayoutIntent(tree);
return normalizeDenseSurfaceIntent({ ...derived, ...propLayout, ...layout, tree }, derived);
}
function analyzeElementTree(root) {
const stats = {
elementCount: 0,
leafCount: 0,
branchCount: 0,
maxDepth: 0,
textCells: 0,
listLikeBranchCount: 0,
kindCounts: {},
};
visit(root, 1);
stats.signalWeight = Math.max(1, stats.branchCount * 2 + stats.leafCount + Math.ceil(stats.textCells / 48));
return stats;
function visit(element, depth) {
if (!element || typeof element !== "object") return;
stats.elementCount += 1;
stats.maxDepth = Math.max(stats.maxDepth, depth);
const kind = String(element.kind || "unknown");
stats.kindCounts[kind] = (stats.kindCounts[kind] || 0) + 1;
const text = textValue(element);
stats.textCells += text.length + Math.max(0, text.split(/\r?\n/).length - 1) * 8;
const children = Array.isArray(element.children) ? element.children.filter((child) => child && typeof child === "object") : [];
if (!children.length) {
stats.leafCount += 1;
return;
}
stats.branchCount += 1;
if (children.length >= 4 && children.every((child) => String(child.kind || "") === "text" && !(Array.isArray(child.children) && child.children.length))) {
stats.listLikeBranchCount += 1;
}
for (const child of children) visit(child, depth + 1);
}
}
function denseTreeLayoutIntent(tree) {
const signal = Math.max(1, tree.signalWeight || 1);
const depthPressure = Math.max(0, tree.maxDepth - 2);
const textPressure = Math.sqrt(Math.max(1, tree.textCells) / 18);
const branchPressure = Math.sqrt(Math.max(1, tree.branchCount));
return {
minWidth: Math.min(72, 28 + depthPressure * 7),
minHeight: Math.min(18, 5 + depthPressure * 2),
preferredWidth: Math.min(144, 44 + Math.sqrt(signal) * 7 + depthPressure * 5),
preferredHeight: Math.min(36, 8 + textPressure + branchPressure * 3 + tree.listLikeBranchCount * 2),
density: "dense",
viewportMode: "nested-scroll",
layoutStrategy: "dense-tree",
signalWeight: signal,
};
}
function normalizeDenseSurfaceIntent(intent, derived) {
const viewportMode = intent.viewportMode || derived.viewportMode;
if (viewportMode === "fullscreen") {
return intent;
}
return {
...intent,
minWidth: Math.min(72, positiveNumber(intent.minWidth, derived.minWidth)),
minHeight: Math.min(18, positiveNumber(intent.minHeight, derived.minHeight)),
preferredWidth: Math.min(144, positiveNumber(intent.preferredWidth, derived.preferredWidth)),
preferredHeight: Math.min(36, positiveNumber(intent.preferredHeight, derived.preferredHeight)),
density: intent.density || derived.density || "dense",
viewportMode,
layoutStrategy: intent.layoutStrategy || derived.layoutStrategy || "dense-tree",
signalWeight: intent.signalWeight || derived.signalWeight || 1,
};
}
function isDenseLayoutStrategy(strategy) {
const value = String(strategy || "");
return value === "dense-tree" || value === "legacy-node-groups" || value.startsWith("dense-");
}
function textValue(element) {
if (typeof element.text === "string") return element.text;
const props = element.props && typeof element.props === "object" ? element.props : {};
if (typeof props.text === "string") return props.text;
if (typeof props.title === "string") return props.title;
return "";
}
module.exports = {
analyzeElementTree,
createLayoutStore,
defaultLayoutFor,
denseTreeLayoutIntent,
fullscreenLayoutIntent,
mergeLayoutIntent,
surfaceLayoutIntent,

View file

@ -1,6 +1,6 @@
"use strict";
const { fullscreenLayoutIntent, mergeLayoutIntent } = require("./layout.cjs");
const { analyzeElementTree, fullscreenLayoutIntent, mergeLayoutIntent } = require("./layout.cjs");
const { observationPane } = require("./observations.cjs");
const { stableId } = require("./utils.cjs");
@ -27,21 +27,30 @@ function buildSurface({ observedAt, docker, adb, hosts, yggdrasilServices, verse
},
},
children: [
...activeInterfaces.map((entry) => ({
id: `interface-${stableId(entry.providerId)}`,
kind: "interface",
props: {
title: verseUri(entry),
providerId: entry.providerId,
source: entry.source,
status: entry.state,
detail: entry.detail,
version: entry.version,
updatedAt: entry.updatedAt,
layout: mergeLayoutIntent(layout.tiles?.[entry.providerId], entry, interfaces),
},
children: [entry.surface.root],
})),
...activeInterfaces.map((entry) => {
const tree = analyzeElementTree(entry.surface.root);
return {
id: `interface-${stableId(entry.providerId)}`,
kind: "interface",
props: {
title: verseUri(entry),
providerId: entry.providerId,
source: entry.source,
status: entry.state,
detail: entry.detail,
version: entry.version,
updatedAt: entry.updatedAt,
layout: mergeLayoutIntent(layout.tiles?.[entry.providerId], entry, interfaces),
tree,
packing: {
strategy: "nested-dense-signal",
flattening: "forbidden-when-surface-root-has-children",
listPolicy: "group-or-tree; never render provider signal as a single log/list blob",
},
},
children: [entry.surface.root],
};
}),
],
},
assets: [],