From 269e6a92f723ae209bb30883c6f9d8c50d81ab0e Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Mon, 1 Jun 2026 14:14:00 +0100 Subject: [PATCH] Infer reply anchors for Face answers --- apps/worker/src/index.ts | 41 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/apps/worker/src/index.ts b/apps/worker/src/index.ts index 2bb5fb9..ea0f5dc 100644 --- a/apps/worker/src/index.ts +++ b/apps/worker/src/index.ts @@ -1411,10 +1411,49 @@ async function resolveRepoIdentityPostIntent( identity, channelId, content: intent.content.trim(), - replyToMessageId: intent.replyToMessageId, + replyToMessageId: intent.replyToMessageId ?? + inferQuestionReplyAnchor(job, identity, intent.content), }; } +function inferQuestionReplyAnchor( + job: JobRecord, + identity: NonNullable>, + content: string, +): string | undefined { + const normalizedContent = content.trim(); + if (!normalizedContent || normalizedContent.includes("\n")) { + return undefined; + } + + const contentLooksLikeAnswer = + /^(my|i|for me|honestly|yeah|yes|no|still)\b/i.test(normalizedContent) || + /\b(answer|for me|my cheap little answer|i think|i love|i hate|i want)\b/i.test(normalizedContent); + if (!contentLooksLikeAnswer) { + return undefined; + } + + const recentQuestions = job.contextBundle.recentMessages + .filter((message) => + message.id && + message.content.includes("?") && + message.authorName.trim().toLowerCase() !== identity.displayName.trim().toLowerCase() && + message.timestamp && + Number.isFinite(Date.parse(message.timestamp)), + ) + .sort((left, right) => Date.parse(right.timestamp) - Date.parse(left.timestamp)); + const latestQuestion = recentQuestions[0]; + + if (!latestQuestion) { + return undefined; + } + + console.warn( + `Inferred reply_to ${latestQuestion.id} for repo identity ${identity.id} SAY from job ${job.id} because the public line appears to answer a recent question.`, + ); + return latestQuestion.id; +} + async function resolveRepoIdentityMemeIntent( job: JobRecord, intent: RepoIdentityMemeIntent,