Merge a06741397d15f5226a9f77b22305e1b74a4b825f into 5e417b44e1540f528d2ae63e3e20229a902d1db2

This commit is contained in:
puppylpg 2026-03-20 19:55:09 -07:00 committed by GitHub
commit b538f6da80
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 36 additions and 3 deletions

View File

@ -307,7 +307,9 @@ export async function runPreparedReply(
);
const baseBodyForPrompt = isBareSessionReset
? baseBodyFinal
: [inboundUserContext, baseBodyFinal].filter(Boolean).join("\n\n");
: inboundUserContext
? `${inboundUserContext}\n\n---\n**User Message:**\n${baseBodyFinal}`
: baseBodyFinal;
const baseBodyTrimmed = baseBodyForPrompt.trim();
const hasMediaAttachment = Boolean(
sessionCtx.MediaPath || (sessionCtx.MediaPaths && sessionCtx.MediaPaths.length > 0),

View File

@ -146,6 +146,28 @@ Hello`;
});
});
describe("user-message separator stripping", () => {
it("strips separator after metadata removal", () => {
const input = `${CONV_BLOCK}\n\n---\n**User Message:**\nHello world`;
expect(stripInboundMetadata(input)).toBe("Hello world");
});
it("strips separator with multiple metadata blocks", () => {
const input = `${CONV_BLOCK}\n\n${SENDER_BLOCK}\n\n---\n**User Message:**\nHello world`;
expect(stripInboundMetadata(input)).toBe("Hello world");
});
it("preserves separator when no metadata blocks are present", () => {
const input = `---\n**User Message:**\nHello world`;
expect(stripInboundMetadata(input)).toBe(input);
});
it("preserves user content starting with --- when it is not the separator", () => {
const input = `${CONV_BLOCK}\n\n---\nSome regular content`;
expect(stripInboundMetadata(input)).toBe("---\nSome regular content");
});
});
describe("extractInboundSenderLabel", () => {
it("returns the sender label block when present", () => {
const input = `${CONV_BLOCK}\n\n${SENDER_BLOCK}\n\nHello from user`;

View File

@ -184,7 +184,16 @@ export function stripInboundMetadata(text: string): string {
result.push(line);
}
return result.join("\n").replace(/^\n+/, "").replace(/\n+$/, "");
return stripUserMessageSeparator(result.join("\n").replace(/^\n+/, "").replace(/\n+$/, ""));
}
/**
* Removes the `---\n**User Message:**` separator injected between metadata and
* user content. Called after metadata blocks have already been stripped so the
* separator (if any) is now a leading artefact in the remaining text.
*/
function stripUserMessageSeparator(text: string): string {
return text.replace(/^[\t ]*---[\t ]*\n[\t ]*\*\*User Message:\*\*[\t ]*\n?/, "");
}
export function stripLeadingInboundMetadata(text: string): string {
@ -232,7 +241,7 @@ export function stripLeadingInboundMetadata(text: string): string {
}
const strippedRemainder = stripTrailingUntrustedContextSuffix(lines.slice(index));
return strippedRemainder.join("\n");
return stripUserMessageSeparator(strippedRemainder.join("\n"));
}
export function extractInboundSenderLabel(text: string): string | null {