Add canonical native Persona CultCache state

This commit is contained in:
Meta Vens 2026-07-16 03:24:10 +01:00
commit b916dd577e
13 changed files with 288 additions and 5 deletions

View file

@ -0,0 +1,25 @@
import { resolve } from "node:path";
import { migrateCanonicalPortablePersonaState, readCanonicalPortablePersonaState } from "@voidbot/core";
void main().catch((error) => { console.error(error instanceof Error ? error.message : String(error)); process.exitCode = 1; });
async function main(): Promise<void> {
const sourcePath = value("--source");
const targetPath = value("--target");
if (!sourcePath || !targetPath) throw new Error("Usage: migrate-portable-persona-state --source <canonical.json> --target <persona.cc> [--write]");
const source = resolve(sourcePath);
const target = resolve(targetPath);
if (!process.argv.includes("--write")) {
const state = await readCanonicalPortablePersonaState(source);
process.stdout.write(`${JSON.stringify({ ok: true, dryRun: true, sourcePath: source, targetPath: target, personaId: state.personaId, memoryCount: state.thoughtMemory.memories.length, pressureCount: state.agencyPressure.pressures.length })}\n`);
return;
}
const result = await migrateCanonicalPortablePersonaState({ sourcePath: source, targetPath: target });
process.stdout.write(`${JSON.stringify({ ok: true, dryRun: false, ...result })}\n`);
}
function value(flag: string): string | undefined {
const index = process.argv.indexOf(flag);
return index >= 0 ? process.argv[index + 1] : undefined;
}

View file

@ -794,6 +794,14 @@ async function renderRepoFaceMemorySurfaceForTurn(
const acquired = observation ?? await readPersonaStateObservation({ identity, storageRoot: config.storageRoot });
if (acquired.status !== "ok") throw new Error(`${identity.displayName} Persona state ${acquired.status}: ${acquired.reason}`);
if (acquired.stateKind === "gamecult_persona") {
return projectPortablePersonaState(identity, {
status: "ok",
statePath: acquired.statePath,
state: acquired.personaState,
schemaVersion: "gamecult.persona_state.v0",
});
}
const typedState = acquired.typedState;
const curiosityGraphFacts = roomContext && identity.identityKind !== "native_persona"
? await renderRepoFaceCuriosityGraphFacts(identity, config, typedState, roomContext)

View file

@ -0,0 +1,34 @@
import assert from "node:assert/strict";
import { mkdtemp, rm } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join, resolve } from "node:path";
import { loadGamecultPersonaState, migrateCanonicalPortablePersonaState } from "@voidbot/core";
import { projectPortablePersonaState } from "../apps/persona-scheduler/dist/persona-portable-state-projector.js";
import { readPersonaStateObservation } from "../apps/persona-scheduler/dist/persona-state-source.js";
void main().catch((error) => { console.error(error); process.exitCode = 1; });
async function main(): Promise<void> {
const directory = await mkdtemp(join(tmpdir(), "voidbot-persona-migration-"));
try {
const targetPath = join(directory, "tengu.cc");
const sourcePath = resolve(".voidbot/private/personas/tengu/tengu.persona_state.v0.json");
await migrateCanonicalPortablePersonaState({ sourcePath, targetPath });
const state = await loadGamecultPersonaState(targetPath);
assert.equal(state.thoughtMemory.memories.length, 13, "legacy stress responses are preserved as standard memories");
assert.ok(state.thoughtMemory.memories.some((memory) => memory.tags.includes("migration:legacy-stress-response") && memory.extensions?.legacyStressResponse), "legacy stress response provenance remains inspectable");
const identity = { id: "tengu", displayName: "Tengu", repoName: "", roleId: "", identityKind: "native_persona" as const, personaStatePath: targetPath, allowedChannelIds: [] };
const observation = await readPersonaStateObservation({ identity, storageRoot: directory });
assert.equal(observation.status, "ok");
assert.equal(observation.status === "ok" && observation.stateKind, "gamecult_persona");
if (observation.status !== "ok" || observation.stateKind !== "gamecult_persona") throw new Error("Expected canonical standard Persona state.");
const projection = projectPortablePersonaState(identity, { status: "ok", statePath: targetPath, state: observation.personaState, schemaVersion: "gamecult.persona_state.v0" });
assert.match(projection, /canonical gamecult\.persona_state\.v0 state loaded from typed CultCache/);
await assert.rejects(migrateCanonicalPortablePersonaState({ sourcePath: resolve(".voidbot/private/personas/muninn/muninn.persona_state.v0.json"), targetPath: join(directory, "muninn.cc") }), /Refusing to promote projection/);
await assert.rejects(migrateCanonicalPortablePersonaState({ sourcePath, targetPath }), /Refusing to overwrite existing Persona state target/);
console.log("Portable Persona migration smoke passed.");
} finally {
await rm(directory, { recursive: true, force: true });
}
}