Quarantine noncanonical Persona projections in CultCache

This commit is contained in:
Meta Vens 2026-07-16 03:34:23 +01:00
commit 13bdb7adca
13 changed files with 117 additions and 59 deletions

View file

@ -35,7 +35,9 @@ export async function readPersonaMemoryRecall(input: {
const common = { identity: input.identity, statePath: input.state.statePath, projectedMemory: input.projectedMemory, observedAt: input.observedAt ?? new Date() };
const chunks = input.state.stateKind === "gamecult_persona"
? buildGamecultPersonaMemoryChunks({ ...common, state: input.state.personaState })
: buildPersonaMemoryChunks({ ...common, state: input.state.typedState });
: input.state.stateKind === "persona_projection_import"
? buildProjectionImportMemoryChunks(common)
: buildPersonaMemoryChunks({ ...common, state: input.state.typedState });
await store.deleteByFilters({ corpusKind: "persona_memory", identityId: input.identity.id });
await store.upsert(chunks);
const retrieval = new RetrievalService(store, store, store);
@ -55,6 +57,15 @@ export async function readPersonaMemoryRecall(input: {
}
}
function buildProjectionImportMemoryChunks(input: { identity: RepoDiscordIdentity; statePath: string; projectedMemory: string; observedAt: Date }): EmbeddingChunk[] {
const text = collapseWhitespace(input.projectedMemory, 1800);
if (text.length < 24) return [];
return [{
id: `persona:${input.identity.id}:projected-surface`, sourceId: `persona:${input.identity.id}`, sourceKind: "persona_memory", text, normalizedText: normalizeText(text),
metadata: { corpusKind: "persona_memory", identityId: input.identity.id, personaName: input.identity.displayName, sourceId: `persona:${input.identity.id}`, statePath: input.statePath, memoryKind: "noncanonical_projection", targetKind: "self", targetId: input.identity.id, targetLabel: input.identity.displayName, createdAt: "", updatedAt: input.observedAt.toISOString() },
}];
}
export function buildGamecultPersonaMemoryChunks(input: {
identity: RepoDiscordIdentity;
statePath: string;

View file

@ -1,23 +0,0 @@
import { readFile } from "node:fs/promises";
import { resolve } from "node:path";
export type PortablePersonaStateObservation =
| { status: "ok"; statePath: string; state: Record<string, unknown>; schemaVersion: "gamecult.persona_state.v0" }
| { status: "missing" | "malformed" | "unsupported"; statePath: string; reason: string };
export async function readPortablePersonaState(path: string): Promise<PortablePersonaStateObservation> {
const statePath = resolve(path);
try {
const raw = await readFile(statePath, "utf8");
const parsed = JSON.parse(stripBom(raw)) as unknown;
if (!record(parsed)) return { status: "malformed", statePath, reason: "Portable Persona state root is not an object." };
if (parsed.schemaVersion !== "gamecult.persona_state.v0") return { status: "unsupported", statePath, reason: `Unsupported portable Persona schema ${String(parsed.schemaVersion ?? "missing")}.` };
return { status: "ok", statePath, state: parsed, schemaVersion: "gamecult.persona_state.v0" };
} catch (error) {
if ((error as NodeJS.ErrnoException).code === "ENOENT") return { status: "missing", statePath, reason: "Portable Persona state file does not exist." };
return { status: "malformed", statePath, reason: error instanceof Error ? error.message : String(error) };
}
}
function stripBom(value: string): string { return value.charCodeAt(0) === 0xfeff ? value.slice(1) : value; }
function record(value: unknown): value is Record<string, unknown> { return typeof value === "object" && value !== null && !Array.isArray(value); }

View file

@ -1,9 +1,6 @@
import type { RepoDiscordIdentity } from "@voidbot/core";
import type { PortablePersonaStateObservation } from "./persona-portable-state-source.js";
export function projectPortablePersonaState(identity: RepoDiscordIdentity, observation: PortablePersonaStateObservation): string {
if (observation.status !== "ok") return [`${identity.displayName} is a native VoidBot Persona, not a repo Face.`, `Portable Persona state is ${observation.status}: ${observation.reason}`, "Treat this as a Body fault and keep the public turn modest."].join("\n");
const state = observation.state;
export function projectGamecultPersonaState(identity: RepoDiscordIdentity, state: Record<string, unknown>): string {
const profile = child(state, "profile") ?? child(state, "selfProfile") ?? state;
const memory = child(state, "memory") ?? child(state, "thoughtMemory");
const affect = child(state, "affect") ?? child(state, "faceAffect");

View file

@ -4,18 +4,21 @@ import { access } from "node:fs/promises";
import {
inspectPersonaStateSurfaceKind,
loadGamecultPersonaState,
loadPersonaProjectionImport,
loadVoidSelfStateTypedDocuments,
projectRepoFaceSleepCycleForNow,
resolveRepoFaceStatePath,
type RepoDiscordIdentity,
type RepoFaceRestSnapshot,
type GamecultPersonaState,
type PersonaProjectionImport,
type VoidSelfStateTypedProjection,
} from "@voidbot/core";
export type PersonaStateObservation =
| { status: "ok"; stateKind: "void_self_state"; identityId: string; statePath: string; typedState: VoidSelfStateTypedProjection; rest?: RepoFaceRestSnapshot }
| { status: "ok"; stateKind: "gamecult_persona"; identityId: string; statePath: string; personaState: GamecultPersonaState }
| { status: "ok"; stateKind: "persona_projection_import"; identityId: string; statePath: string; projectionImport: PersonaProjectionImport }
| { status: "unconfigured" | "unsupported" | "missing"; identityId: string; statePath?: string; reason: string };
export async function readPersonaStateObservation(input: {
@ -34,6 +37,9 @@ export async function readPersonaStateObservation(input: {
if (stateKind === "gamecult_persona") {
return { status: "ok", stateKind, identityId: input.identity.id, statePath, personaState: await loadGamecultPersonaState(statePath) };
}
if (stateKind === "persona_projection_import") {
return { status: "ok", stateKind, identityId: input.identity.id, statePath, projectionImport: await loadPersonaProjectionImport(statePath) };
}
if (stateKind !== "void_self_state") {
return { status: "unsupported", identityId: input.identity.id, statePath, reason: "The CultCache surface contains no supported Persona state document." };
}