Keep repo Face replies in source channels

This commit is contained in:
Meta Vens 2026-06-14 13:44:11 +01:00
commit 9d6b51fc02
3 changed files with 106 additions and 12 deletions

View file

@ -945,7 +945,10 @@ function normalizeInterpretedRepoFaceSpeechDestinations(
return outputText;
}
return rewriteRepoFaceSayChannels(outputText, "current_room");
return rewriteRepoFaceSayChannels(
outputText,
inferRepoFaceImplicitSpeechChannel(input.job, input.faceOutputText) ?? "current_room",
);
}
function repoFaceOutputHasExplicitSayChannel(outputText: string): boolean {
@ -1002,6 +1005,51 @@ function rewriteRepoFaceSayChannels(outputText: string, channelSelector: string)
return rewritten.join("\n");
}
function inferRepoFaceImplicitSpeechChannel(job: JobRecord, faceOutputText: string): string | undefined {
const channelLabels = extractPromptChannelLabelMap(job.contextBundle.prompt);
if (channelLabels.size === 0) {
return undefined;
}
const currentChannel = repoIdentityDefaultSpeechChannel(job);
const normalizedCurrent = normalizeChannelSelector(currentChannel);
const text = faceOutputText.toLowerCase();
for (const [label, channelId] of channelLabels) {
if (normalizeChannelSelector(channelId) === normalizedCurrent) {
continue;
}
const escaped = escapeRegExp(label.toLowerCase());
const patterns = [
new RegExp(`(?:in|from|to|inside)\\s+\`#?${escaped}\``),
new RegExp(`(?:in|from|to|inside)\\s+#${escaped}\\b`),
new RegExp(`\\b${escaped}\\s+(?:thread|post|message|conversation|room)\\b`),
];
if (patterns.some((pattern) => pattern.test(text))) {
return channelId;
}
}
return undefined;
}
function extractPromptChannelLabelMap(prompt: string): Map<string, string> {
const map = new Map<string, string>();
for (const line of prompt.split(/\r?\n/)) {
const current = line.match(/^Current room \(([^,()]+), channel (\d{5,})\)/i);
if (current) {
map.set(normalizeChannelSelector(current[1]), current[2]);
continue;
}
const nearby = line.match(/^Nearby ([^(]+) \(channel (\d{5,})\)/i);
if (nearby) {
map.set(normalizeChannelSelector(nearby[1]), nearby[2]);
}
}
return map;
}
function escapeRegExp(value: string): string {
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
}
function parseInterpretationBlock(interpretationText: string): Record<string, string> {
const lines = interpretationText.split(/\r?\n/);
const start = lines.findIndex((line) =>
@ -1314,7 +1362,13 @@ async function postRepoIdentityIntent(job: JobRecord, intent: RepoIdentityPostIn
return false;
}
const requestedChannelId = intent.channelId ?? repoIdentityDefaultSpeechChannel(job);
const replyTargetChannelId = resolveRepoIdentityReplyTargetChannel(job, intent.replyToMessageId);
if (replyTargetChannelId && intent.channelId && normalizeChannelSelector(intent.channelId) !== normalizeChannelSelector(replyTargetChannelId)) {
console.warn(
`Coerced repo identity ${identity.id} speech for job ${job.id} from requested channel "${intent.channelId}" to reply target channel ${replyTargetChannelId}.`,
);
}
const requestedChannelId = replyTargetChannelId ?? intent.channelId ?? repoIdentityDefaultSpeechChannel(job);
const channelId = normalizeRepoIdentitySpeechChannel(identity, job, requestedChannelId);
if (!channelId) {
console.warn(`Rejected repo identity ${identity.id} speech for job ${job.id}: no Discord channel was available.`);
@ -2980,6 +3034,43 @@ function repoIdentityDefaultSpeechChannel(job: JobRecord): string | undefined {
: job.outputChannelId;
}
function resolveRepoIdentityReplyTargetChannel(
job: JobRecord,
replyToMessageId: string | undefined,
): string | undefined {
const normalizedReplyId = replyToMessageId?.trim();
if (!normalizedReplyId) {
return undefined;
}
const primaryChannelId = repoIdentityDefaultSpeechChannel(job);
if (
primaryChannelId &&
job.contextBundle.recentMessages.some((message) => message.id === normalizedReplyId)
) {
return primaryChannelId;
}
return extractPromptMessageChannelMap(job.contextBundle.prompt).get(normalizedReplyId);
}
function extractPromptMessageChannelMap(prompt: string): Map<string, string> {
const map = new Map<string, string>();
for (const line of prompt.split(/\r?\n/)) {
const chronologyMatch = line.match(/\[[^\]]*?\bchannel\s+(\d{5,})\][\s\S]*?\(message\s+(\d{5,})\)/i);
if (chronologyMatch) {
map.set(chronologyMatch[2], chronologyMatch[1]);
continue;
}
const sectionMatch = line.match(/\(\s*channel\s+(\d{5,})\s*,\s*message\s+(\d{5,})\s*\)/i);
if (sectionMatch) {
map.set(sectionMatch[2], sectionMatch[1]);
}
}
return map;
}
function normalizeRepoIdentitySpeechChannel(
identity: { channelPermissions?: Array<{ channelId: string; label?: string }> },
job: JobRecord,

View file

@ -4367,6 +4367,7 @@ function renderRepoFaceConversationTranscript(input: {
"Use the visible cross-channel chronology below to decide whether a correction is still unresolved or was already answered later by the same Face.",
"Do not infer consensus from agents repeating each other. If a human reframes, narrows, or corrects an agent's proposal, account for that correction directly.",
"If you answer the live conversation, default to the current room unless a human explicitly asks to move elsewhere.",
"If you answer or riff on a nearby-room message, set channel to that message's listed channel id and usually set reply_to to that message id. Never answer a nearby-room post in the current room just because the current room is easier to speak in.",
"Message IDs are shown so a public reply can target the message that gives it context. If you revive an older side thread, either reply_to that message id or include enough context in your message for readers to know what you mean.",
].join("\n"));
const chronology = renderVisibleConversationChronology(input);
@ -4385,15 +4386,15 @@ function renderRepoFaceConversationTranscript(input: {
option.channelId === input.channelPlan.primaryChannelId
)?.label ?? "current room";
sections.push([
`Current room (${currentLabel}), oldest to newest:`,
...formatConversationMessages(input.recentMessages, 15),
`Current room (${currentLabel}, channel ${input.channelPlan.primaryChannelId ?? "unknown"}), oldest to newest:`,
...formatConversationMessages(input.recentMessages, 15, input.channelPlan.primaryChannelId),
].join("\n"));
for (const snapshot of input.channelSnapshots) {
const label = input.channelPlan.options.find((option) => option.channelId === snapshot.channelId)?.label ??
"nearby room";
sections.push([
`Nearby ${label}, oldest to newest:`,
...formatConversationMessages(snapshot.messages, 6),
`Nearby ${label} (channel ${snapshot.channelId}), oldest to newest:`,
...formatConversationMessages(snapshot.messages, 6, snapshot.channelId),
].join("\n"));
}
return sections.join("\n\n");
@ -4404,18 +4405,18 @@ function renderVisibleConversationChronology(input: {
channelSnapshots: ChannelSnapshot[];
channelPlan: RepoFaceChannelPlan;
}): string {
const byId = new Map<string, SourceMessage & { channelLabel: string }>();
const byId = new Map<string, SourceMessage & { channelLabel: string; channelId: string }>();
const primaryLabel = input.channelPlan.options.find((option) =>
option.channelId === input.channelPlan.primaryChannelId
)?.label ?? "current room";
for (const message of input.recentMessages) {
byId.set(message.id, { ...message, channelLabel: primaryLabel });
byId.set(message.id, { ...message, channelLabel: primaryLabel, channelId: input.channelPlan.primaryChannelId ?? "unknown" });
}
for (const snapshot of input.channelSnapshots) {
const label = input.channelPlan.options.find((option) => option.channelId === snapshot.channelId)?.label ??
"nearby room";
for (const message of snapshot.messages) {
byId.set(message.id, { ...message, channelLabel: label });
byId.set(message.id, { ...message, channelLabel: label, channelId: snapshot.channelId });
}
}
@ -4432,7 +4433,7 @@ function renderVisibleConversationChronology(input: {
...messages.map((message) => {
const speaker = message.isBot ? `${message.authorName} (agent/bot)` : message.authorName;
const content = collapseWhitespace(message.content, 700) || "[no text]";
return `- [${message.channelLabel}] ${speaker} (message ${message.id}): ${content}${renderMessageAttachmentSuffix(message)}`;
return `- [${message.channelLabel} channel ${message.channelId}] ${speaker} (message ${message.id}): ${content}${renderMessageAttachmentSuffix(message)}`;
}),
].join("\n");
}
@ -4487,14 +4488,15 @@ function renderRepoFaceRepoActivitySurface(
}
}
function formatConversationMessages(messages: SourceMessage[], limit: number): string[] {
function formatConversationMessages(messages: SourceMessage[], limit: number, channelId?: string): string[] {
if (messages.length === 0) {
return ["- No recent messages."];
}
return messages.slice(-limit).map((message) => {
const speaker = message.isBot ? `${message.authorName} (agent/bot)` : message.authorName;
const content = collapseWhitespace(message.content, 900) || "[no text]";
return `- ${speaker} (message ${message.id}): ${content}${renderMessageAttachmentSuffix(message)}`;
const channelPrefix = channelId ? `channel ${channelId}, ` : "";
return `- ${speaker} (${channelPrefix}message ${message.id}): ${content}${renderMessageAttachmentSuffix(message)}`;
});
}

View file

@ -362,3 +362,4 @@
{"ts":"2026-06-14T11:53:52Z","type":"implementation","status":"ok","note":"Reoriented repo Face turns from private-by-default rumination toward public-social Persona turns. Banter is now explicit social graph maintenance, generic silence is no longer rewarded, stale swarm peer bonds/status reads surface as touch-base pressure, and relationship staleness contributes to speaking pressure while public freshness prompts are scoped to registered swarm peers."}
{"ts":"2026-06-14T12:06:49Z","type":"implementation","status":"ok","note":"Added outgoing curiosity openings for repo Face heartbeats: when a jurisdiction dive is due and room texture is not heavy/agent-filled, the turn is classified as autonomous Eyes/Imagination presence, requires source/history/Odin exploration before checked/found claims, and expects one compact unprompted SAY when socially legible. Interpreter now retries generic private restraint on those turns instead of laundering them into state-only rumination."}
{"ts":"2026-06-14T12:26:21Z","type":"implementation","status":"ok","note":"Made repo Face self-maintenance grievances public-first: prompt projection now surfaces Persona/system substrate, tools, voice/avatar/access, state-projection, semantic-memory, and agency-path pressure under a Self-maintenance public advocacy section; Face and Interpreter prompts now require a compact public-safe SAY for body/mind/substrate asks instead of burying them as private state. Detector was narrowed after prompt verification so sensitive human body/home trauma does not get auto-promoted by this machinery."}
{"ts":"2026-06-14T12:43:35Z","type":"implementation","status":"ok","note":"Fixed repo Face cross-channel reply routing: prompt transcripts now include source channel ids for current, nearby, and chronology messages; Face prompts explicitly forbid answering nearby-room posts in the current room; worker post routing now derives the destination channel from reply_to message ids and also infers a non-current room when a bare Face output names that room label (e.g. general thread). Verified against Libby prompt showing Metacrat general messages followed by the bad Aquarium post."}