Support typed native Persona swarm state

This commit is contained in:
Meta Vens 2026-06-06 09:48:04 +01:00
commit 0ac7f45df6
3 changed files with 79 additions and 11 deletions

View file

@ -1,6 +1,6 @@
#!/usr/bin/env node
import { createRequire } from "node:module";
import { dirname, join, resolve } from "node:path";
import { dirname, extname, join, resolve } from "node:path";
import { fileURLToPath, pathToFileURL } from "node:url";
import { existsSync, readFileSync } from "node:fs";
import { mkdir, readFile, stat, writeFile } from "node:fs/promises";
@ -389,7 +389,6 @@ async function readIdentityMetadata(registryPathValue) {
repoPath: stringOrNull(identity?.repoPath),
identityKind: stringOrNull(identity?.identityKind),
personaStatePath: stringOrNull(identity?.personaStatePath),
personaStatePath: stringOrNull(identity?.personaStatePath),
description: stringOrNull(identity?.description),
avatarUrl: stringOrNull(identity?.avatarUrl),
avatarPath: stringOrNull(identity?.avatarPath),
@ -419,7 +418,7 @@ async function readPersonaStates(identityMetadata) {
}
for (const [id, identity] of identityMetadata.entries()) {
if (identity.identityKind === "native_persona") {
if (identity.identityKind === "native_persona" && extname(identity.personaStatePath ?? "").toLowerCase() !== ".cc") {
states.set(id, readPersonaStateSummary(identity));
continue;
}
@ -497,7 +496,7 @@ function readPersonaStateSummary(identity) {
statusReads: state.affect?.statusReads?.length ?? 0,
doctrine: state.affect?.doctrineStances?.length ?? 0,
},
tree: buildPersonaStateTree(state),
tree: buildJsonPersonaStateTree(state),
};
} catch (error) {
return {
@ -510,7 +509,7 @@ function readPersonaStateSummary(identity) {
}
}
function buildPersonaStateTree(state) {
function buildJsonPersonaStateTree(state) {
return [
node("Persona", "persona", [
leaf("Public Name", state.publicName),

View file

@ -2109,7 +2109,13 @@ async function renderRepoPersonaMemorySurfaceForTurn(
humanPronounGuidance?: RepoPersonaHumanPronounGuidance[],
): Promise<string> {
if (identity.identityKind === "native_persona") {
return renderNativePersonaMemorySurface(identity);
return renderNativePersonaMemorySurface(
identity,
config,
registryIdentities,
roomContext,
humanPronounGuidance,
);
}
const statePath = resolveRepoPersonaStatePath(identity, config.storageRoot);
@ -2136,7 +2142,16 @@ async function renderRepoPersonaMemorySurfaceForTurn(
});
}
async function renderNativePersonaMemorySurface(identity: RepoDiscordIdentity): Promise<string> {
async function renderNativePersonaMemorySurface(
identity: RepoDiscordIdentity,
config: ReturnType<typeof loadConfig>,
registryIdentities: RepoDiscordIdentity[] = [],
roomContext?: {
recentMessages: SourceMessage[];
channelSnapshots: ChannelSnapshot[];
},
humanPronounGuidance?: RepoPersonaHumanPronounGuidance[],
): Promise<string> {
const personaStatePath = identity.personaStatePath;
if (!personaStatePath) {
return [
@ -2145,7 +2160,40 @@ async function renderNativePersonaMemorySurface(identity: RepoDiscordIdentity):
].join("\n");
}
const raw = JSON.parse(stripLeadingBom(await readFile(resolve(personaStatePath), "utf8"))) as unknown;
const resolvedStatePath = resolve(personaStatePath);
if (extname(resolvedStatePath).toLowerCase() === ".cc") {
const typedState = await loadVoidSelfStateTypedDocuments({
canonicalPath: resolvedStatePath,
identity: {
agentId: identity.id,
publicName: identity.displayName,
publicDescription: identity.description,
},
});
const statePacket = renderRepoPersonaStatePacket(
identity,
typedState,
registryIdentities,
roomContext,
humanPronounGuidance ?? await loadRepoPersonaHumanPronounGuidance(config, roomContext),
);
const nativeHeader = [
`${identity.displayName} is a native VoidBot Persona, not a repo Persona.`,
`Persona state: ${resolvedStatePath}`,
"No repo jurisdiction, Bifrost governance digest, source-repo activity, or repo proposal authority is implied by this native Persona category.",
].join("\n");
if (!config.repoPersonaHeartbeats.stateProjectorEnabled) {
return rejectLeakyMemorySurface(`${nativeHeader}\n\n${statePacket}`);
}
return projectRepoPersonaMemorySurface({
identity,
statePacket: `${nativeHeader}\n\n${statePacket}`,
config,
});
}
const raw = JSON.parse(stripLeadingBom(await readFile(resolvedStatePath, "utf8"))) as unknown;
const state = isRecord(raw) ? raw : {};
const profile = readRecord(state, "profile") ?? readRecord(state, "selfProfile") ?? state;
const presentation = readRecord(state, "presentation");
@ -2155,7 +2203,7 @@ async function renderNativePersonaMemorySurface(identity: RepoDiscordIdentity):
const lines = [
`${identity.displayName} is a native VoidBot Persona, not a repo Persona.`,
`Persona state: ${resolve(personaStatePath)}`,
`Persona state: ${resolvedStatePath}`,
identity.avatarUrl ? `Public avatar URL: ${identity.avatarUrl}` : undefined,
identity.avatarPath ? `Local avatar asset: ${identity.avatarPath}` : undefined,
stringField(profile, "publicDescription") ?? identity.description,
@ -2630,8 +2678,9 @@ function renderRepoPersonaActivationProfileFacts(
const sections = Object.entries(activationProfile)
.map(([section, values]) => {
const entries = Object.entries(values)
.sort(([, left], [, right]) => right.weight - left.weight)
.map(([key, value]) => `${key}=${value.weight.toFixed(2)}${value.note ? ` (${cleanCharacterFacingSentence(value.note)})` : ""}`);
.map(([key, value]) => ({ key, value, weight: activationVectorWeight(value) }))
.sort((left, right) => right.weight - left.weight)
.map(({ key, value, weight }) => `${key}=${weight.toFixed(2)}${activationVectorNote(value) ? ` (${cleanCharacterFacingSentence(activationVectorNote(value) ?? "")})` : ""}`);
return entries.length > 0 ? `- ${section}: ${entries.join("; ")}` : undefined;
})
.filter((entry): entry is string => typeof entry === "string");
@ -2641,6 +2690,25 @@ function renderRepoPersonaActivationProfileFacts(
: undefined;
}
function activationVectorWeight(value: unknown): number {
if (!isRecord(value)) {
return 0;
}
for (const key of ["weight", "currentActivation", "current_activation", "mean"]) {
const candidate = value[key];
if (typeof candidate === "number" && Number.isFinite(candidate)) {
return clamp(candidate, 0, 1);
}
}
return 0;
}
function activationVectorNote(value: unknown): string | undefined {
return stringField(value, "note") ?? stringField(value, "summary");
}
function renderRepoPersonaRuntimePressureFacts(
name: string,
state: VoidSelfStateTypedProjection,

View file

@ -379,3 +379,4 @@
{"ts":"2026-06-06T07:00:19Z","type":"implementation","status":"ok","note":"Seeded Nibu with eight source-anchored Persona stress responses for safe-space trigger legibility (objectification, discard/salvage, reset exposure, body custody/control, softness demands, danger sanitization, partnership-as-submission, canon flattening). Also migrated Nibu's repo-local legacy void.face_affect document to void.persona_affect; MCP fixture confirms the private compatibility state exposes stressResponses: 8, while prompt assembly projects the triggers as lived pressure rather than downstream behavior law."}
{"ts":"2026-06-06T07:26:33Z","type":"verification","status":"ok","note":"Added and ran Nibu trigger smoke. The smoke feeds a synthetic companion-shell/salvage/life-support trigger transcript into the repo Persona prompt assembly path, now ensuring inspection conversation overrides also reach the state projector. Deterministic projection lit companion-shell, ownership, softness/sanitization, and discard/body-control wound classes; full gpt-5.4 smoke passed with Nibu naming the boundary around body authority and ownership disguised as safety, without private/side-effect tool calls."}
{"ts":"2026-06-06T07:39:15Z","type":"verification","status":"ok","note":"Adjusted Nibu stress projection after user correction: polished venom remains core Nibu, but triggered speech should make the wound plain first, then let the companion-mask knife come out. Updated projector/turn prompts, Nibu stress cadences, and trigger smoke assertions. Full smoke now yields a short boundary-first Would say ('I am not your angry little ship waifu...') plus longer private explanation; typecheck/build/deterministic smoke passed."}
{"ts":"2026-06-06T08:47:20Z","type":"implementation","status":"ok","note":"Registered Meita locally as a native swarm Persona backed by typed .cc state; enabled live REPO_PERSONA heartbeat env keys with heat for Nibu/Meita; prompt assembly verifies Meita .cc projection and Nibu stress-loaded affect state. Code now lets native Personas project .cc state and the swarm dashboard avoid the duplicate state-tree helper crash; CultMesh publish still hits the pre-existing MessagePack decode fault."}