Bolt recent chat into Void self-state
This commit is contained in:
parent
d6e20e674e
commit
52a9010ad6
5 changed files with 57 additions and 4 deletions
|
|
@ -153,8 +153,13 @@ export interface PromptHandlerOptions {
|
|||
}
|
||||
|
||||
export async function handlePrompt(options: PromptHandlerOptions): Promise<void> {
|
||||
const recentMessages = await getRecentMessages(options.channel, 10);
|
||||
const voidSelfState = await loadVoidSelfState(
|
||||
options.config.moderationAgentStatePath,
|
||||
{
|
||||
recentMessages,
|
||||
guildContext: options.guildContext,
|
||||
},
|
||||
);
|
||||
const sleepModeActive = voidSelfState?.projection?.mode === "napping";
|
||||
const requestedProviderName =
|
||||
|
|
@ -230,7 +235,6 @@ export async function handlePrompt(options: PromptHandlerOptions): Promise<void>
|
|||
|
||||
let interactionMemory = await options.interactionMemory.getProfile(options.actor.id);
|
||||
|
||||
const recentMessages = await getRecentMessages(options.channel, 10);
|
||||
const situationalSocialRead = sleepModeActive
|
||||
? undefined
|
||||
: await inferSituationalSocialRead(options, {
|
||||
|
|
|
|||
|
|
@ -1,12 +1,22 @@
|
|||
import { readFile } from "node:fs/promises";
|
||||
|
||||
import { type VoidSelfStateContext } from "@voidbot/shared";
|
||||
import {
|
||||
type GuildContext,
|
||||
type SourceMessage,
|
||||
type VoidSelfStateContext,
|
||||
} from "@voidbot/shared";
|
||||
|
||||
type JsonValue = null | boolean | number | string | JsonValue[] | { [key: string]: JsonValue };
|
||||
type JsonObject = { [key: string]: JsonValue };
|
||||
|
||||
export interface LoadVoidSelfStateOptions {
|
||||
recentMessages?: SourceMessage[];
|
||||
guildContext?: GuildContext;
|
||||
}
|
||||
|
||||
export async function loadVoidSelfState(
|
||||
statePath: string,
|
||||
options: LoadVoidSelfStateOptions = {},
|
||||
): Promise<VoidSelfStateContext | undefined> {
|
||||
let raw: string;
|
||||
|
||||
|
|
@ -28,12 +38,15 @@ export async function loadVoidSelfState(
|
|||
return {
|
||||
sourcePath: statePath,
|
||||
loadedAt: new Date().toISOString(),
|
||||
summary: renderVoidSelfStateSummary(parsed),
|
||||
summary: renderVoidSelfStateSummary(parsed, options),
|
||||
projection,
|
||||
};
|
||||
}
|
||||
|
||||
function renderVoidSelfStateSummary(state: JsonObject): string {
|
||||
function renderVoidSelfStateSummary(
|
||||
state: JsonObject,
|
||||
options: LoadVoidSelfStateOptions,
|
||||
): string {
|
||||
const identity = getObject(state, "identity");
|
||||
const goals = getArray(state, "goals");
|
||||
const memories = getObject(state, "memories");
|
||||
|
|
@ -127,6 +140,7 @@ function renderVoidSelfStateSummary(state: JsonObject): string {
|
|||
const lastRun = getObject(runtime, "last_run");
|
||||
const lastRunSummary = readString(lastRun, "summary");
|
||||
const sleepCycleSummary = renderSleepCycleSummary(runtime, memories);
|
||||
const transientRoomLog = renderTransientRoomLog(options);
|
||||
|
||||
return [
|
||||
`- Identity: ${readString(identity, "name") ?? "Void"}${readString(identity, "public_description") ? ` - ${readString(identity, "public_description")}` : ""}`,
|
||||
|
|
@ -181,6 +195,34 @@ function renderVoidSelfStateSummary(state: JsonObject): string {
|
|||
candidateInterventions.length > 0
|
||||
? ["- Draft conversation/intervention seeds:", ...candidateInterventions].join("\n")
|
||||
: "- Draft conversation/intervention seeds: none recorded.",
|
||||
transientRoomLog,
|
||||
].join("\n");
|
||||
}
|
||||
|
||||
function renderTransientRoomLog(options: LoadVoidSelfStateOptions): string {
|
||||
const recentMessages = (options.recentMessages ?? []).slice(-10);
|
||||
const guildName = options.guildContext?.guildName ?? options.guildContext?.guildId ?? "(direct/unknown)";
|
||||
const channelName =
|
||||
options.guildContext?.channelName ?? options.guildContext?.channelId ?? "(unknown channel)";
|
||||
|
||||
if (recentMessages.length === 0) {
|
||||
return [
|
||||
"- Temporary invocation room log:",
|
||||
`- Current room: guild=${guildName}; channel=${channelName}`,
|
||||
"- No recent chat messages were attached to this invocation.",
|
||||
].join("\n");
|
||||
}
|
||||
|
||||
const lines = recentMessages.map(
|
||||
(message) =>
|
||||
`- [${message.timestamp}] ${message.authorName}: ${collapseWhitespace(message.content || "(no text content)")}`,
|
||||
);
|
||||
|
||||
return [
|
||||
"- Temporary invocation room log:",
|
||||
"- Treat this as live working memory for the current summon, not durable canon.",
|
||||
`- Current room: guild=${guildName}; channel=${channelName}`,
|
||||
...lines,
|
||||
].join("\n");
|
||||
}
|
||||
|
||||
|
|
@ -425,3 +467,7 @@ function readNumber(value: JsonObject | undefined, key: string): number | undefi
|
|||
function isObject(value: JsonValue | undefined): value is JsonObject {
|
||||
return typeof value === "object" && value !== null && !Array.isArray(value);
|
||||
}
|
||||
|
||||
function collapseWhitespace(value: string): string {
|
||||
return value.replace(/\s+/g, " ").trim();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ export function buildSystemPrompt(context: ContextBundle): string {
|
|||
"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.",
|
||||
"If that shared self-state includes a temporary invocation room log, treat it as live working memory for this summon rather than ornamental flavor text.",
|
||||
"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.",
|
||||
`Sleep projection: ${sleepInstructions}`,
|
||||
"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.",
|
||||
|
|
|
|||
|
|
@ -105,6 +105,7 @@ export function buildDiscordReplyPrompt(
|
|||
"- 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.",
|
||||
"- If that shared self-state includes a temporary invocation room log, treat it as live working memory for this summon instead of decorative background flavor.",
|
||||
"- 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.",
|
||||
sleepInstructions,
|
||||
"- 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.",
|
||||
|
|
|
|||
|
|
@ -51,3 +51,4 @@
|
|||
{"ts":"2026-05-05T10:53:00Z","type":"implementation","status":"ok","note":"The moderation loop was missing live Discord traffic because recent-history helpers compared ISO timestamp strings instead of actual times, so local +01:00 cursors skipped later Z-stamped messages. History helpers now compare parsed timestamps, and the moderation runner clamps the saved cursor to the pre-run observed latest live message so quiet rumination cannot step over mid-run chatter."}
|
||||
{"ts":"2026-05-05T11:22:36Z","type":"implementation","status":"ok","note":"owner_codex was hitting spawn ENAMETOOLONG on Windows because the full Discord prompt rode the command line; the local exec path now passes the prompt over stdin with a trailing '-' argument instead, matching the moderation runner and avoiding argument-length failure."}
|
||||
{"ts":"2026-05-05T11:37:24Z","type":"implementation","status":"ok","note":"The scheduled moderation runner was failing before it wrote status because Task Scheduler launched it from a non-repo working directory and the preflight history poll used a relative node script path. The runner now anchors itself to the repo root, resolves the helper by absolute path, and the task registration sets an explicit working directory too."}
|
||||
{"ts":"2026-05-05T12:40:41Z","type":"implementation","status":"ok","note":"Direct Void summons were carrying recent chat as a parallel context bundle lane, which made it too easy for the model to fixate on self-state/reporting instead of the room. The shared Void self-state now gets a temporary invocation room log bolted into its summary at load time, and both reply prompts explicitly treat that embedded transcript as live working memory for the current summon."}
|
||||
|
|
|
|||
Loading…
Reference in a new issue