fix: allow directive-only toggles inside group batches

main
Peter Steinberger 2025-12-03 14:32:58 +00:00
parent 89d49cd925
commit 088bdb3313
1 changed files with 16 additions and 3 deletions

View File

@ -117,6 +117,20 @@ function isAbortTrigger(text?: string): boolean {
return ABORT_TRIGGERS.has(normalized); return ABORT_TRIGGERS.has(normalized);
} }
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)
: text;
return afterMarker
.replace(/\[[^\]]+\]\s*/g, "")
.replace(/^[ \t]*[A-Za-z0-9+()\-_. ]+:\s*/gm, "")
.replace(/\s+/g, " ")
.trim();
}
export async function getReplyFromConfig( export async function getReplyFromConfig(
ctx: MsgContext, ctx: MsgContext,
opts?: GetReplyOptions, opts?: GetReplyOptions,
@ -279,8 +293,7 @@ export async function getReplyFromConfig(
const directiveOnly = (() => { const directiveOnly = (() => {
if (!hasThinkDirective) return false; if (!hasThinkDirective) return false;
if (!thinkCleaned) return true; if (!thinkCleaned) return true;
// Ignore bracketed prefixes (timestamps, same-phone markers, etc.) const stripped = stripStructuralPrefixes(thinkCleaned);
const stripped = thinkCleaned.replace(/\[[^\]]+\]\s*/g, "").trim();
return stripped.length === 0; return stripped.length === 0;
})(); })();
@ -313,7 +326,7 @@ export async function getReplyFromConfig(
const verboseDirectiveOnly = (() => { const verboseDirectiveOnly = (() => {
if (!hasVerboseDirective) return false; if (!hasVerboseDirective) return false;
if (!verboseCleaned) return true; if (!verboseCleaned) return true;
const stripped = verboseCleaned.replace(/\[[^\]]+\]\s*/g, "").trim(); const stripped = stripStructuralPrefixes(verboseCleaned);
return stripped.length === 0; return stripped.length === 0;
})(); })();