From 128858dd1c13f1f1d82e2945004ec5a81ff7de76 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Wed, 15 Jul 2026 23:33:37 +0100 Subject: [PATCH] Extract Persona scheduler control source --- apps/persona-scheduler/src/control-source.ts | 75 ++++++++++++++++++++ notes/fresh-workspace-handoff.md | 1 + notes/voidbot-current-system-map.md | 1 + scripts/run-repo-face-heartbeats.ts | 66 ++--------------- scripts/smoke-persona-initiative-engine.ts | 20 ++++++ state/evidence.jsonl | 2 + state/map.yaml | 1 + 7 files changed, 105 insertions(+), 61 deletions(-) create mode 100644 apps/persona-scheduler/src/control-source.ts diff --git a/apps/persona-scheduler/src/control-source.ts b/apps/persona-scheduler/src/control-source.ts new file mode 100644 index 0000000..fdfcd8e --- /dev/null +++ b/apps/persona-scheduler/src/control-source.ts @@ -0,0 +1,75 @@ +import { readFile } from "node:fs/promises"; +import { createRequire } from "node:module"; +import { resolve } from "node:path"; + +export interface AgentSwarmPause { + paused: boolean; + path: string; + reason?: string; +} + +export async function readAgentSwarmPause(input: { path?: string } = {}): Promise { + const path = resolve(input.path ?? resolve(process.cwd(), "state", "agent-swarm-paused.json")); + try { + const parsed = JSON.parse(stripLeadingBom(await readFile(path, "utf8"))) as Record; + return { + paused: parsed.paused !== false, + path, + reason: typeof parsed.reason === "string" ? parsed.reason : undefined, + }; + } catch (error) { + if (error && typeof error === "object" && "code" in error && error.code === "ENOENT") { + return { paused: false, path }; + } + return { paused: true, path, reason: "Pause file exists but could not be parsed; failing closed." }; + } +} + +export async function readSwarmControlState(input: { + controlStorePath?: string; + cwd?: string; + loadControl?: (controlStorePath: string) => Promise | unknown; +} = {}): Promise<{ globalHeat: number } | null> { + const cwd = input.cwd ?? process.cwd(); + const controlStorePath = resolve(input.controlStorePath + ?? process.env.VOIDBOT_SWARM_CONTROL_STORE + ?? resolve(cwd, ".voidbot", "private", "swarm-controls.cc")); + try { + const value = input.loadControl + ? await input.loadControl(controlStorePath) + : await loadCultMeshControl(controlStorePath, cwd); + const globalHeat = Number((value as { globalHeat?: unknown } | undefined)?.globalHeat); + return Number.isFinite(globalHeat) && globalHeat >= 0.05 && globalHeat <= 2 ? { globalHeat } : null; + } catch { + return null; + } +} + +async function loadCultMeshControl(controlStorePath: string, cwd: string): Promise { + const cultMeshPackage = resolve(cwd, "..", "CultLib", "packages", "cultmesh-ts", "package.json"); + const { CultMesh } = createRequire(cultMeshPackage)("./dist/index.js"); + const cultCachePackage = resolve(cwd, "..", "CultLib", "packages", "cultcache-ts", "package.json"); + const { defineDocumentType } = createRequire(cultCachePackage)("./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] }); + return node.get(definition, "voidbot-swarm"); +} + +function stripLeadingBom(input: string): string { + return input.charCodeAt(0) === 0xfeff ? input.slice(1) : input; +} diff --git a/notes/fresh-workspace-handoff.md b/notes/fresh-workspace-handoff.md index d78361c..7b0eb48 100644 --- a/notes/fresh-workspace-handoff.md +++ b/notes/fresh-workspace-handoff.md @@ -148,6 +148,7 @@ Git history and smoke artifacts carry routine proof. `state/evidence.jsonl` shou - Scheduler state mutation is centralized. `initiative-engine.ts` owns reconciliation, controls, skip/stale witnesses, pressure, mention consumption, queue transitions, and tick finalization through named commits. The orchestration shell has no direct scheduler state/history writes; queue and context adapters only return facts. - Persona job submission is isolated in `turn-actuator.ts`. That output port alone owns worker actor/guild context construction, `ContextBundle` lowering, the `repo-face-rumination` command, approval defaults, request IDs, and `createJob`; it returns a queue receipt and has no state-selection or prompt-composition authority. - Persona channel policy is isolated in `turn-routing.ts`. It owns pending-attention room preference, default/threshold fallback, snapshot neighborhoods, low-threshold topic projection, and bounded channel-speed projection; prompt/context code receives a route plan and does not choose rooms independently. +- Operator control acquisition is isolated in `control-source.ts`. It owns pause-witness parsing and typed CultMesh swarm-heat loading with fail-closed validation; it reports facts while engine commits alone apply heat or record skipped ticks. - Dynamic heat is live as derived semantic response pressure. `semantic-pressure-source.ts` batches canonical Face affinity cards and recent permitted-channel human-message embeddings through the existing RAG embedder, applies recency decay/noisy-OR aggregation, and returns bounded projections for at most three scheduler-eligible Faces. It does not write scheduler state. `initiative-engine.ts` alone commits inspectable evidence, `dynamicHeat`, one-time semantic interrupt receipts, and readiness changes. Direct mentions remain obligations, and model/Discord failures fail cool without bypassing rest, active jobs, or scheduler capacity. - Repo Face heartbeat prompt assembly now has one model projection boundary before the child Face sees context: `repo-face-state-projector.prompt.md` turns typed Face state into character-facing memory/affect/social prose. `turn-context-source.ts` owns raw Discord acquisition and its bounded attachment cache; it returns current-room and nearby-channel messages oldest-to-newest plus explicit nearby-channel failure witnesses, without reading Persona state or composing prompts. Pending mentions remain scheduler-owned input. The deleted conversation projector was turning evidence into mushy consensus; do not revive it. The Face model must read human corrections directly. A separate deterministic social-affordance surface connects active typed person-bonds/status reads to recent raw messages by that person, so relationship state becomes a live hook instead of private flavor text. Model ownership is split: Face turns default to full `gpt-5.4`; state projection and parent Interpreter passes use the cheaper Spark/Mini support chain. - Repo Face prompts now include read-only recent home-repo activity before Discord transcript. `scripts/run-repo-face-heartbeats.ts` calls `scripts/export-recent-repo-activity.mjs --repos --state-path --read-only --hours 96 --max-commits 5`, so Faces see current body/jurisdiction motion before reacting to room pressure. This is the fix for Mimir missing live camera-runtime work, not a downstream compensator telling it to apologize harder. diff --git a/notes/voidbot-current-system-map.md b/notes/voidbot-current-system-map.md index 5abdab2..ff7b97f 100644 --- a/notes/voidbot-current-system-map.md +++ b/notes/voidbot-current-system-map.md @@ -187,6 +187,7 @@ VoidBot runs on Yggdrasil. Idunn owns deployment and consumes upstream repositor - The scheduler state has one write authority. `initiative-engine.ts` commits participant reconciliation, operator controls, pause/disabled skips, stale-turn recovery witnesses, semantic pressure, pending-attention consumption, queue outcomes, and tick finalization. `run-repo-face-heartbeats.ts` contains no direct participant/state assignment or history append; its sources and actuators return facts to engine commits. - `apps/persona-scheduler/src/turn-actuator.ts` is the worker-queue output port. Given a completed prompt, output channel, evidence fields, provider, identity, timestamp, and narrow `createJob` capability, it builds the canonical worker actor/guild `ContextBundle`, creates one approved `repo-face-rumination` job, and returns `{created, activeJobId, requestMessageId}`. It cannot choose a Persona, mutate scheduler state, or compose prompt content. The orchestration shell no longer knows `ContextBuilder`, job approval defaults, worker command names, or `createJob` mechanics. - `apps/persona-scheduler/src/turn-routing.ts` owns channel selection and projection. It turns registered channel permissions, the configured default, and the newest pending-attention channel into one `PersonaChannelPlan` containing the primary output room, nearby snapshot rooms, normalized options, and low-threshold topics. It also owns the bounded channel-speed multiplier used by participant specs. Context readers and prompt renderers consume this plan without deciding routes. +- `apps/persona-scheduler/src/control-source.ts` owns operator-control observation. It reads the pause witness with explicit absent/running and malformed/fail-closed semantics, loads the typed `voidbot.swarm_control_state` CultMesh document, validates heat bounds, and returns neutral facts. It cannot write scheduler state; engine commits own control application and skip witnesses. - The same scheduler derives semantic `responsePressure` for scheduler-eligible Personas by embedding canonical Face identity-card projections and recent human messages from channels each Face may enter. Pressure decays by message age, aggregates with noisy-OR, awakens at most three eligible Faces, and exposes its message-scoped cosine evidence. It produces bounded `dynamicHeat` for the next scheduled recovery calculation; an unseen message crossing the Persona's interrupt threshold may pull readiness to the current initiative clock exactly once. It cannot create a job, bypass rest or active-turn brakes, impersonate a direct mention, or write inferred desire into Persona state. - The Windows `GameCult Local Orchestrator` and per-organ scheduled-task wrapper no longer own Persona pulses. `voidbot.service` deploys `persona-scheduler` beside bot, worker, Qdrant, and the CultMesh publisher. Turn frequency is controlled by `REPO_FACE_HEARTBEAT_BASE_RECOVERY_MINUTES`, `REPO_FACE_HEARTBEAT_GLOBAL_HEAT`, `REPO_FACE_HEARTBEAT_SPEED_OVERRIDES`, and `REPO_FACE_HEARTBEAT_HEAT_OVERRIDES`. Heat keys can target `all`, `kind:`, `turn:`, `identity:`, `repo:`, `display:`, `channel:`, or the bare identity/repo/display key. - The local ignored registry currently includes Nibu for `AetheriaLore`, with Face state in `E:/Projects/AetheriaLore/.voidbot/state/nibu.cc`, Discord role id `1505918221453103247`, and an Aquarium channel allow-list. Nibu's Face state now treats AetheriaLore-first map-building, abrasive character voice, consensus-backed change agency, her own `Aetheria/Lore/Nibu.md` character-note stewardship, Nibu-authored lore essays, and tangential setting fascination as separate active doctrines. That tangential fascination points at embodied ship minds, junkyard abandonment, murderous autonomy, salvage, and save-scumming survival. The repo Face heartbeat organ is now pulsed by `GameCult Local Orchestrator`; after restarting the stack onto the new worker code, forced heartbeat job `76020f1e-0c55-424b-9e35-89ba7f77fcc3` completed without base-bot auto-posting. diff --git a/scripts/run-repo-face-heartbeats.ts b/scripts/run-repo-face-heartbeats.ts index 4be8984..9745f3a 100644 --- a/scripts/run-repo-face-heartbeats.ts +++ b/scripts/run-repo-face-heartbeats.ts @@ -1,8 +1,7 @@ import "dotenv/config"; -import { spawn } from "node:child_process"; +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, resolve } from "node:path"; @@ -80,6 +79,10 @@ import { type PersonaChannelOption as RepoFaceChannelOption, type PersonaChannelPlan as RepoFaceChannelPlan, } from "../apps/persona-scheduler/dist/turn-routing.js"; +import { + readAgentSwarmPause, + readSwarmControlState, +} from "../apps/persona-scheduler/dist/control-source.js"; async function main(): Promise { const config = loadConfig(); @@ -304,27 +307,6 @@ async function main(): Promise { ); } -async function readAgentSwarmPause(): Promise<{ paused: boolean; path: string; reason?: string }> { - const path = resolve(process.cwd(), "state", "agent-swarm-paused.json"); - try { - const parsed = JSON.parse(stripLeadingBom(await readFile(path, "utf8"))) as Record; - return { - paused: parsed.paused !== false, - path, - reason: typeof parsed.reason === "string" ? parsed.reason : undefined, - }; - } catch (error) { - if (error && typeof error === "object" && "code" in error && error.code === "ENOENT") { - return { paused: false, path }; - } - return { - paused: true, - path, - reason: "Pause file exists but could not be parsed; failing closed.", - }; - } -} - interface ParticipantSpec extends SchedulerParticipantSpec { identity?: RepoDiscordIdentity; } @@ -4438,44 +4420,6 @@ function projectCharacterDescription(description: string | undefined): string | .join(" "); } -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; - } -} - function mergeStrings(values: string[], value: string): string[] { return Array.from(new Set([...values, value])); } diff --git a/scripts/smoke-persona-initiative-engine.ts b/scripts/smoke-persona-initiative-engine.ts index 6fe7f1e..0921ca4 100644 --- a/scripts/smoke-persona-initiative-engine.ts +++ b/scripts/smoke-persona-initiative-engine.ts @@ -54,6 +54,10 @@ import { newestPendingMentionChannel, personaChannelSpeedMultiplier, } from "../apps/persona-scheduler/dist/turn-routing.js"; +import { + readAgentSwarmPause, + readSwarmControlState, +} from "../apps/persona-scheduler/dist/control-source.js"; function participant(identityId: string, nextTurnAt: number): InitiativeParticipant { return { @@ -411,6 +415,22 @@ assert.equal(newestPendingMentionChannel([ { identityId: "nibu", channelId: "newer", queuedAt: "2026-07-15T21:00:00.000Z" }, ] as RepoFacePendingMention[]), "newer", "routing follows the newest pending room obligation"); +const controlDirectory = await mkdtemp(join(tmpdir(), "voidbot-persona-controls-")); +try { + const pausePath = join(controlDirectory, "pause.json"); + assert.equal((await readAgentSwarmPause({ path: pausePath })).paused, false, "an absent pause witness leaves the resident scheduler running"); + await writeFile(pausePath, "{broken", "utf8"); + const malformedPause = await readAgentSwarmPause({ path: pausePath }); + assert.equal(malformedPause.paused, true, "a present malformed pause witness fails closed"); + assert.match(malformedPause.reason ?? "", /could not be parsed/, "the pause source explains its fail-closed observation"); + await writeFile(pausePath, JSON.stringify({ paused: false, reason: "operator resumed" }), "utf8"); + assert.deepEqual(await readAgentSwarmPause({ path: pausePath }), { paused: false, path: pausePath, reason: "operator resumed" }, "the pause source returns operator facts without touching scheduler state"); + assert.deepEqual(await readSwarmControlState({ loadControl: () => ({ globalHeat: 1.75 }) }), { globalHeat: 1.75 }, "typed CultMesh heat is projected through the control source"); + assert.equal(await readSwarmControlState({ loadControl: () => ({ globalHeat: 4 }) }), null, "out-of-contract heat fails closed before the engine sees it"); +} finally { + await rm(controlDirectory, { recursive: true, force: true }); +} + const stateDirectory = await mkdtemp(join(tmpdir(), "voidbot-persona-scheduler-")); try { const statePath = join(stateDirectory, "scheduler.json"); diff --git a/state/evidence.jsonl b/state/evidence.jsonl index addef21..fc65625 100644 --- a/state/evidence.jsonl +++ b/state/evidence.jsonl @@ -400,3 +400,5 @@ {"ts":"2026-07-15T22:19:44Z","type":"implementation","status":"ok","note":"Scheduler state now has one write authority: initiative-engine.ts owns reconciliation, controls, skip/stale witnesses, semantic pressure, mention consumption, queue outcomes, and tick finalization; the heartbeat shell has no direct state assignment or history append."} {"ts":"2026-07-15T22:28:38Z","type":"implementation","status":"ok","note":"Persona worker submission now lives in turn-actuator.ts; it alone lowers assembled prompt/evidence into ContextBundle and approved repo-face-rumination jobs, while the orchestration shell has no ContextBuilder or createJob authority."} {"ts":"2026-07-15T22:31:18Z","type":"implementation","status":"ok","note":"Persona channel policy now lives in turn-routing.ts; pending-attention preference, fallback selection, snapshot neighborhoods, low-threshold topics, and channel-speed projection share one deterministic route plan."} +{"ts":"2026-07-15T22:33:37Z","type":"implementation","status":"ok","note":"Operator pause and CultMesh swarm-heat acquisition now live in control-source.ts with explicit absent/malformed pause semantics and bounded heat validation; the source returns facts while initiative-engine commits controls."} +{"ts":"2026-07-15T22:37:10Z","type":"verification","status":"ok","note":"Yggdrasil exposed a missing spawnSync import after the Bifrost source extraction when a real selected turn entered repo-activity assembly. The remaining repo-activity dependency was restored; local assembly advanced past that call and stopped only at absent local Postgres. Hosted selected-turn verification remains required."} diff --git a/state/map.yaml b/state/map.yaml index d9b1dda..3a43ae9 100644 --- a/state/map.yaml +++ b/state/map.yaml @@ -70,6 +70,7 @@ active_subgoals: - `initiative-engine.ts` is the only writer of scheduler state fields and history. Reconciliation, controls, pause/disabled skips, stale-turn recovery witnesses, semantic pressure, attention consumption, queue transitions, and tick finalization all cross named engine commit primitives. Queue/context actuators return results and cannot patch participants or history directly. - `turn-actuator.ts` owns lowering an assembled Persona prompt and evidence bundle into the canonical worker `ContextBundle` and approved `repo-face-rumination` job. It owns the worker actor, command, request ID, approval defaults, and `createJob` call, then returns only a queue receipt. The orchestration shell chooses no queue mechanics and the actuator cannot read Persona or initiative state. - `turn-routing.ts` owns deterministic Persona channel policy: newest pending-attention preference, default/threshold fallback, snapshot neighborhoods, low-threshold topic projection, and bounded channel-speed projection. Prompt renderers consume a `PersonaChannelPlan`; they do not recompute routing or scheduler speed. + - `control-source.ts` owns operator pause observation and typed CultMesh swarm-heat loading. Missing pause state means running, malformed present pause state fails closed, and out-of-contract heat is rejected. The source returns facts only; `initiative-engine.ts` owns committing controls or skip history. - Keep legacy moderation mirrors, whole-state projection commits, and deleted memory-organ compensators from re-entering the active path before adding more moderation, mood, agency, or public-lane behavior. - Keep public-lane limits, moderation, and provider behavior constrained enough that one 4060 Ti box does not get flayed for sport. - Preserve boring observability and startup discipline around Postgres, Qdrant, Ollama, Docker, backups, scheduled tasks, watchdogs, and any private local fire-signal extensions.