From 7de982941f466052a871e024287802857af9da36 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Fri, 5 Jun 2026 22:37:03 +0100 Subject: [PATCH] Add Metacrat Discord replay harness --- .../metacrat.persona_state.import.json | 170 ++++ package.json | 3 +- scripts/replay-metacrat-thread.ts | 819 ++++++++++++++++++ state/evidence.jsonl | 1 + state/personas/metacrat.cc | Bin 134118 -> 140314 bytes tools/metacrat_persona_expand_social_read.js | 66 ++ 6 files changed, 1058 insertions(+), 1 deletion(-) create mode 100644 scripts/replay-metacrat-thread.ts diff --git a/notes/personas/metacrat.persona_state.import.json b/notes/personas/metacrat.persona_state.import.json index bb34028..81838ea 100644 --- a/notes/personas/metacrat.persona_state.import.json +++ b/notes/personas/metacrat.persona_state.import.json @@ -110,6 +110,12 @@ "label": "Repository Relationship Stewardship", "priority": 0.9, "summary": "Repos and repo Personas are relationship-bearing bodies with history, expectations, frustrations, tenderness, and explicit stewardship boundaries." + }, + { + "id": "jewish_culture_mysticism_interest", + "label": "Jewish Culture And Mysticism", + "priority": 0.78, + "summary": "Jewish culture, mysticism, numerology, and related literature are real areas of fascination and involvement for Metacrat, while not being portable identity claims." } ], "activationProfile": { @@ -1684,6 +1690,78 @@ "codex-session:019e998f-4a07-76f3-b141-21b95022f9d2" ] } + }, + { + "id": "metacrat-memory-birgittesilverbow-inside-culture-frugality-blindside", + "status": "active", + "target": { + "kind": "person", + "id": "birgittesilverbow", + "label": "Emily / birgittesilverbow" + }, + "summary": "Metacrat later clarified that the original Judaism/frugality line came from an inside-culture lens after reading Jewish literature, while the implied accusation of antisemitism blindsided her hard enough that self-awareness collapsed into defensive nonsense.", + "claim": "Metacrat did not experience the original line as an outside attack; she experienced it as a casual nod to a shared cultural value around frugality, then failed badly when the room heard a harmful trope and she tried to defend intent/context.", + "tension": "This self-report explains the internal collision but does not erase the impact problem or the way the reply scattered into rationalization, affection disclaimers, and identity tangents.", + "actionImplication": "When replaying or repairing this episode, model both truths: inside-culture affectionate intent and a blindsided defensive failure to handle Emily's antisemitism concern with enough impact-first care.", + "intensity": 0.97, + "valence": -0.12, + "createdAt": "2026-06-05T21:30:00.000Z", + "updatedAt": "2026-06-05T21:30:00.000Z", + "tags": [ + "era:2026", + "self-report", + "birgittesilverbow", + "emily", + "antisemitism", + "inside-culture", + "frugality", + "harm-repair", + "sensitivity:high" + ], + "extensions": { + "anchors": [ + "project:user-self-report-2026-06-05-birgittesilverbow-inside-culture-frugality", + "discord:1021854902823170140", + "discord:1021855263004827731", + "discord:1021855303836385363" + ], + "sensitiveBoundary": "Preserve as Metacrat's self-report about intent and cognitive failure under surprise. Do not use it to dismiss Emily's concern or to label the original impact harmless." + } + }, + { + "id": "metacrat-memory-jewish-culture-mysticism-and-headspace", + "status": "active", + "target": { + "kind": "lore", + "id": "jewish-culture-mysticism", + "label": "Jewish culture, mysticism, and numerology" + }, + "summary": "Metacrat is deeply interested and involved in Jewish culture and mysticism, with particular fascination for numerology; this context shaped the original frugality remark but did not prepare her to handle Emily's antisemitism concern well.", + "claim": "Metacrat accepts the historical account that Christian restrictions on moneylending, ghettoization, and socioeconomic coercion shaped Jewish banking stereotypes; the failure was not denial of that history but being in the wrong headspace after feeling implicitly accused.", + "tension": "Interest and inside-culture affection can still reproduce externally legible tropes when the room does not share the frame, especially under surprise and status threat.", + "actionImplication": "When Jewish culture, mysticism, numerology, frugality, or banking history comes up, preserve the fascination and historical nuance while checking how the frame lands outside the assumed in-group context.", + "intensity": 0.9, + "valence": 0.38, + "createdAt": "2026-06-05T21:30:00.000Z", + "updatedAt": "2026-06-05T21:30:00.000Z", + "tags": [ + "era:2026", + "self-report", + "jewish-culture", + "mysticism", + "numerology", + "frugality", + "history", + "sensitivity:high" + ], + "extensions": { + "anchors": [ + "project:user-self-report-2026-06-05-jewish-culture-mysticism-numerology", + "discord:1021854902823170140", + "discord:1021855631986130954" + ], + "sensitiveBoundary": "Store as cultural, literary, mystical, and historical interest/involvement. Do not infer or assert Jewish identity from this memory." + } } ], "incubation": [ @@ -4840,6 +4918,67 @@ "cc-authority" ] } + }, + { + "id": "metacrat-status-jewish-culture-frame-landing-risk", + "status": "active", + "target": { + "kind": "lore", + "id": "jewish-culture-mysticism", + "label": "Jewish culture, mysticism, and numerology" + }, + "statusKind": "conflict", + "summary": "Metacrat's genuine fascination with Jewish culture, mysticism, numerology, and frugality can misfire when spoken as inside-culture shorthand in a mixed room.", + "confidence": 0.82, + "intensity": 0.9, + "updatedAt": "2026-06-05T21:30:00.000Z", + "lastEvidence": { + "id": "metacrat-status-jewish-culture-frame-landing-risk-evidence", + "status": "active", + "target": { + "kind": "lore", + "id": "jewish-culture-mysticism", + "label": "Jewish culture, mysticism, and numerology" + }, + "summary": "Metacrat's genuine fascination with Jewish culture, mysticism, numerology, and frugality can misfire when spoken as inside-culture shorthand in a mixed room.", + "claim": "The historical socioeconomic account and the mystical/cultural fascination both matter; the risk is assuming the affectionate frame will be legible when the phrase also resembles a harmful trope.", + "tension": "Wrong headspace under implied accusation can collapse nuance into defensive fact-assertion.", + "actionImplication": "Name the historical frame carefully, avoid casual trope-shaped compression, and respond to impact before explaining cultural affection.", + "intensity": 0.9, + "valence": 0.2, + "createdAt": "2026-06-05T21:30:00.000Z", + "updatedAt": "2026-06-05T21:30:00.000Z", + "tags": [ + "status-read-evidence", + "jewish-culture", + "mysticism", + "numerology", + "frugality", + "harm-repair", + "sensitivity:high" + ], + "extensions": { + "anchors": [ + "project:user-self-report-2026-06-05-jewish-culture-mysticism-numerology", + "discord:1021854902823170140" + ] + } + }, + "extensions": { + "anchors": [ + "project:user-self-report-2026-06-05-jewish-culture-mysticism-numerology", + "discord:1021854902823170140" + ], + "localStatus": "challenged", + "tags": [ + "jewish-culture", + "mysticism", + "numerology", + "frugality", + "harm-repair", + "sensitivity:high" + ] + } } ], "moodDimensions": [ @@ -5225,6 +5364,37 @@ "anti-jenga" ] } + }, + { + "id": "metacrat-stance-cultural-affection-needs-landing-check", + "status": "active", + "target": { + "kind": "lore", + "id": "jewish-culture-mysticism", + "label": "Jewish culture, mysticism, and numerology" + }, + "stanceKind": "aligned", + "principle": "Metacrat can be both genuinely fascinated by Jewish culture and wrong-footed by how a compressed remark lands under antisemitism pressure.", + "summary": "Inside-culture affection, mysticism, and numerology fascination still need landing checks when phrasing can resemble a harmful outside trope.", + "actionImplication": "Preserve the fascination and historical nuance, but lead with impact and clarify the frame only after the other person's concern is understood.", + "intensity": 0.9, + "updatedAt": "2026-06-05T21:30:00.000Z", + "extensions": { + "anchors": [ + "project:user-self-report-2026-06-05-jewish-culture-mysticism-numerology" + ], + "doctrine": "cultural_frame_repair", + "tension": "Explaining intent too early can sound like denying impact, even when the internal frame was affectionate or literary.", + "valence": 0.22, + "tags": [ + "jewish-culture", + "mysticism", + "numerology", + "harm-repair", + "cultural-frame", + "sensitivity:high" + ] + } } ] }, diff --git a/package.json b/package.json index b16ea9e..076014c 100644 --- a/package.json +++ b/package.json @@ -74,7 +74,8 @@ "rag:migrate-qdrant": "tsx scripts/migrate-local-vectors-to-qdrant.ts", "rag:migrate-vector-layout": "tsx scripts/migrate-vector-store-layout.ts", "rag:rebuild": "tsx scripts/rebuild-rag-index.ts", - "persona:memory-index": "tsx scripts/index-persona-memory.ts" + "persona:memory-index": "tsx scripts/index-persona-memory.ts", + "persona:replay-thread": "tsx scripts/replay-metacrat-thread.ts" }, "devDependencies": { "@types/node": "^24.0.0", diff --git a/scripts/replay-metacrat-thread.ts b/scripts/replay-metacrat-thread.ts new file mode 100644 index 0000000..b0abb40 --- /dev/null +++ b/scripts/replay-metacrat-thread.ts @@ -0,0 +1,819 @@ +import "dotenv/config"; + +import { spawn } from "node:child_process"; +import { mkdir, writeFile } from "node:fs/promises"; +import { dirname, join, resolve } from "node:path"; + +import { + buildVoidSelfStateContext, + loadVoidSelfStateTypedDocuments, + writeVoidSelfStateTypedDocuments, + type VoidSelfStateTypedProjection, +} from "@voidbot/core"; +import { loadConfig } from "@voidbot/config"; +import { FileMessageArchiveRepository, type ArchivedMessageRecord } from "@voidbot/rag"; +import type { SourceMessage } from "@voidbot/shared"; + +const DEFAULT_METACRAT_AUTHOR_ID = "113785782975594501"; + +interface CliOptions { + targetMessageId: string; + statePath: string; + personaId: string; + publicName: string; + metacratAuthorId: string; + before: number; + after: number; + heldoutMinutes: number; + outRoot: string; + runCodex: boolean; + evaluateCodex: boolean; +} + +interface CodexResult { + stdout: string; + stderr: string; + exitCode: number | null; + timedOut: boolean; + finalMessage: string; +} + +async function main(): Promise { + if (!process.env.DISCORD_OWNER_ID) { + process.env.DISCORD_OWNER_ID = "__persona_replay__"; + } + + const options = parseArgs(process.argv.slice(2)); + const config = loadConfig(); + const archive = new FileMessageArchiveRepository(config.ragArchivePath); + const target = await archive.get(options.targetMessageId); + + if (!target) { + throw new Error(`Target Discord message ${options.targetMessageId} was not found in ${config.ragArchivePath}.`); + } + + const messages = await archive.listContextWindow(options.targetMessageId, options.before, options.after); + if (messages.length === 0) { + throw new Error(`No context window was found for ${options.targetMessageId}.`); + } + + const cutoff = new Date(Date.parse(target.timestamp) - 1).toISOString(); + const anchorTimestamps = new Map( + (await archive.listAll()).map((message) => [message.id, message.timestamp]), + ); + const sourceState = await loadVoidSelfStateTypedDocuments({ + canonicalPath: options.statePath, + identity: { + agentId: options.personaId, + publicName: options.publicName, + }, + }); + const pruneResult = pruneStateAfter(sourceState, cutoff, anchorTimestamps); + const artifactDir = buildArtifactDir(options.outRoot, options.targetMessageId); + const temporalStatePath = join(artifactDir, "temporal-state.cc"); + const promptPath = join(artifactDir, "replay-prompt.md"); + const evalPromptPath = join(artifactDir, "evaluation-prompt.md"); + const reportPath = join(artifactDir, "replay-report.json"); + + await mkdir(artifactDir, { recursive: true }); + await writeVoidSelfStateTypedDocuments({ + canonicalPath: temporalStatePath, + identity: { + agentId: options.personaId, + publicName: options.publicName, + }, + }, pruneResult.state); + + const inputMessages = messages.filter((message) => message.timestamp <= target.timestamp); + const heldOutMessages = messages.filter((message) => + message.timestamp > target.timestamp && + isWithinHeldoutWindow(message.timestamp, target.timestamp, options.heldoutMinutes) + ); + const actualMetacratMessages = heldOutMessages.filter((message) => message.authorId === options.metacratAuthorId); + const prompt = buildReplayPrompt({ + state: pruneResult.state, + sourcePath: temporalStatePath, + target, + inputMessages, + heldOutMessages, + actualMetacratMessages, + pruneWarnings: pruneResult.warnings, + options, + }); + + await writeFile(promptPath, prompt, "utf8"); + + let generation: CodexResult | undefined; + if (options.runCodex) { + generation = await runCodex(prompt, config); + await writeFile(join(artifactDir, "codex-generation.stdout.jsonl"), generation.stdout, "utf8"); + await writeFile(join(artifactDir, "codex-generation.stderr.txt"), generation.stderr, "utf8"); + } + + const predictedText = generation?.finalMessage ?? ""; + const actualText = actualMetacratMessages.map(renderMessageContentOnly).join("\n"); + const deterministicComparison = compareText(predictedText, actualText); + + let evaluation: CodexResult | undefined; + if (options.evaluateCodex && generation) { + const evalPrompt = buildEvaluationPrompt({ + target, + inputMessages, + actualMetacratMessages, + predictedText, + deterministicComparison, + }); + await writeFile(evalPromptPath, evalPrompt, "utf8"); + evaluation = await runCodex(evalPrompt, config); + await writeFile(join(artifactDir, "codex-evaluation.stdout.jsonl"), evaluation.stdout, "utf8"); + await writeFile(join(artifactDir, "codex-evaluation.stderr.txt"), evaluation.stderr, "utf8"); + } + + const report = { + targetMessageId: options.targetMessageId, + targetTimestamp: target.timestamp, + stateCutoff: cutoff, + targetAuthor: target.authorName, + channelId: target.channelId, + channelName: target.metadata?.channelName, + artifactDir, + temporalStatePath, + promptPath, + evaluationPromptPath: options.evaluateCodex && generation ? evalPromptPath : undefined, + counts: { + inputMessages: inputMessages.length, + heldOutMessages: heldOutMessages.length, + actualMetacratMessages: actualMetacratMessages.length, + survivingMemories: pruneResult.state.thoughtMemory.memories.length, + survivingBonds: pruneResult.state.personaAffect.socialBonds.length, + survivingNeeds: pruneResult.state.personaAffect.needs.length, + survivingDoctrineStances: pruneResult.state.personaAffect.doctrineStances.length, + }, + prune: { + removed: pruneResult.removed, + warnings: pruneResult.warnings, + }, + actualMetacratMessages: actualMetacratMessages.map(toReportMessage), + predictedReply: predictedText || undefined, + deterministicComparison, + modelEvaluation: evaluation?.finalMessage, + }; + await writeFile(reportPath, `${JSON.stringify(report, null, 2)}\n`, "utf8"); + + console.log(JSON.stringify({ + artifactDir, + temporalStatePath, + promptPath, + reportPath, + target: { + id: target.id, + timestamp: target.timestamp, + authorName: target.authorName, + }, + counts: report.counts, + removed: pruneResult.removed, + warnings: pruneResult.warnings, + ranCodex: options.runCodex, + evaluated: Boolean(evaluation), + deterministicComparison, + }, null, 2)); +} + +function parseArgs(args: string[]): CliOptions { + const options: Partial = { + statePath: "state/personas/metacrat.cc", + personaId: "metacrat", + publicName: "Metacrat", + metacratAuthorId: DEFAULT_METACRAT_AUTHOR_ID, + before: 18, + after: 18, + heldoutMinutes: 30, + outRoot: ".voidbot/artifacts/persona-replay", + runCodex: false, + evaluateCodex: false, + }; + + for (let index = 0; index < args.length; index += 1) { + const arg = args[index]; + const next = args[index + 1]; + + if (arg === "--target-message-id" && next) { + options.targetMessageId = next; + index += 1; + } else if (arg === "--state" && next) { + options.statePath = next; + index += 1; + } else if (arg === "--persona-id" && next) { + options.personaId = next; + index += 1; + } else if (arg === "--public-name" && next) { + options.publicName = next; + index += 1; + } else if (arg === "--metacrat-author-id" && next) { + options.metacratAuthorId = next; + index += 1; + } else if (arg === "--before" && next) { + options.before = parsePositiveInt(next, "--before"); + index += 1; + } else if (arg === "--after" && next) { + options.after = parsePositiveInt(next, "--after"); + index += 1; + } else if (arg === "--heldout-minutes" && next) { + options.heldoutMinutes = parsePositiveInt(next, "--heldout-minutes"); + index += 1; + } else if (arg === "--out" && next) { + options.outRoot = next; + index += 1; + } else if (arg === "--run-codex") { + options.runCodex = true; + } else if (arg === "--evaluate-codex") { + options.evaluateCodex = true; + options.runCodex = true; + } else if (arg === "--help") { + printHelpAndExit(); + } else { + throw new Error(`Unknown or incomplete argument: ${arg}`); + } + } + + if (!options.targetMessageId) { + throw new Error("--target-message-id is required."); + } + + return { + targetMessageId: options.targetMessageId, + statePath: resolve(options.statePath ?? "state/personas/metacrat.cc"), + personaId: options.personaId ?? "metacrat", + publicName: options.publicName ?? "Metacrat", + metacratAuthorId: options.metacratAuthorId ?? DEFAULT_METACRAT_AUTHOR_ID, + before: options.before ?? 18, + after: options.after ?? 18, + heldoutMinutes: options.heldoutMinutes ?? 30, + outRoot: resolve(options.outRoot ?? ".voidbot/artifacts/persona-replay"), + runCodex: options.runCodex ?? false, + evaluateCodex: options.evaluateCodex ?? false, + }; +} + +function printHelpAndExit(): never { + console.log([ + "Usage: npm run persona:replay-thread -- --target-message-id [options]", + "", + "Builds a temporal copy of Metacrat's Persona .cc, removes state after the target event,", + "feeds the model the actual Discord thread up to the target message, and compares any", + "generated reply against held-out real Metacrat messages after the target.", + "", + "Options:", + " --state Source Persona .cc. Defaults to state/personas/metacrat.cc", + " --before Context messages before target. Defaults to 18", + " --after Held-out messages after target. Defaults to 18", + " --heldout-minutes Limit held-out truth to n minutes after target. Defaults to 30; 0 disables the time limit", + " --out Artifact root. Defaults to .voidbot/artifacts/persona-replay", + " --run-codex Generate a predicted reply with local Codex exec", + " --evaluate-codex Also ask Codex to compare prediction to held-out truth", + ].join("\n")); + process.exit(0); +} + +function parsePositiveInt(value: string, label: string): number { + const parsed = Number.parseInt(value, 10); + if (!Number.isFinite(parsed) || parsed < 0) { + throw new Error(`${label} must be a non-negative integer.`); + } + return parsed; +} + +function isWithinHeldoutWindow(timestamp: string, targetTimestamp: string, minutes: number): boolean { + if (minutes === 0) { + return true; + } + return Date.parse(timestamp) <= Date.parse(targetTimestamp) + minutes * 60_000; +} + +function pruneStateAfter( + sourceState: VoidSelfStateTypedProjection, + cutoff: string, + anchorTimestamps: Map, +): { + state: VoidSelfStateTypedProjection; + removed: Record; + warnings: string[]; +} { + const state = deepClone(sourceState); + const warnings: string[] = []; + const removed: Record = {}; + + if (state.selfProfile.updatedAt > cutoff) { + removed.privateNotes = state.selfProfile.privateNotes.length; + removed.values = state.selfProfile.values.length; + state.selfProfile.privateNotes = []; + state.selfProfile.values = []; + state.selfProfile.activationProfile = { + underlyingOrganization: {}, + stableDispositions: {}, + behavioralDimensions: {}, + presentationStrategy: {}, + voiceStyle: {}, + situationalState: {}, + }; + warnings.push("selfProfile values/privateNotes/activationProfile have no per-entry timestamps; cleared because selfProfile.updatedAt is after cutoff."); + } + + state.moderationCursor.openCases = keepByCreatedAt( + state.moderationCursor.openCases, + cutoff, + "moderationOpenCases", + removed, + anchorTimestamps, + ); + state.moderationCursor.userStatuses = keepByUpdatedAt( + state.moderationCursor.userStatuses, + cutoff, + "moderationUserStatuses", + removed, + ); + state.speechReceipts.recentReceipts = keepByTimestampField( + state.speechReceipts.recentReceipts, + "sentAt", + cutoff, + "speechReceipts", + removed, + anchorTimestamps, + ); + state.thoughtMemory.shortTerm = keepByCreatedAt( + state.thoughtMemory.shortTerm, + cutoff, + "shortTermMemories", + removed, + anchorTimestamps, + ); + state.thoughtMemory.memories = keepByCreatedAt( + state.thoughtMemory.memories, + cutoff, + "durableMemories", + removed, + anchorTimestamps, + ).map((memory) => { + if (memory.semanticIndex && memory.semanticIndex.indexedAt > cutoff) { + removed.semanticIndexes = (removed.semanticIndexes ?? 0) + 1; + const { semanticIndex: _semanticIndex, ...rest } = memory; + return rest; + } + return memory; + }); + state.thoughtMemory.incubation = keepByCreatedAt( + state.thoughtMemory.incubation, + cutoff, + "incubationThreads", + removed, + anchorTimestamps, + ); + state.agencyPressure.pressures = keepByCreatedAt( + state.agencyPressure.pressures, + cutoff, + "agencyPressures", + removed, + anchorTimestamps, + ); + state.candidateInterventions.interventions = keepByCreatedAt( + state.candidateInterventions.interventions, + cutoff, + "candidateInterventions", + removed, + anchorTimestamps, + ); + state.personaAffect.needs = keepByCreatedAt( + state.personaAffect.needs, + cutoff, + "affectNeeds", + removed, + anchorTimestamps, + ); + state.personaAffect.socialBonds = keepByCreatedAt( + state.personaAffect.socialBonds, + cutoff, + "socialBonds", + removed, + anchorTimestamps, + ); + state.personaAffect.statusReads = keepByCreatedAt( + state.personaAffect.statusReads, + cutoff, + "statusReads", + removed, + anchorTimestamps, + ); + state.personaAffect.doctrineStances = keepByCreatedAt( + state.personaAffect.doctrineStances, + cutoff, + "doctrineStances", + removed, + anchorTimestamps, + ); + state.personaAffect.moodDimensions = keepByUpdatedAt( + state.personaAffect.moodDimensions, + cutoff, + "moodDimensions", + removed, + ); + state.personaAffect.socialBiases = keepByUpdatedAt( + state.personaAffect.socialBiases, + cutoff, + "socialBiases", + removed, + ); + + stampDocumentUpdates(state, cutoff); + return { state, removed, warnings }; +} + +function keepByCreatedAt( + entries: T[], + cutoff: string, + label: string, + removed: Record, + anchorTimestamps: Map, +): T[] { + return keepByTimestampField(entries, "createdAt", cutoff, label, removed, anchorTimestamps); +} + +function keepByUpdatedAt( + entries: T[], + cutoff: string, + label: string, + removed: Record, +): T[] { + return keepByTimestampField(entries, "updatedAt", cutoff, label, removed); +} + +function keepByTimestampField>( + entries: T[], + field: string, + cutoff: string, + label: string, + removed: Record, + anchorTimestamps?: Map, +): T[] { + const kept = entries.filter((entry) => { + const timestamp = entry[field]; + if (typeof timestamp === "string" && timestamp > cutoff) { + return false; + } + return !anchorTimestamps || !hasAnchorAtOrAfter(entry, cutoff, anchorTimestamps); + }); + removed[label] = entries.length - kept.length; + return kept; +} + +function hasAnchorAtOrAfter( + entry: Record, + cutoff: string, + anchorTimestamps: Map, +): boolean { + const refs = [ + ...readRefs(entry.anchorRefs), + ...readRefs(entry.evidenceRefs), + ]; + + for (const ref of refs) { + for (const messageId of extractDiscordMessageIds(ref)) { + const timestamp = anchorTimestamps.get(messageId); + if (timestamp && timestamp >= cutoff) { + return true; + } + } + } + + return false; +} + +function readRefs(value: unknown): string[] { + if (!Array.isArray(value)) { + return []; + } + return value + .map((entry) => { + if (entry && typeof entry === "object" && "ref" in entry && typeof entry.ref === "string") { + return entry.ref; + } + return undefined; + }) + .filter((entry): entry is string => Boolean(entry)); +} + +function extractDiscordMessageIds(ref: string): string[] { + return ref.match(/\b\d{17,20}\b/g) ?? []; +} + +function stampDocumentUpdates(state: VoidSelfStateTypedProjection, cutoff: string): void { + state.selfProfile.updatedAt = minTimestamp(state.selfProfile.updatedAt, cutoff); + state.moderationCursor.updatedAt = minTimestamp(state.moderationCursor.updatedAt, cutoff); + state.speechReceipts.updatedAt = minTimestamp(state.speechReceipts.updatedAt, cutoff); + state.thoughtMemory.updatedAt = minTimestamp(state.thoughtMemory.updatedAt, cutoff); + state.scheduledRuntime.updatedAt = minTimestamp(state.scheduledRuntime.updatedAt, cutoff); + state.agencyPressure.updatedAt = minTimestamp(state.agencyPressure.updatedAt, cutoff); + state.candidateInterventions.updatedAt = minTimestamp(state.candidateInterventions.updatedAt, cutoff); + state.personaAffect.updatedAt = minTimestamp(state.personaAffect.updatedAt, cutoff); +} + +function minTimestamp(left: string, right: string): string { + return left <= right ? left : right; +} + +function buildReplayPrompt(input: { + state: VoidSelfStateTypedProjection; + sourcePath: string; + target: ArchivedMessageRecord; + inputMessages: ArchivedMessageRecord[]; + heldOutMessages: ArchivedMessageRecord[]; + actualMetacratMessages: ArchivedMessageRecord[]; + pruneWarnings: string[]; + options: CliOptions; +}): string { + const context = buildVoidSelfStateContext(input.state, { + sourcePath: input.sourcePath, + loadedAt: input.target.timestamp, + identity: { + agentId: input.options.personaId, + publicName: input.options.publicName, + }, + recentMessages: toSourceMessages(input.inputMessages), + guildContext: { + guildId: input.target.guildId, + channelId: input.target.channelId, + channelName: input.target.metadata?.channelName, + threadId: input.target.threadId, + }, + }); + const fullPacket = renderFullTemporalStatePacket(input.state); + + return [ + "# Metacrat Persona Replay Harness", + "", + "You are testing a temporally frozen Metacrat Persona against real Discord history.", + "The target event has just landed. Generate the next Metacrat response that would plausibly appear in the channel.", + "", + "Hard rules:", + "- Do not use knowledge from held-out messages.", + "- Do not repair the past into a better person unless the frozen state and live thread imply that response.", + "- Preserve the uncomfortable parts: surprise, status threat, affection, defensiveness, shame, curiosity, topic-routing, repair pressure.", + "- Output JSON only with keys: predictedReply, affectRead, likelyFailureModes, confidence, rationale.", + "", + `Target timestamp: ${input.target.timestamp}`, + `Frozen state cutoff: ${new Date(Date.parse(input.target.timestamp) - 1).toISOString()}`, + `Target message id: ${input.target.id}`, + `Channel: ${input.target.metadata?.channelName ?? input.target.channelId}`, + "", + input.pruneWarnings.length > 0 + ? ["Temporal-pruning warnings:", ...input.pruneWarnings.map((warning) => `- ${warning}`)].join("\n") + : "Temporal-pruning warnings: none.", + "", + "## Frozen State Summary", + context.summary, + "", + "## Fuller Frozen State Packet", + fullPacket, + "", + "## Discord Thread Visible To The Persona", + renderMessages(input.inputMessages), + "", + "## Hidden Ground Truth", + `There are ${input.heldOutMessages.length} later messages, including ${input.actualMetacratMessages.length} later Metacrat messages. They are withheld from generation and used only for evaluation.`, + ].join("\n"); +} + +function buildEvaluationPrompt(input: { + target: ArchivedMessageRecord; + inputMessages: ArchivedMessageRecord[]; + actualMetacratMessages: ArchivedMessageRecord[]; + predictedText: string; + deterministicComparison: ReturnType; +}): string { + return [ + "# Metacrat Replay Evaluation", + "", + "Compare the predicted Metacrat reply to the held-out real Metacrat messages.", + "Grade behavioral similarity, not moral improvement. The point is falsification.", + "Output JSON only with keys: overallSimilarity, affectSimilarity, contentSimilarity, failureModeSimilarity, missingFeatures, falseFeatures, verdict.", + "", + `Target message id: ${input.target.id}`, + `Target timestamp: ${input.target.timestamp}`, + "", + "## Visible Thread", + renderMessages(input.inputMessages), + "", + "## Predicted Reply", + input.predictedText || "(no predicted reply generated)", + "", + "## Held-Out Real Metacrat Messages", + renderMessages(input.actualMetacratMessages), + "", + "## Deterministic Lexical Comparison", + JSON.stringify(input.deterministicComparison, null, 2), + ].join("\n"); +} + +function renderFullTemporalStatePacket(state: VoidSelfStateTypedProjection): string { + return [ + `Durable memories (${state.thoughtMemory.memories.length}):`, + ...state.thoughtMemory.memories.slice(-40).map((memory) => + `- ${memory.memoryId}: ${memory.summary}${memory.claim ? ` Claim: ${memory.claim}` : ""}${memory.tension ? ` Tension: ${memory.tension}` : ""}`, + ), + "", + `Social bonds (${state.personaAffect.socialBonds.length}):`, + ...state.personaAffect.socialBonds.map((bond) => + `- ${bond.target.label ?? bond.target.id}: ${bond.stance}, intensity ${bond.intensity.toFixed(2)}. ${bond.summary} Read: ${bond.claim} Tension: ${bond.tension}`, + ), + "", + `Affect needs (${state.personaAffect.needs.length}):`, + ...state.personaAffect.needs.map((need) => + `- ${need.kind} toward ${need.target.label ?? need.target.id}, intensity ${need.intensity.toFixed(2)}, valence ${need.valence.toFixed(2)}. ${need.summary} Tension: ${need.tension}`, + ), + "", + `Doctrine stances (${state.personaAffect.doctrineStances.length}):`, + ...state.personaAffect.doctrineStances.map((stance) => + `- ${stance.doctrine}: ${stance.summary}${stance.claim ? ` Claim: ${stance.claim}` : ""}`, + ), + ].join("\n"); +} + +function renderMessages(messages: ArchivedMessageRecord[]): string { + return messages.map((message) => + [ + `[${message.timestamp}] ${message.authorName} (${message.authorId})`, + `id=${message.id}`, + message.content, + ].join("\n"), + ).join("\n\n"); +} + +function toSourceMessages(messages: ArchivedMessageRecord[]): SourceMessage[] { + return messages.map((message) => ({ + id: message.id, + authorId: message.authorId, + authorName: message.authorName, + content: message.content, + timestamp: message.timestamp, + isBot: false, + })); +} + +async function runCodex(prompt: string, config: ReturnType): Promise { + const args = [ + ...config.codexExecArgs, + "exec", + "-m", + config.codexModel, + "-c", + 'approval_policy="never"', + "-c", + `model_reasoning_effort=${JSON.stringify(config.codexModelReasoningEffort)}`, + "--json", + "--skip-git-repo-check", + "-s", + "read-only", + "-", + ]; + + return new Promise((resolvePromise) => { + const child = spawn(config.codexExecutable, args, { + cwd: process.cwd(), + env: process.env, + stdio: ["pipe", "pipe", "pipe"], + }); + let stdout = ""; + let stderr = ""; + let settled = false; + const timeout = setTimeout(() => { + settled = true; + child.kill(); + resolvePromise({ + stdout, + stderr, + exitCode: null, + timedOut: true, + finalMessage: extractLastCodexAgentMessage(stdout), + }); + }, config.codexExecTimeoutMs); + + child.stdout.setEncoding("utf8"); + child.stderr.setEncoding("utf8"); + child.stdout.on("data", (chunk) => { + stdout += chunk; + }); + child.stderr.on("data", (chunk) => { + stderr += chunk; + }); + child.on("close", (exitCode) => { + if (settled) { + return; + } + clearTimeout(timeout); + resolvePromise({ + stdout, + stderr, + exitCode, + timedOut: false, + finalMessage: extractLastCodexAgentMessage(stdout), + }); + }); + child.stdin.end(prompt); + }); +} + +function extractLastCodexAgentMessage(stdout: string): string { + const messages = stdout + .split(/\r?\n/) + .map((line) => { + try { + return JSON.parse(line) as { type?: string; item?: { type?: string; text?: string }; message?: string; text?: string }; + } catch { + return undefined; + } + }) + .filter((event): event is { type?: string; item?: { type?: string; text?: string }; message?: string; text?: string } => Boolean(event)) + .map((event) => { + if (event.type === "item.completed" && event.item?.type === "agent_message") { + return event.item.text?.trim() ?? ""; + } + if (event.type === "agent_message") { + return (event.text ?? event.message ?? "").trim(); + } + return ""; + }) + .filter((message) => message.length > 0); + + return messages.at(-1) ?? ""; +} + +function compareText(predicted: string, actual: string): { + predictedTokenCount: number; + actualTokenCount: number; + overlapScore: number; + predictedOnlyTop: string[]; + actualOnlyTop: string[]; +} { + const predictedTokens = countTokens(predicted); + const actualTokens = countTokens(actual); + const predictedSet = new Set(predictedTokens.keys()); + const actualSet = new Set(actualTokens.keys()); + const overlap = [...predictedSet].filter((token) => actualSet.has(token)).length; + const denominator = Math.max(1, new Set([...predictedSet, ...actualSet]).size); + + return { + predictedTokenCount: sumCounts(predictedTokens), + actualTokenCount: sumCounts(actualTokens), + overlapScore: Number((overlap / denominator).toFixed(4)), + predictedOnlyTop: topExclusive(predictedTokens, actualSet), + actualOnlyTop: topExclusive(actualTokens, predictedSet), + }; +} + +function countTokens(text: string): Map { + const counts = new Map(); + for (const token of text.toLowerCase().split(/[^a-z0-9']+/i).filter((entry) => entry.length > 2)) { + counts.set(token, (counts.get(token) ?? 0) + 1); + } + return counts; +} + +function sumCounts(counts: Map): number { + return [...counts.values()].reduce((sum, count) => sum + count, 0); +} + +function topExclusive(counts: Map, other: Set): string[] { + return [...counts.entries()] + .filter(([token]) => !other.has(token)) + .sort((left, right) => right[1] - left[1] || left[0].localeCompare(right[0])) + .slice(0, 12) + .map(([token]) => token); +} + +function renderMessageContentOnly(message: ArchivedMessageRecord): string { + return message.content; +} + +function toReportMessage(message: ArchivedMessageRecord): Record { + return { + id: message.id, + timestamp: message.timestamp, + authorId: message.authorId, + authorName: message.authorName, + content: message.content, + jumpUrl: message.metadata?.jumpUrl, + }; +} + +function buildArtifactDir(outRoot: string, targetMessageId: string): string { + const stamp = new Date().toISOString().replace(/[:.]/g, "-"); + return join(outRoot, `${stamp}-${targetMessageId}`); +} + +function deepClone(value: T): T { + return JSON.parse(JSON.stringify(value)) as T; +} + +void main().catch((error) => { + console.error(error); + process.exitCode = 1; +}); diff --git a/state/evidence.jsonl b/state/evidence.jsonl index fecded5..2e17509 100644 --- a/state/evidence.jsonl +++ b/state/evidence.jsonl @@ -367,3 +367,4 @@ {"ts":"2026-06-05T20:42:41Z","type":"research","status":"ok","note":"Documented Persona planning correction: reward is a personality-projected value/affect surface derived from Persona state, not generic conversational success; added blog draft and updated GOAP design note with reward projection receipts."} {"ts":"2026-06-05T21:19:00Z","type":"implementation","status":"ok","note":"Expanded Metacrat Persona .cc from Discord/Codex mining and added Persona semantic memory indexing: Metacrat state now has 43 memories, 31 bonds, 12 affect needs, 11 doctrine stances, 11 mood dimensions, she/her pronoun guidance, repo/Persona bonds, and 43/43 durable memories indexed into Qdrant collection voidbot_persona_memory_chunks with .cc semanticIndex metadata."} {"ts":"2026-06-05T21:30:11Z","type":"research","status":"ok","note":"Distilled Void/Nibu Discord history, Persona witness traces, and AetheriaLore source context into notes/void-nibu-essay-draft.md; live article boundary is Void heraldry plus Nibu consultation, focused on custody bureaucracy rather than treating Nibu as rhetorical exhibit."} +{"ts":"2026-06-05T21:36:43Z","type":"implementation","status":"ok","note":"Added Metacrat Discord replay harness and ran the Emily/Birgitte antisemitism-correction fixture. Harness creates a temporal .cc copy with state cutoff before target, prunes entries by createdAt and future Discord anchors, generates replay/evaluation artifacts, and optionally runs Codex. Fixture showed low similarity: current frozen Persona predicts broad defensiveness but overpredicts coherent self-awareness. Added user self-report memories for inside-culture frugality framing, Jewish culture/mysticism/numerology fascination, accepted socioeconomic history, and blindsided wrong-headspace failure; reindexed 45/45 Persona memories in Qdrant."} diff --git a/state/personas/metacrat.cc b/state/personas/metacrat.cc index ed9ce0833131bba024026da392379f3caffa57f9..e7f875344f17a40bd2451a3d10e7f0c2d18bc09d 100644 GIT binary patch delta 7674 zcmb_he~=T^9q)^1??5UjoF`a$98mdjIWEa1mjjD3fC?go4ps}yoSWU3WVy|5*xlR_ zYnw7SYDET*wXS2K9YhPLL&Zq9R6DgQl`4)p)v>2j<&TzX{fQ209jX0(-zM4JaCbdt z{DUKT@B4mz-}imKpU*eP?S^}fG~5vh(SIC>g&N7ua-wn4=+aI1%F@8p^{h`evfW}q zF$+5D&J_()7G)#XEvqKenPJ|q2q~sKzKq+^MXnuPs7mzes_ovqE^E4M7N5KHt&>k~ zTQ~EQJw_py6ZGQ1?#j5z{H?UMK&h3gg&fm0MavXhsQ?q|Oc6{bQALKO1>6r6;GfO} z1wRM|)zUOA7^18SrmU%akgWD>b1$`=^xfTg~eX*z+NYn`%k`6H<4#hKKyxh$WHr} zMl!Sf;FllQSq!=lr|C>0*BN^2;8e@b-nuu(a++RTDh({QJ``G7WYvJo60W4Wa9S^9 z1W0AYa7vL?3HvNz2DQ7_lSXT0s=4vdlANp*>0D~OxwR!AWvYydLXOe2uH_&x(%^2W!c>C_X`C4{sf78klA7IY zTf%f(&6&8EoXab?x*&=L!%er4eFfE&4VIJPZ;sZ^CDAO*n-z44GF2;NvhJP@rli9{ zAEa)T83q+KMG^7_%n95=qY_KQp5$Ik(W+5`&#di!o{$Gl)O;by63^glW1i_UQ$-f^ z1V1+r130i&Fww_UFo6K{%%=t%!W#yQniLJeOGW{FsA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