2026-07-13 01:02:17 +01:00
#!/usr/bin/env node
import { createRequire } from "node:module" ;
import { resolve } from "node:path" ;
const repoRoot = resolve ( import . meta . dirname , ".." ) ;
2026-07-15 01:48:41 +01:00
const cultLibRoot = process . env . VOIDBOT _CULTLIB _ROOT
? resolve ( process . env . VOIDBOT _CULTLIB _ROOT )
: resolve ( repoRoot , ".." , "CultLib-dev-runtime" ) ;
const requireCult = createRequire ( resolve ( cultLibRoot , "packages" , "cultmesh-ts" , "package.json" ) ) ;
2026-07-13 01:02:17 +01:00
const { CultMesh } = requireCult ( "./dist/index.js" ) ;
2026-07-15 01:48:41 +01:00
const { defineDocumentType } = createRequire ( resolve ( cultLibRoot , "packages" , "cultcache-ts" , "package.json" ) ) ( "./dist/index.js" ) ;
2026-07-13 01:02:17 +01:00
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 ,
} ) ;
2026-07-13 17:28:21 +01:00
const receiptDefinition = defineDocumentType ( {
type : "gamecult.eve.command_receipt" , schemaName : "gamecult.eve.command_receipt" , schemaId : "gamecult.eve.command_receipt.v1" , schemaVersion : "gamecult.eve.command_receipt.v1" ,
global : false , name : input => input ? . commandId || "smoke-receipt" , schema : objectSchema ,
} ) ;
2026-07-13 01:02:17 +01:00
const commandId = ` smoke:swarm-heat: ${ Date . now ( ) } ` ;
2026-07-13 17:28:21 +01:00
const receipt = await CultMesh . publishRudpDocumentAndWaitForReceipt ( "voidbot-swarm-heat-smoke" , 0x43554c54 , "rudp://127.0.0.1:17873" , { definition : commandDefinition } , commandId , {
2026-07-13 01:02:17 +01:00
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 ( ) ,
2026-07-13 17:28:21 +01:00
} , { definition : receiptDefinition } , { sourceRuntimeId : "voidbot-swarm-heat-smoke" , sourceRole : "verification" , tags : [ "smoke" , "command" ] , receiptTimeoutMs : 5_000 } ) ;
if ( receipt . commandId !== commandId || receipt . state !== "reconciled" ) throw new Error ( ` Receipt did not confirm application: ${ JSON . stringify ( receipt ) } ` ) ;
2026-07-13 01:02:17 +01:00
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 ) } ` ) ;
2026-07-13 17:28:21 +01:00
console . log ( JSON . stringify ( { ok : true , commandId , globalHeat : control . globalHeat , receipt , controlStore : resolve ( repoRoot , ".voidbot" , "private" , "swarm-controls.cc" ) } ) ) ;