fix(auto-reply): RawBody commands + locked session updates (#643)

This commit is contained in:
Peter Steinberger
2026-01-10 17:32:19 +01:00
parent e2ea02160d
commit e3cd431551
17 changed files with 566 additions and 89 deletions

View File

@@ -23,6 +23,8 @@ function deriveMentionPatterns(identity?: { name?: string; emoji?: string }) {
const BACKSPACE_CHAR = "\u0008";
export const CURRENT_MESSAGE_MARKER = "[Current message - respond to this]";
function normalizeMentionPattern(pattern: string): string {
if (!pattern.includes(BACKSPACE_CHAR)) return pattern;
return pattern.split(BACKSPACE_CHAR).join("\\b");
@@ -87,13 +89,18 @@ export function matchesMentionPatterns(
export function stripStructuralPrefixes(text: string): string {
// Ignore wrapper labels, timestamps, and sender prefixes so directive-only
// detection still works in group batches that include history/context.
const marker = "[Current message - respond to this]";
const afterMarker = text.includes(marker)
? text.slice(text.indexOf(marker) + marker.length)
const afterMarker = text.includes(CURRENT_MESSAGE_MARKER)
? text
.slice(
text.indexOf(CURRENT_MESSAGE_MARKER) + CURRENT_MESSAGE_MARKER.length,
)
.trimStart()
: text;
return afterMarker
.replace(/\[[^\]]+\]\s*/g, "")
.replace(/^[ \t]*[A-Za-z0-9+()\-_. ]+:\s*/gm, "")
.replace(/\\n/g, " ")
.replace(/\s+/g, " ")
.trim();
}
@@ -105,9 +112,9 @@ export function stripMentions(
agentId?: string,
): string {
let result = text;
const patterns = normalizeMentionPatterns(
resolveMentionPatterns(cfg, agentId),
);
const rawPatterns = resolveMentionPatterns(cfg, agentId);
const patterns = normalizeMentionPatterns(rawPatterns);
for (const p of patterns) {
try {
const re = new RegExp(p, "gi");