Finish typed swarm dashboard bindings
This commit is contained in:
parent
f51765604a
commit
a425a5f682
7 changed files with 104 additions and 50 deletions
|
|
@ -29,6 +29,8 @@ const commandBoundaryDocumentType = "idunn.command_boundary";
|
|||
const commandBoundarySchemaId = "idunn.command_boundary.v1";
|
||||
const swarmControlDocumentType = "voidbot.swarm_control_state";
|
||||
const swarmControlSchemaId = "voidbot.swarm_control_state.v1";
|
||||
const swarmOperatorViewDocumentType = "voidbot.swarm_operator_view";
|
||||
const swarmOperatorViewSchemaId = "voidbot.swarm_operator_view.v1";
|
||||
|
||||
const args = parseArgs(process.argv.slice(2));
|
||||
|
||||
|
|
@ -908,6 +910,16 @@ async function writeCultMeshPublication(snapshot, eveState, storePath, allowStor
|
|||
name: () => "voidbot-swarm",
|
||||
schema: { parse: parseObjectDocument("VoidBot swarm control state") },
|
||||
});
|
||||
const swarmOperatorViewDefinition = defineDocumentType({
|
||||
type: swarmOperatorViewDocumentType,
|
||||
schemaName: swarmOperatorViewDocumentType,
|
||||
schemaId: swarmOperatorViewSchemaId,
|
||||
schemaVersion: swarmOperatorViewSchemaId,
|
||||
contentHash: swarmOperatorViewSchemaId,
|
||||
global: false,
|
||||
name: () => "voidbot-swarm",
|
||||
schema: { parse: parseObjectDocument("VoidBot swarm operator view") },
|
||||
});
|
||||
const node = await CultMesh.createNode(storePath, {
|
||||
documents: [
|
||||
snapshotDefinition,
|
||||
|
|
@ -918,6 +930,7 @@ async function writeCultMeshPublication(snapshot, eveState, storePath, allowStor
|
|||
transportProfileDefinition,
|
||||
commandBoundaryDefinition,
|
||||
swarmControlDefinition,
|
||||
swarmOperatorViewDefinition,
|
||||
],
|
||||
});
|
||||
const providerCatalog = loadProviderAdvertisementCatalog(snapshot);
|
||||
|
|
@ -1495,65 +1508,34 @@ function buildEveProviderState(snapshot) {
|
|||
layout: { gap: 8 },
|
||||
}, [
|
||||
eveNode("voidbot-state", "pane", { title: "State Detail", density: "compact" }, selectedLeaf ? [
|
||||
eveNode("state-path", "text", { role: "mono", text: selectedLeaf.path ?? "state path" }),
|
||||
eveNode("state-preview", "text", { role: "mono", text: compactText(selectedLeaf.detail ?? selectedLeaf.preview ?? "", 520) }),
|
||||
eveNode("state-path", "text", { role: "mono", text: selectedLeaf.path ?? "state path", stateBindings: [operatorBinding("text", "selectedFace.statePath")] }),
|
||||
eveNode("state-preview", "text", { role: "mono", text: compactText(selectedLeaf.detail ?? selectedLeaf.preview ?? "", 520), stateBindings: [operatorBinding("text", "selectedFace.statePreview")] }),
|
||||
] : [
|
||||
eveNode("state-empty", "text", { text: selected?.faceState?.error ?? "No readable Face state leaf." }),
|
||||
eveNode("state-empty", "text", { text: selected?.faceState?.error ?? "No readable Face state leaf.", stateBindings: [operatorBinding("text", "selectedFace.statePreview")] }),
|
||||
]),
|
||||
eveNode("voidbot-watchdog-pane", "pane", { title: "Operations", density: "compact" }, [
|
||||
eveNode("watchdog-summary", "text", {
|
||||
role: "mono",
|
||||
text: `orchestrator ${orchestrator.state ?? "unknown"} organs ${organs.length}\nmesh ${snapshot.cultMesh?.writeStatus ?? "pending"} ${shortIso(snapshot.cultMesh?.writtenAt ?? snapshot.generatedAt)}`,
|
||||
stateBindings: [operatorBinding("text", "operations.summary")],
|
||||
}),
|
||||
eveBar("watchdog", "Watchdog", watchdog?.lastStatus ?? "missing", statusFill(watchdog?.lastStatus)),
|
||||
eveBar("repo-face-organ", "Faces", repoFaceOrgan?.lastStatus ?? "missing", statusFill(repoFaceOrgan?.lastStatus)),
|
||||
eveBar("swarm-surface-organ", "Eve surface", swarmSurfaceOrgan?.lastStatus ?? "missing", statusFill(swarmSurfaceOrgan?.lastStatus)),
|
||||
...organs
|
||||
.slice()
|
||||
.sort((left, right) => String(left.id ?? "").localeCompare(String(right.id ?? "")))
|
||||
.slice(0, 5)
|
||||
.map((organ) => eveNode(`watchdog-organ-${stableId(organ.id)}`, "text", {
|
||||
role: "caption",
|
||||
text: `${organ.label ?? organ.id ?? "organ"}: ${organ.lastStatus ?? "unknown"} / exit ${organ.lastExitCode ?? "?"}`,
|
||||
})),
|
||||
eveNode("operations-items", "list", { items: [], stateBindings: [operatorBinding("items", "operations.items")] }),
|
||||
]),
|
||||
eveNode("voidbot-pressure-pane", "pane", { title: "Pressure", density: "compact" }, [
|
||||
eveNode("pressure-items", "list", { items: [], stateBindings: [operatorBinding("items", "pressure")] }),
|
||||
]),
|
||||
eveNode("voidbot-pressure-pane", "pane", { title: "Pressure", density: "compact" }, highPressureFaces.map((face, index) =>
|
||||
eveNode(`pressure-face-${index}-${stableId(face.identityId)}`, "text", {
|
||||
role: "mono",
|
||||
text: `${String(index + 1).padStart(2, " ")} ${String(face.displayName ?? face.identityId ?? "face").padEnd(14, " ")} mem ${String(faceMemoryCount(face)).padStart(2, " ")} prs ${String(facePressureCount(face)).padStart(2, " ")} heat ${formatNumber(face.heat, 2)} q ${face.queuedCount ?? 0}`,
|
||||
}),
|
||||
)),
|
||||
eveNode("pending-mentions-pane", "pane", { title: "Mentions + Events", density: "compact" }, [
|
||||
...(pendingMentions.length
|
||||
? pendingMentions.slice(0, 4).map((mention, index) => eveNode(`pending-mention-${index}`, "text", {
|
||||
role: "mono",
|
||||
text: `${mention.identityId ?? "face"} / ${shortIso(mention.createdAt)}\n${compactText(mention.prompt ?? "", 150)}`,
|
||||
}))
|
||||
: [eveNode("pending-mentions-empty", "text", { text: mentionEmptyText(summary, recentMentionActivity) })]),
|
||||
...recentMentionActivity.slice(0, 5).map((activity, index) =>
|
||||
eveNode(`recent-mention-activity-${index}`, "text", {
|
||||
role: "mono",
|
||||
text: mentionActivityText(activity),
|
||||
}),
|
||||
),
|
||||
...recentEvents.slice(0, 4).map((event, index) =>
|
||||
eveNode(`recent-event-${index}`, "text", {
|
||||
role: "mono",
|
||||
text: `${event.type ?? "event"} ${event.identityId ?? ""} ${shortIso(event.observedAt)}\n${compactText(event.reason ?? event.statusPath ?? "", 120)}`,
|
||||
}),
|
||||
),
|
||||
eveNode("pending-mention-items", "list", { items: [], stateBindings: [operatorBinding("items", "mentions")] }),
|
||||
eveNode("recent-event-items", "list", { items: [], stateBindings: [operatorBinding("items", "recentEvents")] }),
|
||||
]),
|
||||
]),
|
||||
eveNode("voidbot-context", "grid", {
|
||||
columns: "minmax(0, 1fr)",
|
||||
layout: { gap: 8, overflowX: "hidden" },
|
||||
}, [
|
||||
eveNode("selected-channels", "pane", { title: "Channels", density: "compact" }, (selected?.channelPermissions ?? []).slice(0, 8).map((channel, index) =>
|
||||
eveNode(`selected-channel-${index}`, "text", {
|
||||
role: "mono",
|
||||
text: `${channel.label ?? "channel"} x${formatNumber(channel.speedMultiplier ?? 1, 2)} ${channel.speechThreshold ?? "threshold"}\n${channel.topic ?? "no topic"}`,
|
||||
}),
|
||||
)),
|
||||
eveNode("selected-channels", "pane", { title: "Channels", density: "compact" }, [
|
||||
eveNode("selected-channel-items", "list", { items: [], stateBindings: [operatorBinding("items", "selectedFace.channels")] }),
|
||||
]),
|
||||
]),
|
||||
]),
|
||||
assets: participants
|
||||
|
|
|
|||
|
|
@ -25,7 +25,13 @@ function projectSwarmOperatorView({ heartbeat, orchestrator, pause, control, obs
|
|||
pressureCount: array(participant?.responsePressureEvidence).length,
|
||||
description: text(participant?.description),
|
||||
statePath: text(participant?.statePath) || text(participant?.faceStatePath),
|
||||
statePreview: participant?.statePreview ?? null,
|
||||
statePreview: preview(participant?.statePreview),
|
||||
channels: array(participant?.channelPermissions).slice(0, 8).map((channel) => ({
|
||||
label: text(channel?.label) || text(channel?.channelName) || "channel",
|
||||
speedMultiplier: number(channel?.speedMultiplier) ?? 1,
|
||||
speechThreshold: text(channel?.speechThreshold) || "threshold",
|
||||
topic: text(channel?.topic) || "no topic",
|
||||
})),
|
||||
pendingMentionCount,
|
||||
};
|
||||
});
|
||||
|
|
@ -102,7 +108,46 @@ function projectSwarmOperatorView({ heartbeat, orchestrator, pause, control, obs
|
|||
description: selected.description,
|
||||
statePath: selected.statePath,
|
||||
statePreview: selected.statePreview,
|
||||
channels: selected.channels.map((channel) => ({
|
||||
label: channel.label,
|
||||
status: `${channel.speechThreshold} / x${channel.speedMultiplier}`,
|
||||
detail: channel.topic,
|
||||
})),
|
||||
} : null,
|
||||
operations: {
|
||||
summary: `organs ${organs.length} / ${deriveOrchestratorState(organs, orchestratorReadable)}`,
|
||||
items: organs
|
||||
.sort((left, right) => left.id.localeCompare(right.id))
|
||||
.map((organ) => ({
|
||||
label: organ.label,
|
||||
status: organ.status,
|
||||
detail: compact([
|
||||
organ.lastFinishedAt ? `finished ${organ.lastFinishedAt}` : null,
|
||||
organ.durationSeconds === null ? null : `${organ.durationSeconds}s`,
|
||||
]).join(" / "),
|
||||
})),
|
||||
},
|
||||
pressure: [...participants]
|
||||
.sort((left, right) => right.pressureCount - left.pressureCount || right.memoryCount - left.memoryCount || left.displayName.localeCompare(right.displayName))
|
||||
.slice(0, 6)
|
||||
.map((participant) => ({
|
||||
label: participant.displayName,
|
||||
status: `pressure ${participant.pressureCount}`,
|
||||
detail: `memory ${participant.memoryCount} / heat ${participant.heat ?? "?"}`,
|
||||
})),
|
||||
mentions: array(heartbeat?.pendingMentions).slice(0, 6).map((mention) => ({
|
||||
label: text(mention?.identityId) || "face",
|
||||
status: "pending",
|
||||
detail: compact([text(mention?.createdAt) || text(mention?.queuedAt), text(mention?.prompt)]).join(" / "),
|
||||
})),
|
||||
recentEvents: array(heartbeat?.history).slice(-8).reverse().map((event) => ({
|
||||
label: text(event?.type) || "event",
|
||||
status: text(event?.identityId) || "swarm",
|
||||
detail: compact([
|
||||
text(event?.observedAt) || text(event?.queuedAt) || text(event?.consumedAt) || text(event?.appliedAt),
|
||||
text(event?.reason) || text(event?.statusPath),
|
||||
]).join(" / "),
|
||||
})),
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -205,11 +250,20 @@ function buildAlerts({ sources, organs }) {
|
|||
function array(value) { return Array.isArray(value) ? value : []; }
|
||||
function object(value) { return value && typeof value === "object" && !Array.isArray(value) ? value : {}; }
|
||||
function text(value) { return typeof value === "string" && value.trim() ? value : null; }
|
||||
function number(value) { const parsed = Number(value); return Number.isFinite(parsed) ? parsed : null; }
|
||||
function number(value) {
|
||||
if (value === null || value === undefined || value === "") return null;
|
||||
const parsed = Number(value);
|
||||
return Number.isFinite(parsed) ? parsed : null;
|
||||
}
|
||||
function subtract(left, right) { return left === null || right === null ? null : Math.round((left - right) * 1000) / 1000; }
|
||||
function nullableOrder(left, right) { return left === null ? 1 : right === null ? -1 : left - right; }
|
||||
function compact(values) { return values.filter((value) => value !== null); }
|
||||
function formatTurnDistance(value) { return value === null ? "unscheduled" : value <= 0 ? "ready now" : `turn in ${value}m`; }
|
||||
function preview(value) {
|
||||
if (value === null || value === undefined) return null;
|
||||
if (typeof value === "string") return value;
|
||||
try { return JSON.stringify(value); } catch { return String(value); }
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
RECORD_KEY,
|
||||
|
|
|
|||
|
|
@ -13,9 +13,10 @@ test("projects bounded operator state and lets control own heat", () => {
|
|||
globalHeat: 0.5,
|
||||
initiativeClock: 12,
|
||||
lastTickAt: "2026-07-15T10:00:00.000Z",
|
||||
pendingMentions: [{ identityId: "eve" }],
|
||||
pendingMentions: [{ identityId: "eve", prompt: "status?", createdAt: "2026-07-15T09:59:00.000Z" }],
|
||||
history: [{ type: "queued", identityId: "odin", queuedAt: "2026-07-15T09:58:00.000Z" }],
|
||||
participants: [
|
||||
{ identityId: "eve", displayName: "Eve", status: "active", nextTurnInMinutes: 3, heat: 1.2 },
|
||||
{ identityId: "eve", displayName: "Eve", status: "active", nextTurnInMinutes: 3, heat: 1.2, memories: ["one"], responsePressureEvidence: ["signal"], statePath: "face.eve", statePreview: { claim: "awake" }, channelPermissions: [{ label: "general", speedMultiplier: 1.5, speechThreshold: "low", topic: "room" }] },
|
||||
{ identityId: "odin", displayName: "Odin", status: "active", activeJobId: "job-1", nextTurnInMinutes: 8 },
|
||||
],
|
||||
},
|
||||
|
|
@ -32,7 +33,12 @@ test("projects bounded operator state and lets control own heat", () => {
|
|||
assert.equal(view.summary.nextIdentityId, "eve");
|
||||
assert.equal(view.queue[0].heat, 0.85);
|
||||
assert.equal(view.selectedFace.identityId, "eve");
|
||||
assert.equal(view.recentEvents, undefined);
|
||||
assert.equal(view.selectedFace.statePreview, '{"claim":"awake"}');
|
||||
assert.deepEqual(view.selectedFace.channels, [{ label: "general", status: "low / x1.5", detail: "room" }]);
|
||||
assert.equal(view.operations.items[0].label, "Heartbeat");
|
||||
assert.equal(view.pressure[0].label, "Eve");
|
||||
assert.equal(view.mentions[0].status, "pending");
|
||||
assert.equal(view.recentEvents[0].label, "queued");
|
||||
});
|
||||
|
||||
test("publication exposes the typed record without dashboard-shaped authority", () => {
|
||||
|
|
|
|||
|
|
@ -11,6 +11,11 @@ test("the operator surface is composed from metrics and typed lists", () => {
|
|||
"metric-route-provider",
|
||||
"route-alerts",
|
||||
"metric-swarm-brake",
|
||||
"operations-items",
|
||||
"pressure-items",
|
||||
"pending-mention-items",
|
||||
"recent-event-items",
|
||||
"selected-channel-items",
|
||||
]) assert.match(source, new RegExp(`\\b${componentId}\\b`));
|
||||
|
||||
assert.match(source, /sourceId: "voidbot\.swarm_operator_view:voidbot-swarm"/);
|
||||
|
|
@ -23,5 +28,9 @@ test("the migrated prose authorities cannot reappear in the surface", () => {
|
|||
"route-summary",
|
||||
"swarm-pause-status",
|
||||
"live-queue-empty",
|
||||
"watchdog-organ-",
|
||||
"pressure-face-",
|
||||
"pending-mention-0",
|
||||
"recent-event-0",
|
||||
]) assert.doesNotMatch(source, new RegExp(`\\b${removedId}\\b`));
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue