Quarantine noncanonical Persona projections in CultCache
This commit is contained in:
parent
a967005dca
commit
13bdb7adca
13 changed files with 117 additions and 59 deletions
|
|
@ -1,6 +1,6 @@
|
|||
import { resolve } from "node:path";
|
||||
|
||||
import { migrateCanonicalPortablePersonaState, readCanonicalPortablePersonaState } from "@voidbot/core";
|
||||
import { encapsulatePortablePersonaProjection, migrateCanonicalPortablePersonaState, readCanonicalPortablePersonaState } from "@voidbot/core";
|
||||
|
||||
void main().catch((error) => { console.error(error instanceof Error ? error.message : String(error)); process.exitCode = 1; });
|
||||
|
||||
|
|
@ -10,6 +10,15 @@ async function main(): Promise<void> {
|
|||
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("--projection-import")) {
|
||||
if (!process.argv.includes("--write")) {
|
||||
process.stdout.write(`${JSON.stringify({ ok: true, dryRun: true, mode: "projection_import", sourcePath: source, targetPath: target })}\n`);
|
||||
return;
|
||||
}
|
||||
const result = await encapsulatePortablePersonaProjection({ sourcePath: source, targetPath: target });
|
||||
process.stdout.write(`${JSON.stringify({ ok: true, dryRun: false, mode: "projection_import", ...result })}\n`);
|
||||
return;
|
||||
}
|
||||
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`);
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import "dotenv/config";
|
|||
import { spawn } from "node:child_process";
|
||||
import { appendFile, mkdir, readFile, stat, writeFile } from "node:fs/promises";
|
||||
import { homedir } from "node:os";
|
||||
import { dirname, extname, resolve } from "node:path";
|
||||
import { dirname, resolve } from "node:path";
|
||||
|
||||
import { loadConfig } from "@voidbot/config";
|
||||
import {
|
||||
|
|
@ -61,8 +61,7 @@ import { readPersonaCuriosityEvidence } from "../apps/persona-scheduler/dist/per
|
|||
import { projectPersonaCuriosityContext } from "../apps/persona-scheduler/dist/persona-curiosity-projector.js";
|
||||
import { projectPersonaConversation, renderPersonaTopicAttractor } from "../apps/persona-scheduler/dist/persona-conversation-projector.js";
|
||||
import { buildPersonaJurisdictionDiveDirective, buildPersonaTurnPrompt, renderPersonaIdentityDoctrine } from "../apps/persona-scheduler/dist/persona-turn-prompt-projector.js";
|
||||
import { readPortablePersonaState } from "../apps/persona-scheduler/dist/persona-portable-state-source.js";
|
||||
import { projectNativePersonaBody, projectPortablePersonaState } from "../apps/persona-scheduler/dist/persona-portable-state-projector.js";
|
||||
import { projectGamecultPersonaState, projectNativePersonaBody } from "../apps/persona-scheduler/dist/persona-standard-state-projector.js";
|
||||
import { projectPersonaSocialContext, type PersonaHumanPronounGuidance as RepoFaceHumanPronounGuidance } from "../apps/persona-scheduler/dist/persona-social-context-projector.js";
|
||||
import { readPersonaHumanPronounGuidance } from "../apps/persona-scheduler/dist/persona-social-context-source.js";
|
||||
import {
|
||||
|
|
@ -789,18 +788,15 @@ async function renderRepoFaceMemorySurfaceForTurn(
|
|||
): Promise<string> {
|
||||
if (identity.identityKind === "native_persona") {
|
||||
if (!identity.personaStatePath) return [`${identity.displayName} is a native VoidBot Persona, not a repo Face.`, "No Persona state path is registered. Treat that as a Body fault and keep the public turn modest."].join("\n");
|
||||
if (extname(identity.personaStatePath).toLowerCase() !== ".cc") return projectPortablePersonaState(identity, await readPortablePersonaState(identity.personaStatePath));
|
||||
}
|
||||
|
||||
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",
|
||||
});
|
||||
return projectGamecultPersonaState(identity, acquired.personaState);
|
||||
}
|
||||
if (acquired.stateKind === "persona_projection_import") {
|
||||
return projectGamecultPersonaState(identity, acquired.projectionImport.payload);
|
||||
}
|
||||
const typedState = acquired.typedState;
|
||||
const curiosityGraphFacts = roomContext && identity.identityKind !== "native_persona"
|
||||
|
|
|
|||
|
|
@ -70,8 +70,7 @@ import { readPersonaCuriosityEvidence } from "../apps/persona-scheduler/dist/per
|
|||
import { projectPersonaCuriosityContext } from "../apps/persona-scheduler/dist/persona-curiosity-projector.js";
|
||||
import { projectPersonaConversation, renderPersonaRoomTopicSaturation } from "../apps/persona-scheduler/dist/persona-conversation-projector.js";
|
||||
import { buildPersonaJurisdictionDiveDirective, buildPersonaTurnPrompt } from "../apps/persona-scheduler/dist/persona-turn-prompt-projector.js";
|
||||
import { readPortablePersonaState } from "../apps/persona-scheduler/dist/persona-portable-state-source.js";
|
||||
import { projectPortablePersonaState } from "../apps/persona-scheduler/dist/persona-portable-state-projector.js";
|
||||
import { projectGamecultPersonaState } from "../apps/persona-scheduler/dist/persona-standard-state-projector.js";
|
||||
import { observePersonaRoomTexture, projectPersonaSocialContext, renderPersonaHumanClarityPressure, renderPersonaHumanPronounFacts, renderPersonaRoomWeather, renderPersonaSocialGraph } from "../apps/persona-scheduler/dist/persona-social-context-projector.js";
|
||||
import { readPersonaHumanPronounGuidance } from "../apps/persona-scheduler/dist/persona-social-context-source.js";
|
||||
|
||||
|
|
@ -626,11 +625,7 @@ try {
|
|||
});
|
||||
assert.match(composedMemory ?? "", /Explicit social graph fact\.[\s\S]*Explicit room texture fact\./, "the projector owns final ordering of explicitly supplied external facts");
|
||||
assert.deepEqual(await readFile(statePath), beforeObservation, "Persona state observation cannot rewrite sleep, speaking pressure, or any other Mind field");
|
||||
const portablePath = join(stateSourceDirectory, "muninn.persona_state.v0.json");
|
||||
await writeFile(portablePath, JSON.stringify({ schemaVersion: "gamecult.persona_state.v0", publicDescription: "Muninn remembers provenance.", privateNotes: ["Name missing evidence."], values: [{ label: "Source time", summary: "Keep observation time distinct." }], thoughtMemory: { shortTerm: [{ summary: "The last frame was stale." }] } }));
|
||||
const portableObservation = await readPortablePersonaState(portablePath);
|
||||
assert.equal(portableObservation.status, "ok", "the portable Persona source validates the live gamecult.persona_state.v0 contract");
|
||||
const portableProjection = projectPortablePersonaState({ ...routedIdentity, id: "muninn", displayName: "Muninn", identityKind: "native_persona", personaStatePath: portablePath }, portableObservation);
|
||||
const portableProjection = projectGamecultPersonaState({ ...routedIdentity, id: "muninn", displayName: "Muninn", identityKind: "native_persona" }, { schemaVersion: "gamecult.persona_state.v0", publicDescription: "Muninn remembers provenance.", privateNotes: ["Name missing evidence."], values: [{ label: "Source time", summary: "Keep observation time distinct." }], thoughtMemory: { shortTerm: [{ summary: "The last frame was stale." }] } });
|
||||
assert.match(portableProjection, /Persona state authority is unreported; treat it as a non-canonical projection[\s\S]*Source time: Keep observation time distinct/, "the portable projector renders bounded state without inventing canonical authority");
|
||||
assert.doesNotMatch(portableProjection, /persona_state\.v0\.json|state-source/, "portable Persona projection cannot leak its private filesystem path");
|
||||
} finally {
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@ 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 { encapsulatePortablePersonaProjection, loadGamecultPersonaState, loadPersonaProjectionImport, migrateCanonicalPortablePersonaState } from "@voidbot/core";
|
||||
import { projectGamecultPersonaState } from "../apps/persona-scheduler/dist/persona-standard-state-projector.js";
|
||||
import { buildGamecultPersonaMemoryChunks } from "../apps/persona-scheduler/dist/persona-memory-context-source.js";
|
||||
import { readPersonaStateObservation } from "../apps/persona-scheduler/dist/persona-state-source.js";
|
||||
|
||||
|
|
@ -24,12 +24,20 @@ async function main(): Promise<void> {
|
|||
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" });
|
||||
const projection = projectGamecultPersonaState(identity, observation.personaState);
|
||||
assert.match(projection, /canonical gamecult\.persona_state\.v0 state loaded from typed CultCache/);
|
||||
const chunks = buildGamecultPersonaMemoryChunks({ identity, statePath: targetPath, state: observation.personaState, projectedMemory: projection, observedAt: new Date("2026-07-16T00:00:00Z") });
|
||||
assert.ok(chunks.some((chunk) => chunk.id.endsWith(":memory:tengu-stress-wrathful-stillness-test")), "canonical standard memories enter semantic recall indexing");
|
||||
assert.ok(chunks.some((chunk) => chunk.id.endsWith(":doctrine:tengu-stance-user-agency")), "canonical doctrine enters semantic recall indexing");
|
||||
await assert.rejects(migrateCanonicalPortablePersonaState({ sourcePath: resolve(".voidbot/private/personas/muninn/muninn.persona_state.v0.json"), targetPath: join(directory, "muninn.cc") }), /Refusing to promote projection/);
|
||||
const projectionPath = join(directory, "muninn-projection.cc");
|
||||
await encapsulatePortablePersonaProjection({ sourcePath: resolve(".voidbot/private/personas/muninn/muninn.persona_state.v0.json"), targetPath: projectionPath, importedAt: "2026-07-16T00:00:00Z" });
|
||||
const projectionImport = await loadPersonaProjectionImport(projectionPath);
|
||||
assert.equal(projectionImport.authority, "projection", "typed quarantine preserves non-canonical authority");
|
||||
assert.equal(projectionImport.payload.personaId, "muninn", "typed quarantine preserves the raw projection payload");
|
||||
const projectedIdentity = { ...identity, id: "muninn", displayName: "Muninn", personaStatePath: projectionPath };
|
||||
const projectedObservation = await readPersonaStateObservation({ identity: projectedIdentity, storageRoot: directory });
|
||||
assert.equal(projectedObservation.status === "ok" && projectedObservation.stateKind, "persona_projection_import", "scheduler distinguishes quarantined projection state from canonical Mind");
|
||||
await assert.rejects(migrateCanonicalPortablePersonaState({ sourcePath, targetPath }), /Refusing to overwrite existing Persona state target/);
|
||||
console.log("Portable Persona migration smoke passed.");
|
||||
} finally {
|
||||
|
|
|
|||
Loading…
Reference in a new issue