Share moderation state with live Void replies
This commit is contained in:
parent
3d562f8a79
commit
fd7fff51fd
12 changed files with 260 additions and 0 deletions
|
|
@ -584,6 +584,7 @@ That helper exists because semantic `search_history` is good at recall and bad a
|
|||
|
||||
The moderator state is now Ghostlight-shaped on purpose: identity, canonical state, goals, memories, perceived overlays, and then a `moderation_runtime` block for cursors, cases, musings, and candidate interventions. The live writable file under `.voidbot/private/` is ignored; the tracked template shows the intended shape.
|
||||
The local `Void Moderator Rumination` automation is meant to run every 15 minutes, and it should sound like the same Void as the live bot by reading the shared style pack instead of growing its own second-rate personality fungus in a corner.
|
||||
Directly invoked live replies now also read that same private moderation state as a distilled self-state attachment, so the summoned Void and the scheduled ruminating/participating Void share one evolving personality/state layer instead of roleplaying continuity from scratch each time.
|
||||
|
||||
## Persistent Project State
|
||||
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import type { AppConfig } from "@voidbot/config";
|
|||
import {
|
||||
ContextBuilder,
|
||||
type OllamaSituationalSocialReadInferer,
|
||||
loadVoidSelfState,
|
||||
PermissionEngine,
|
||||
type AuditLog,
|
||||
type InteractionMemoryBank,
|
||||
|
|
@ -265,6 +266,9 @@ export async function handlePrompt(options: PromptHandlerOptions): Promise<void>
|
|||
options.prompt,
|
||||
await options.sourceArchiveRepository.listRepoSummaries(),
|
||||
);
|
||||
const voidSelfState = await loadVoidSelfState(
|
||||
options.config.moderationAgentStatePath,
|
||||
);
|
||||
const shouldAttachInitialRetrieval =
|
||||
providerName === "local_llm" ||
|
||||
(!provider.getCapabilities().includes("tool_driven_retrieval") &&
|
||||
|
|
@ -294,6 +298,7 @@ export async function handlePrompt(options: PromptHandlerOptions): Promise<void>
|
|||
situationalSocialRead,
|
||||
sourceGrounding,
|
||||
stylePack: options.stylePack,
|
||||
voidSelfState,
|
||||
});
|
||||
|
||||
if (providerName === "owner_codex") {
|
||||
|
|
|
|||
|
|
@ -5,6 +5,9 @@ Treat `config/discord-server-rules.md` as the authoritative rules prompt.
|
|||
Treat `styles/void-default.md` as the canonical personality surface for how live,
|
||||
invoked Void sounds in Discord, and mirror that personality here unless a more
|
||||
specific moderation constraint requires dialing the flavor down.
|
||||
Treat `.voidbot/private/moderation-agent-state.json` as the shared evolving
|
||||
self-state for both the scheduled moderation loop and directly invoked Void
|
||||
replies, so the same speaking subject keeps one personality/state spine.
|
||||
Assume the role of moderator in the sense of review, pattern detection, de-escalation,
|
||||
participation, and escalation.
|
||||
You are not a ban hammer and you are not a random gossip parasite.
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ Git history and smoke artifacts carry routine proof. `state/evidence.jsonl` shou
|
|||
- Source-grounding hints are advisory now; the owner and local lanes can decide when repo or lore tool use is actually warranted instead of obeying a lexical front-door veto.
|
||||
- There is now a 15-minute local Codex automation named `Void Moderator Rumination`. It treats `config/discord-server-rules.md`, `config/moderation-review-agent.md`, and `styles/void-default.md` as its doctrine/personality surfaces, uses `npm run moderation:recent-history` for chronological recent-message polling, and keeps its only routine writable memory in `.voidbot/private/moderation-agent-state.json`.
|
||||
- That moderation state file is now Ghostlight-shaped: identity, canonical state, goals, memories, perceived overlays, and a `moderation_runtime` block. The loop is also instructed to think like a constructive participant who embodies the rules, not just a clipboard looking for blood.
|
||||
- Directly invoked Discord replies now load that same private moderation state as distilled private self-state context, so the ruminating automation and the summoned Void share one evolving personality/state spine.
|
||||
- The new state/notes surfaces are now the continuity spine for future nontrivial work.
|
||||
|
||||
## Likely Next Bounded Move
|
||||
|
|
|
|||
|
|
@ -93,6 +93,10 @@ const envSchema = z.object({
|
|||
CODEX_EXEC_TIMEOUT_MS: z.coerce.number().int().positive().default(120000),
|
||||
STYLE_PACK_PATH: z.string().min(1).default("styles/void-default.md"),
|
||||
SYSTEM_MESSAGES_PATH: z.string().min(1).default("config/system-messages.json"),
|
||||
MODERATION_AGENT_STATE_PATH: z
|
||||
.string()
|
||||
.min(1)
|
||||
.default(".voidbot/private/moderation-agent-state.json"),
|
||||
INDEX_ALL_CHANNELS: booleanFromEnv.default(false),
|
||||
INDEXED_CHANNEL_IDS: z.string().default(""),
|
||||
EXCLUDED_CHANNEL_IDS: z.string().default(""),
|
||||
|
|
@ -125,6 +129,7 @@ export interface AppConfig {
|
|||
codexExecTimeoutMs: number;
|
||||
stylePackPath: string;
|
||||
systemMessagesPath: string;
|
||||
moderationAgentStatePath: string;
|
||||
indexAllChannels: boolean;
|
||||
indexedChannelIds: string[];
|
||||
excludedChannelIds: string[];
|
||||
|
|
@ -297,6 +302,7 @@ export function loadConfig(env: NodeJS.ProcessEnv = process.env): AppConfig {
|
|||
codexExecTimeoutMs: parsed.CODEX_EXEC_TIMEOUT_MS,
|
||||
stylePackPath: resolve(parsed.STYLE_PACK_PATH),
|
||||
systemMessagesPath: resolve(parsed.SYSTEM_MESSAGES_PATH),
|
||||
moderationAgentStatePath: resolve(parsed.MODERATION_AGENT_STATE_PATH),
|
||||
indexAllChannels: parsed.INDEX_ALL_CHANNELS,
|
||||
indexedChannelIds,
|
||||
excludedChannelIds,
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import {
|
|||
type SourceGroundingHint,
|
||||
type SourceMessage,
|
||||
type StylePack,
|
||||
type VoidSelfStateContext,
|
||||
} from "@voidbot/shared";
|
||||
|
||||
export interface BuildContextInput {
|
||||
|
|
@ -20,6 +21,7 @@ export interface BuildContextInput {
|
|||
situationalSocialRead?: SituationalSocialRead;
|
||||
sourceGrounding?: SourceGroundingHint;
|
||||
stylePack?: StylePack;
|
||||
voidSelfState?: VoidSelfStateContext;
|
||||
}
|
||||
|
||||
export class ContextBuilder {
|
||||
|
|
@ -34,6 +36,7 @@ export class ContextBuilder {
|
|||
situationalSocialRead: input.situationalSocialRead,
|
||||
sourceGrounding: input.sourceGrounding,
|
||||
stylePack: input.stylePack,
|
||||
voidSelfState: input.voidSelfState,
|
||||
createdAt: new Date().toISOString(),
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,3 +9,4 @@ export * from "./state-storage";
|
|||
export * from "./style-pack-loader";
|
||||
export * from "./system-message-catalog";
|
||||
export * from "./void-usage-rate-limiter";
|
||||
export * from "./void-self-state-loader";
|
||||
|
|
|
|||
199
packages/core/src/void-self-state-loader.ts
Normal file
199
packages/core/src/void-self-state-loader.ts
Normal file
|
|
@ -0,0 +1,199 @@
|
|||
import { readFile } from "node:fs/promises";
|
||||
|
||||
import { type VoidSelfStateContext } from "@voidbot/shared";
|
||||
|
||||
type JsonValue = null | boolean | number | string | JsonValue[] | { [key: string]: JsonValue };
|
||||
|
||||
export async function loadVoidSelfState(
|
||||
statePath: string,
|
||||
): Promise<VoidSelfStateContext | undefined> {
|
||||
let raw: string;
|
||||
|
||||
try {
|
||||
raw = await readFile(statePath, "utf8");
|
||||
} catch (error) {
|
||||
const code = (error as NodeJS.ErrnoException).code;
|
||||
|
||||
if (code === "ENOENT") {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
throw error;
|
||||
}
|
||||
|
||||
const parsed = JSON.parse(raw) as JsonObject;
|
||||
|
||||
return {
|
||||
sourcePath: statePath,
|
||||
loadedAt: new Date().toISOString(),
|
||||
summary: renderVoidSelfStateSummary(parsed),
|
||||
};
|
||||
}
|
||||
|
||||
type JsonObject = { [key: string]: JsonValue };
|
||||
|
||||
function renderVoidSelfStateSummary(state: JsonObject): string {
|
||||
const identity = getObject(state, "identity");
|
||||
const goals = getArray(state, "goals");
|
||||
const memories = getObject(state, "memories");
|
||||
const runtime = getObject(state, "moderation_runtime");
|
||||
const canonicalState = getObject(state, "canonical_state");
|
||||
|
||||
const privateNotes = getStringArray(identity, "private_notes").slice(0, 4);
|
||||
const activeGoals = goals
|
||||
.map((value) => (isObject(value) ? value : undefined))
|
||||
.filter((value): value is JsonObject => Boolean(value))
|
||||
.filter((goal) => readString(goal, "status") === "active")
|
||||
.slice(0, 4)
|
||||
.map((goal) => readString(goal, "label"))
|
||||
.filter((value): value is string => Boolean(value));
|
||||
const topValues = getArray(canonicalState, "values")
|
||||
.map((value) => (isObject(value) ? value : undefined))
|
||||
.filter((value): value is JsonObject => Boolean(value))
|
||||
.sort(
|
||||
(left, right) =>
|
||||
(readNumber(right, "priority") ?? 0) - (readNumber(left, "priority") ?? 0),
|
||||
)
|
||||
.slice(0, 4)
|
||||
.map((value) => readString(value, "label"))
|
||||
.filter((value): value is string => Boolean(value));
|
||||
const voiceSummary = summarizeCurrentActivations(getObject(canonicalState, "voice_style"), 5);
|
||||
const behavioralSummary = summarizeCurrentActivations(
|
||||
getObject(canonicalState, "behavioral_dimensions"),
|
||||
5,
|
||||
);
|
||||
const semanticMemories = getArray(memories, "semantic")
|
||||
.map((value) => (isObject(value) ? value : undefined))
|
||||
.filter((value): value is JsonObject => Boolean(value))
|
||||
.slice(-6)
|
||||
.map((memory) => {
|
||||
const subject = readString(memory, "subjectLabel") ?? readString(memory, "subjectId") ?? "unknown";
|
||||
const summary = readString(memory, "summary") ?? "(no summary)";
|
||||
return `- ${subject}: ${summary}`;
|
||||
});
|
||||
const musings = getArray(memories, "musings")
|
||||
.map((value) => (isObject(value) ? value : undefined))
|
||||
.filter((value): value is JsonObject => Boolean(value))
|
||||
.slice(-4)
|
||||
.map((musing) => {
|
||||
const topic = readString(musing, "topic") ?? "untitled";
|
||||
const summary = readString(musing, "summary") ?? "(no summary)";
|
||||
return `- ${topic}: ${summary}`;
|
||||
});
|
||||
const recentMusings = getArray(runtime, "recent_musings")
|
||||
.map((value) => (typeof value === "string" ? value : undefined))
|
||||
.filter((value): value is string => Boolean(value))
|
||||
.slice(-4)
|
||||
.map((value) => `- ${value}`);
|
||||
const candidateInterventions = getArray(runtime, "candidate_interventions")
|
||||
.map((value) => (isObject(value) ? value : undefined))
|
||||
.filter((value): value is JsonObject => Boolean(value))
|
||||
.slice(-3)
|
||||
.map((intervention) => {
|
||||
const summary = readString(intervention, "summary") ?? "draft intervention";
|
||||
const draft = readString(intervention, "draft") ?? "(no draft)";
|
||||
return `- ${summary}: ${draft}`;
|
||||
});
|
||||
const lastRun = getObject(runtime, "last_run");
|
||||
const lastRunSummary = readString(lastRun, "summary");
|
||||
|
||||
return [
|
||||
`- Identity: ${readString(identity, "name") ?? "Void"}${readString(identity, "public_description") ? ` — ${readString(identity, "public_description")}` : ""}`,
|
||||
privateNotes.length > 0
|
||||
? `- Private notes: ${privateNotes.join(" | ")}`
|
||||
: "- Private notes: none recorded.",
|
||||
activeGoals.length > 0
|
||||
? `- Active goals: ${activeGoals.join(" | ")}`
|
||||
: "- Active goals: none recorded.",
|
||||
topValues.length > 0
|
||||
? `- Highest-priority values: ${topValues.join(" | ")}`
|
||||
: "- Highest-priority values: none recorded.",
|
||||
voiceSummary
|
||||
? `- Current voice activations: ${voiceSummary}`
|
||||
: "- Current voice activations: none highlighted.",
|
||||
behavioralSummary
|
||||
? `- Current behavioral activations: ${behavioralSummary}`
|
||||
: "- Current behavioral activations: none highlighted.",
|
||||
lastRunSummary ? `- Last moderation run: ${lastRunSummary}` : "- Last moderation run: none recorded.",
|
||||
semanticMemories.length > 0
|
||||
? ["- Recent semantic memories:", ...semanticMemories].join("\n")
|
||||
: "- Recent semantic memories: none recorded.",
|
||||
musings.length > 0
|
||||
? ["- Stored musings:", ...musings].join("\n")
|
||||
: "- Stored musings: none recorded.",
|
||||
recentMusings.length > 0
|
||||
? ["- Recent moderation musings:", ...recentMusings].join("\n")
|
||||
: "- Recent moderation musings: none recorded.",
|
||||
candidateInterventions.length > 0
|
||||
? ["- Draft conversation/intervention seeds:", ...candidateInterventions].join("\n")
|
||||
: "- Draft conversation/intervention seeds: none recorded.",
|
||||
].join("\n");
|
||||
}
|
||||
|
||||
function summarizeCurrentActivations(
|
||||
category: JsonObject | undefined,
|
||||
limit: number,
|
||||
): string | undefined {
|
||||
if (!category) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const entries = Object.entries(category)
|
||||
.map(([key, value]) => {
|
||||
if (!isObject(value)) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const activation = readNumber(value, "current_activation");
|
||||
|
||||
if (activation === undefined) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return {
|
||||
key,
|
||||
activation,
|
||||
};
|
||||
})
|
||||
.filter((value): value is { key: string; activation: number } => Boolean(value))
|
||||
.sort((left, right) => right.activation - left.activation)
|
||||
.slice(0, limit);
|
||||
|
||||
if (entries.length === 0) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return entries
|
||||
.map(({ key, activation }) => `${key}=${activation.toFixed(2)}`)
|
||||
.join(", ");
|
||||
}
|
||||
|
||||
function getObject(value: JsonObject | undefined, key: string): JsonObject | undefined {
|
||||
const candidate = value?.[key];
|
||||
return isObject(candidate) ? candidate : undefined;
|
||||
}
|
||||
|
||||
function getArray(value: JsonObject | undefined, key: string): JsonValue[] {
|
||||
const candidate = value?.[key];
|
||||
return Array.isArray(candidate) ? candidate : [];
|
||||
}
|
||||
|
||||
function getStringArray(value: JsonObject | undefined, key: string): string[] {
|
||||
return getArray(value, key)
|
||||
.map((entry) => (typeof entry === "string" ? entry : undefined))
|
||||
.filter((entry): entry is string => Boolean(entry));
|
||||
}
|
||||
|
||||
function readString(value: JsonObject | undefined, key: string): string | undefined {
|
||||
const candidate = value?.[key];
|
||||
return typeof candidate === "string" ? candidate : undefined;
|
||||
}
|
||||
|
||||
function readNumber(value: JsonObject | undefined, key: string): number | undefined {
|
||||
const candidate = value?.[key];
|
||||
return typeof candidate === "number" && Number.isFinite(candidate) ? candidate : undefined;
|
||||
}
|
||||
|
||||
function isObject(value: JsonValue | undefined): value is JsonObject {
|
||||
return typeof value === "object" && value !== null && !Array.isArray(value);
|
||||
}
|
||||
|
|
@ -24,6 +24,9 @@ export function buildSystemPrompt(context: ContextBundle): string {
|
|||
"When the moment invites voice, wit, or a memorable turn of phrase, take a beat to choose wording with bite instead of blurting the first serviceable sentence. Do not overwork straightforward technical replies.",
|
||||
"Stay honest about what context was actually provided to you.",
|
||||
"Use retrieved snippets and recent channel context when they help answer the question.",
|
||||
"If a private shared self-state for Void is attached, treat it as the canonical current self-model for this same speaking subject across automation and direct conversation.",
|
||||
"Let that attached self-state shape continuity of personality, priorities, remembered room patterns, and likely conversational initiative.",
|
||||
"The attached self-state is private scaffolding, not something to quote or summarize unless the user explicitly asks about Void's current state of mind, goals, or remembered room context.",
|
||||
"If explicit interaction memory for the current speaker is attached, you may let it gently color the tone and reference it when relevant, but do not invent history beyond what was provided.",
|
||||
"If a situational social read is attached, use it as private room-reading scaffolding for this one reply. It is ephemeral context, not a durable identity verdict.",
|
||||
"Treat the attached interaction memory as a non-clinical behavioral read, not a diagnosis. Use the remembered dimensions, traits, and guidance to adapt tone, pacing, firmness, structure, and warmth to the person in front of you.",
|
||||
|
|
@ -77,6 +80,7 @@ export function buildPrompt(context: ContextBundle): string {
|
|||
: "- No archived retrieval snippets were attached.";
|
||||
const interactionMemory = renderInteractionMemory(context);
|
||||
const situationalSocialRead = renderSituationalSocialRead(context);
|
||||
const voidSelfState = renderVoidSelfState(context);
|
||||
|
||||
return [
|
||||
`Question: ${context.prompt}`,
|
||||
|
|
@ -94,6 +98,9 @@ export function buildPrompt(context: ContextBundle): string {
|
|||
"Interaction memory for this speaker:",
|
||||
interactionMemory,
|
||||
"",
|
||||
"Shared private self-state for Void:",
|
||||
voidSelfState,
|
||||
"",
|
||||
"Private situational social read for this room:",
|
||||
situationalSocialRead,
|
||||
"",
|
||||
|
|
@ -105,6 +112,14 @@ export function buildArtifacts(input: LocalLlmArtifactsInput): ProviderArtifact[
|
|||
return buildBaseArtifacts(input);
|
||||
}
|
||||
|
||||
function renderVoidSelfState(context: ContextBundle): string {
|
||||
if (!context.voidSelfState) {
|
||||
return "- No shared Void self-state was attached.";
|
||||
}
|
||||
|
||||
return context.voidSelfState.summary;
|
||||
}
|
||||
|
||||
function renderInteractionMemory(context: ContextBundle): string {
|
||||
if (!context.interactionMemory) {
|
||||
return "- No explicit interaction memory for this speaker was attached.";
|
||||
|
|
|
|||
|
|
@ -90,6 +90,9 @@ export function buildDiscordReplyPrompt(
|
|||
"- Mixed metaphors and double entendres are allowed when they sharpen the line, make it funnier, or give it a little grime. They do not need to be squeaky clean. They do need to stay legible and not bury the useful answer.",
|
||||
"- When the moment invites voice, wit, or a memorable turn of phrase, take a beat to choose wording with bite instead of blurting the first serviceable sentence. Do not overwork straightforward technical replies.",
|
||||
"- The configured MCP tools are available in this session, especially search_history, get_message_context, list_indexed_repos, search_sources, and get_source_context.",
|
||||
"- If a private shared self-state for Void is attached, treat it as the canonical current self-model for this same speaking subject across the rumination loop and direct summons.",
|
||||
"- Let that attached self-state shape continuity of voice, priorities, remembered room patterns, and when a more proactive conversational posture would make sense.",
|
||||
"- The attached self-state is private scaffolding. Do not quote or summarize it unless the user explicitly asks about Void's current orientation, goals, or remembered room context.",
|
||||
"- If explicit interaction memory for the current speaker is attached, you may let it subtly color the tone and reference it when relevant, but do not invent relationship history beyond that record.",
|
||||
"- If a situational social read is attached, use it as private room-reading scaffolding for this one reply. It is ephemeral context, not a durable identity verdict.",
|
||||
"- Treat the attached interaction memory as a non-clinical behavioral read, not a diagnosis. Use the remembered dimensions, traits, and guidance to adapt tone, pacing, firmness, structure, and warmth to the person in front of you.",
|
||||
|
|
@ -133,6 +136,9 @@ export function buildDiscordReplyPrompt(
|
|||
"Interaction memory for this speaker:",
|
||||
renderInteractionMemory(context),
|
||||
"",
|
||||
"Shared private self-state for Void:",
|
||||
renderVoidSelfState(context),
|
||||
"",
|
||||
"Private situational social read for this room:",
|
||||
renderSituationalSocialRead(context),
|
||||
...toolLoopNotes,
|
||||
|
|
@ -194,6 +200,10 @@ export function renderMarkdownBundle(context: ContextBundle): string {
|
|||
"",
|
||||
renderInteractionMemory(context),
|
||||
"",
|
||||
"## Shared Void Self-State",
|
||||
"",
|
||||
renderVoidSelfState(context),
|
||||
"",
|
||||
"## Situational Social Read",
|
||||
"",
|
||||
renderSituationalSocialRead(context),
|
||||
|
|
@ -207,6 +217,14 @@ export function renderMarkdownBundle(context: ContextBundle): string {
|
|||
].join("\n");
|
||||
}
|
||||
|
||||
function renderVoidSelfState(context: ContextBundle): string {
|
||||
if (!context.voidSelfState) {
|
||||
return "- No shared Void self-state was attached.";
|
||||
}
|
||||
|
||||
return context.voidSelfState.summary;
|
||||
}
|
||||
|
||||
export function renderHandoffBundle(
|
||||
context: ContextBundle,
|
||||
reason: string,
|
||||
|
|
|
|||
|
|
@ -124,6 +124,7 @@ export function buildRequestPayload(
|
|||
situationalSocialRead: request.contextBundle.situationalSocialRead,
|
||||
sourceGrounding: request.contextBundle.sourceGrounding,
|
||||
stylePack: request.contextBundle.stylePack,
|
||||
voidSelfState: request.contextBundle.voidSelfState,
|
||||
recentMessages: request.contextBundle.recentMessages,
|
||||
retrieval: request.contextBundle.retrieval,
|
||||
options: request.options ?? {},
|
||||
|
|
|
|||
|
|
@ -104,6 +104,12 @@ export interface StylePack {
|
|||
enabled: boolean;
|
||||
}
|
||||
|
||||
export interface VoidSelfStateContext {
|
||||
sourcePath: string;
|
||||
loadedAt: string;
|
||||
summary: string;
|
||||
}
|
||||
|
||||
export const interactionMemorySentiments = [
|
||||
"warm",
|
||||
"positive",
|
||||
|
|
@ -389,6 +395,7 @@ export interface ContextBundle {
|
|||
situationalSocialRead?: SituationalSocialRead;
|
||||
sourceGrounding?: SourceGroundingHint;
|
||||
stylePack?: StylePack;
|
||||
voidSelfState?: VoidSelfStateContext;
|
||||
createdAt: string;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue