Isolate Persona Bifrost governance source

This commit is contained in:
Meta Vens 2026-07-15 23:17:07 +01:00
commit 7178cfaa85
7 changed files with 150 additions and 93 deletions

View file

@ -1,6 +1,6 @@
import "dotenv/config";
import { spawn, spawnSync } from "node:child_process";
import { spawn } from "node:child_process";
import { appendFile, mkdir, readFile, stat, writeFile } from "node:fs/promises";
import { createRequire } from "node:module";
import { homedir } from "node:os";
@ -65,6 +65,10 @@ import {
fetchRecentDiscordMessages,
type ChannelSnapshot,
} from "../apps/persona-scheduler/dist/turn-context-source.js";
import {
readBifrostGovernanceDigest,
type BifrostGovernanceDigest,
} from "../apps/persona-scheduler/dist/bifrost-governance-source.js";
const HEARTBEAT_COMMAND = "repo-face-rumination";
@ -84,34 +88,6 @@ interface RepoFaceChannelOption {
posture?: string;
}
interface BifrostGovernanceDigest {
generatedAt: string;
topics: BifrostGovernanceTopic[];
}
interface BifrostGovernanceTopic {
id: string;
title: string;
jurisdictionRepoName: string;
jurisdictionAgentIdentity?: string;
status: string;
summaryMarkdown: string;
priority: number;
updatedAt: string;
approvedByAgent?: string;
dispatchRequestId?: string;
comments?: BifrostGovernanceComment[];
}
interface BifrostGovernanceComment {
id: string;
authorKind: string;
authorId: string;
stance: string;
bodyMarkdown: string;
createdAt: string;
}
async function main(): Promise<void> {
const config = loadConfig();
const dryRun = process.argv.includes("--dry-run");
@ -489,7 +465,7 @@ async function queueRepoFaceTurn(input: {
bifrostDiscordChannelId: input.config.bifrostDiscordChannelId,
});
const bifrostDigest = input.config.repoFaceBifrostEnabled && identity.identityKind !== "native_persona"
? await fetchBifrostGovernanceDigest({
? await readBifrostGovernanceDigest({
bifrostRoot: input.config.bifrostRoot,
repoName: identity.repoName,
agentIdentity: identity.id,
@ -770,68 +746,6 @@ function sleepCyclesEqual(left: unknown, right: unknown): boolean {
return JSON.stringify(left) === JSON.stringify(right);
}
async function fetchBifrostGovernanceDigest(input: {
bifrostRoot: string;
repoName: string;
agentIdentity: string;
}): Promise<BifrostGovernanceDigest | undefined> {
const scriptPath = resolve(input.bifrostRoot, "tools", "governance-threads.mjs");
const result = spawnSync(
process.execPath,
[
scriptPath,
"digest",
"--repo", input.repoName,
"--agent", input.agentIdentity,
"--limit", "6",
],
{
cwd: input.bifrostRoot,
encoding: "utf8",
stdio: ["ignore", "pipe", "pipe"],
windowsHide: true,
timeout: 30000,
},
);
if (result.status !== 0) {
return {
generatedAt: new Date().toISOString(),
topics: [{
id: "bifrost-digest-error",
title: "Bifrost governance digest unavailable",
jurisdictionRepoName: input.repoName,
jurisdictionAgentIdentity: input.agentIdentity,
status: "error",
summaryMarkdown: `Could not read Bifrost governance digest: ${result.stderr || result.error?.message || result.stdout || "unknown failure"}`,
priority: 0,
updatedAt: new Date().toISOString(),
comments: [],
}],
};
}
try {
return JSON.parse(result.stdout) as BifrostGovernanceDigest;
} catch (error) {
const message = error instanceof Error ? error.message : String(error);
return {
generatedAt: new Date().toISOString(),
topics: [{
id: "bifrost-digest-parse-error",
title: "Bifrost governance digest parse failure",
jurisdictionRepoName: input.repoName,
jurisdictionAgentIdentity: input.agentIdentity,
status: "error",
summaryMarkdown: `Could not parse Bifrost governance digest: ${message}`,
priority: 0,
updatedAt: new Date().toISOString(),
comments: [],
}],
};
}
}
async function startVoidModerationTurn(input: {
queuedAt: string;
storageRoot: string;
@ -1072,7 +986,7 @@ async function assembleRepoFaceTurnPrompt(input: {
bifrostDiscordChannelId: input.config.bifrostDiscordChannelId,
}),
input.config.repoFaceBifrostEnabled
? fetchBifrostGovernanceDigest({
? readBifrostGovernanceDigest({
bifrostRoot: input.config.bifrostRoot,
repoName: identity.repoName,
agentIdentity: identity.id,

View file

@ -37,6 +37,7 @@ import {
fetchChannelSnapshots,
fetchRecentDiscordMessages,
} from "../apps/persona-scheduler/dist/turn-context-source.js";
import { readBifrostGovernanceDigest } from "../apps/persona-scheduler/dist/bifrost-governance-source.js";
function participant(identityId: string, nextTurnAt: number): InitiativeParticipant {
return {
@ -278,6 +279,28 @@ const failedSnapshot = await fetchChannelSnapshots({
assert.equal(failedSnapshot[0].messages[0].id, "snapshot-error:nearby", "nearby-channel failure is returned as explicit evidence rather than aborting the turn");
assert.equal(failedSnapshot[0].messages[0].timestamp, "2026-07-15T21:00:00.000Z", "context-source failure witnesses use the caller's observation clock");
let bifrostArgs: string[] = [];
const bifrostDigest = await readBifrostGovernanceDigest({
bifrostRoot: "Bifrost",
repoName: "VoidBot",
agentIdentity: "void",
runDigest: (_scriptPath, args) => {
bifrostArgs = args;
return { status: 0, stdout: JSON.stringify({ generatedAt: "2026-07-15T21:00:00.000Z", topics: [] }) };
},
});
assert.deepEqual(bifrostArgs, ["digest", "--repo", "VoidBot", "--agent", "void", "--limit", "6"], "the Bifrost source alone owns the governance CLI contract");
assert.deepEqual(bifrostDigest.topics, [], "typed Bifrost governance facts cross the source boundary unchanged");
const malformedBifrostDigest = await readBifrostGovernanceDigest({
bifrostRoot: "Bifrost",
repoName: "VoidBot",
agentIdentity: "void",
now: new Date("2026-07-15T21:00:00.000Z"),
runDigest: () => ({ status: 0, stdout: "not-json" }),
});
assert.equal(malformedBifrostDigest.topics[0].id, "bifrost-digest-parse-error", "malformed provider output becomes an explicit typed error topic");
assert.equal(malformedBifrostDigest.generatedAt, "2026-07-15T21:00:00.000Z", "provider failure witnesses use the caller's observation clock");
const stateDirectory = await mkdtemp(join(tmpdir(), "voidbot-persona-scheduler-"));
try {
const statePath = join(stateDirectory, "scheduler.json");