Wire typed swarm heat controls
This commit is contained in:
parent
66e84c5cd3
commit
6a88c67ce4
4 changed files with 129 additions and 4 deletions
|
|
@ -1359,8 +1359,8 @@ function buildEveProviderState(snapshot) {
|
|||
}, [
|
||||
eveNode("ctb-rail", "rail", {
|
||||
title: "CTB order",
|
||||
layout: { direction: "horizontal", overflowX: "auto", overflowY: "hidden", height: 96, gap: 6, padding: 6, grow: 1 },
|
||||
}, upcoming.slice(0, 12).map((turn, index) =>
|
||||
layout: { direction: "horizontal", overflow: "hidden", height: 96, gap: 6, padding: 6, grow: 1 },
|
||||
}, upcoming.slice(0, 8).map((turn, index) =>
|
||||
eveNode(`turn-${stableId(turn.identityId)}-${index}`, "avatar", {
|
||||
text: turn.displayName,
|
||||
assetUri: turn.avatarUrl,
|
||||
|
|
@ -2860,6 +2860,16 @@ function providerEndpoints() {
|
|||
role: "provider-cultmesh-rudp snapshot",
|
||||
schemaId: surfaceSchemaId,
|
||||
},
|
||||
{
|
||||
id: "voidbot.swarm.command",
|
||||
transport: "cultmesh-rudp",
|
||||
uri: "cultmesh://voidbot.local/commands/swarm",
|
||||
address: swarmCultMeshRudpEndpoint.replace(/^rudp:\/\//, ""),
|
||||
connectionId: 0x43554c54,
|
||||
role: "provider-command",
|
||||
tags: ["command", "swarm"],
|
||||
schemaId: "gamecult.eve.command.v1",
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import "dotenv/config";
|
|||
import { createHash } from "node:crypto";
|
||||
import { spawn, spawnSync } from "node:child_process";
|
||||
import { appendFile, mkdir, readFile, stat, writeFile } from "node:fs/promises";
|
||||
import { createRequire } from "node:module";
|
||||
import { homedir } from "node:os";
|
||||
import { dirname, extname, resolve } from "node:path";
|
||||
|
||||
|
|
@ -254,8 +255,10 @@ async function main(): Promise<void> {
|
|||
});
|
||||
}
|
||||
|
||||
const swarmControl = await readSwarmControlState();
|
||||
const globalHeat = swarmControl?.globalHeat ?? config.repoFaceHeartbeats.globalHeat;
|
||||
state.baseRecoveryMinutes = config.repoFaceHeartbeats.baseRecoveryMinutes;
|
||||
state.globalHeat = config.repoFaceHeartbeats.globalHeat;
|
||||
state.globalHeat = globalHeat;
|
||||
const completedThisTick = new Set<string>();
|
||||
state.participants = reconcileParticipants(
|
||||
state.participants,
|
||||
|
|
@ -265,7 +268,7 @@ async function main(): Promise<void> {
|
|||
config.repoFaceHeartbeats.heatOverrides,
|
||||
state.initiativeClock,
|
||||
config.repoFaceHeartbeats.baseRecoveryMinutes,
|
||||
config.repoFaceHeartbeats.globalHeat,
|
||||
globalHeat,
|
||||
).map((participant) =>
|
||||
applyActiveTurnFreeze(
|
||||
participant,
|
||||
|
|
@ -5699,6 +5702,44 @@ function recoveryFor(participant: FaceHeartbeatParticipant): number {
|
|||
return (participant.baseRecoveryMinutes * loadPenalty) / Math.max(participant.effectiveSpeed, 0.1);
|
||||
}
|
||||
|
||||
async function readSwarmControlState(): Promise<{ globalHeat: number } | null> {
|
||||
const controlStorePath = resolve(
|
||||
process.env.VOIDBOT_SWARM_CONTROL_STORE || ".voidbot/private/swarm-controls.cc",
|
||||
);
|
||||
try {
|
||||
const packageJson = resolve(process.cwd(), "..", "CultLib", "packages", "cultmesh-ts", "package.json");
|
||||
const requireCult = createRequire(packageJson);
|
||||
const { CultMesh } = requireCult("./dist/index.js");
|
||||
const { defineDocumentType } = createRequire(
|
||||
resolve(process.cwd(), "..", "CultLib", "packages", "cultcache-ts", "package.json"),
|
||||
)("./dist/index.js");
|
||||
const definition = defineDocumentType({
|
||||
type: "voidbot.swarm_control_state",
|
||||
schemaName: "voidbot.swarm_control_state",
|
||||
schemaId: "voidbot.swarm_control_state.v1",
|
||||
schemaVersion: "voidbot.swarm_control_state.v1",
|
||||
global: false,
|
||||
name: () => "voidbot-swarm",
|
||||
schema: {
|
||||
parse(value: unknown) {
|
||||
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
||||
throw new Error("VoidBot swarm control state must be an object.");
|
||||
}
|
||||
return value;
|
||||
},
|
||||
},
|
||||
});
|
||||
const node = await CultMesh.createNode(controlStorePath, { documents: [definition] });
|
||||
const value = node.get(definition, "voidbot-swarm") as { globalHeat?: unknown } | undefined;
|
||||
const globalHeat = Number(value?.globalHeat);
|
||||
return Number.isFinite(globalHeat) && globalHeat >= 0.05 && globalHeat <= 2
|
||||
? { globalHeat }
|
||||
: null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async function readHeartbeatState(path: string): Promise<FaceHeartbeatState> {
|
||||
try {
|
||||
const raw = await readFile(path, "utf8");
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ const { createRequire } = require("module");
|
|||
|
||||
const repoRoot = path.resolve(__dirname, "..");
|
||||
const defaultStorePath = path.join(repoRoot, ".voidbot", "status", "cultmesh", "voidbot-swarm-state.cc");
|
||||
const defaultControlStorePath = path.join(repoRoot, ".voidbot", "private", "swarm-controls.cc");
|
||||
const defaultBind = "127.0.0.1:17873";
|
||||
const defaultOdinCultMeshUri = "cultmesh://odin/rendezvous/provider-catalog";
|
||||
const defaultOdinRudpEndpoint = "rudp://127.0.0.1:17871";
|
||||
|
|
@ -15,6 +16,7 @@ const odinConnectionId = 0x0d1d0002;
|
|||
|
||||
const args = parseArgs(process.argv.slice(2));
|
||||
const storePath = path.resolve(args.store || process.env.VOIDBOT_SWARM_CULTMESH_STORE || defaultStorePath);
|
||||
const controlStorePath = path.resolve(args.controlStore || process.env.VOIDBOT_SWARM_CONTROL_STORE || defaultControlStorePath);
|
||||
const bind = parseBind(args.bind || process.env.VOIDBOT_SWARM_CULTMESH_BIND || defaultBind);
|
||||
const odinCultMeshUri = args.odinCultMeshUri || args["odin-cultmesh-uri"] || process.env.VOIDBOT_ODIN_CULTMESH_URI || process.env.ODIN_CULTMESH_URI || defaultOdinCultMeshUri;
|
||||
const odinRudpEndpoint = args.odinRudpEndpoint || args["odin-rudp-endpoint"] || process.env.VOIDBOT_ODIN_RUDP || process.env.CULTMESH_URI_ODIN_RUDP || defaultOdinRudpEndpoint;
|
||||
|
|
@ -53,6 +55,7 @@ async function main() {
|
|||
onError: (error) => {
|
||||
console.error(`VoidBot swarm CultMesh/RUDP server error: ${error instanceof Error ? error.message : String(error)}`);
|
||||
},
|
||||
onDocumentPutRaw: applySwarmCommand,
|
||||
});
|
||||
|
||||
await server.start();
|
||||
|
|
@ -79,6 +82,27 @@ async function main() {
|
|||
process.once("SIGTERM", shutdown);
|
||||
}
|
||||
|
||||
async function applySwarmCommand(document) {
|
||||
if (document.schemaId !== "gamecult.eve.command.v1") return;
|
||||
const command = document.payload;
|
||||
if (!command || command.providerId !== "voidbot.swarm" || command.command !== "swarm.set_heat") return;
|
||||
const value = Number(command.payload?.value);
|
||||
if (!Number.isFinite(value) || value < 0.05 || value > 2) {
|
||||
throw new Error(`swarm.set_heat value must be between 0.05 and 2, got ${command.payload?.value}`);
|
||||
}
|
||||
const node = await CultMesh.createNode(controlStorePath, { documents: [documents.swarmControl] });
|
||||
const control = {
|
||||
schemaVersion: "voidbot.swarm_control_state.v1",
|
||||
globalHeat: Math.round(value * 100) / 100,
|
||||
commandId: command.commandId,
|
||||
updatedAt: new Date().toISOString(),
|
||||
updatedBy: command.clientId || command.publishedBy || "unknown",
|
||||
};
|
||||
await node.put(documents.swarmControl, "voidbot-swarm", control);
|
||||
await node.flush?.(true);
|
||||
console.log(`Applied swarm heat ${control.globalHeat} from ${control.commandId}`);
|
||||
}
|
||||
|
||||
async function announceToOdin() {
|
||||
const node = await CultMesh.createNode(storePath, {
|
||||
documents: documentDefinitions,
|
||||
|
|
@ -190,6 +214,24 @@ function defineDocuments(defineDocumentType) {
|
|||
name: (value) => value?.boundary_id || value?.daemon_id || "voidbot",
|
||||
schema: objectSchema("Idunn command boundary"),
|
||||
}),
|
||||
eveCommand: defineDocumentType({
|
||||
type: "gamecult.eve.command",
|
||||
schemaName: "gamecult.eve.command",
|
||||
schemaId: "gamecult.eve.command.v1",
|
||||
schemaVersion: "gamecult.eve.command.v1",
|
||||
global: false,
|
||||
name: (value) => value?.commandId || value?.command_id || "swarm-command",
|
||||
schema: objectSchema("Eve command"),
|
||||
}),
|
||||
swarmControl: defineDocumentType({
|
||||
type: "voidbot.swarm_control_state",
|
||||
schemaName: "voidbot.swarm_control_state",
|
||||
schemaId: "voidbot.swarm_control_state.v1",
|
||||
schemaVersion: "voidbot.swarm_control_state.v1",
|
||||
global: false,
|
||||
name: () => "voidbot-swarm",
|
||||
schema: objectSchema("VoidBot swarm control state"),
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -207,6 +249,7 @@ function parseArgs(values) {
|
|||
for (let index = 0; index < values.length; index += 1) {
|
||||
const arg = values[index];
|
||||
if (arg === "--store") parsed.store = values[++index];
|
||||
else if (arg === "--control-store") parsed.controlStore = values[++index];
|
||||
else if (arg === "--bind") parsed.bind = values[++index];
|
||||
else if (arg === "--odin-cultmesh-uri") parsed.odinCultMeshUri = values[++index];
|
||||
else if (arg === "--odin-rudp-endpoint") parsed.odinRudpEndpoint = values[++index];
|
||||
|
|
|
|||
31
scripts/smoke-swarm-heat-command.mjs
Normal file
31
scripts/smoke-swarm-heat-command.mjs
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
#!/usr/bin/env node
|
||||
import { createRequire } from "node:module";
|
||||
import { resolve } from "node:path";
|
||||
|
||||
const repoRoot = resolve(import.meta.dirname, "..");
|
||||
const requireCult = createRequire(resolve(repoRoot, "..", "CultLib", "packages", "cultmesh-ts", "package.json"));
|
||||
const { CultMesh } = requireCult("./dist/index.js");
|
||||
const { defineDocumentType } = createRequire(resolve(repoRoot, "..", "CultLib", "packages", "cultcache-ts", "package.json"))("./dist/index.js");
|
||||
const value = Number(process.argv[2] ?? 0.75);
|
||||
if (!Number.isFinite(value) || value < 0.05 || value > 2) throw new Error("Heat must be between 0.05 and 2.");
|
||||
|
||||
const objectSchema = { parse(input) { if (!input || typeof input !== "object" || Array.isArray(input)) throw new Error("Expected object."); return input; } };
|
||||
const commandDefinition = defineDocumentType({
|
||||
type: "gamecult.eve.command", schemaName: "gamecult.eve.command", schemaId: "gamecult.eve.command.v1", schemaVersion: "gamecult.eve.command.v1",
|
||||
global: false, name: input => input?.commandId || "smoke-command", schema: objectSchema,
|
||||
});
|
||||
const controlDefinition = defineDocumentType({
|
||||
type: "voidbot.swarm_control_state", schemaName: "voidbot.swarm_control_state", schemaId: "voidbot.swarm_control_state.v1", schemaVersion: "voidbot.swarm_control_state.v1",
|
||||
global: false, name: () => "voidbot-swarm", schema: objectSchema,
|
||||
});
|
||||
const commandId = `smoke:swarm-heat:${Date.now()}`;
|
||||
await CultMesh.publishRudpDocumentOnce("voidbot-swarm-heat-smoke", 0x43554c54, "rudp://127.0.0.1:17873", { definition: commandDefinition }, commandId, {
|
||||
schema: "gamecult.eve.command.v1", commandId, providerId: "voidbot.swarm", surfaceId: "voidbot.swarm.surface",
|
||||
command: "swarm.set_heat", payload: { value, transport: "cultmesh-binding" }, clientId: "voidbot.smoke", issuedAt: new Date().toISOString(),
|
||||
}, { sourceRuntimeId: "voidbot-swarm-heat-smoke", sourceRole: "verification", tags: ["smoke", "command"] });
|
||||
|
||||
await new Promise(resolvePromise => setTimeout(resolvePromise, 500));
|
||||
const node = await CultMesh.createNode(resolve(repoRoot, ".voidbot", "private", "swarm-controls.cc"), { documents: [controlDefinition] });
|
||||
const control = node.get(controlDefinition, "voidbot-swarm");
|
||||
if (Number(control?.globalHeat) !== value || control?.commandId !== commandId) throw new Error(`Applied control did not match command: ${JSON.stringify(control)}`);
|
||||
console.log(JSON.stringify({ ok: true, commandId, globalHeat: control.globalHeat, controlStore: resolve(repoRoot, ".voidbot", "private", "swarm-controls.cc") }));
|
||||
Loading…
Reference in a new issue