Skip to content

Commit 65e6d9c

Browse files
committed
fix(auto-reply): strip delivery hints from leading metadata
1 parent d498b1c commit 65e6d9c

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

src/auto-reply/reply/strip-inbound-meta.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,16 @@ What should I grab on the way?`;
140140
expect(stripLeadingInboundMetadata(input)).toBe("What should I grab on the way?");
141141
});
142142

143+
it("strips message-tool delivery hints before leading metadata blocks", () => {
144+
const input = `${MESSAGE_TOOL_ONLY_DELIVERY_HINT}\n\n${CONV_BLOCK}\n\nActual user message`;
145+
expect(stripLeadingInboundMetadata(input)).toBe("Actual user message");
146+
});
147+
148+
it("strips message-tool delivery hints before leading user text", () => {
149+
const input = `${MESSAGE_TOOL_ONLY_DELIVERY_HINT}\n\nActual user message`;
150+
expect(stripLeadingInboundMetadata(input)).toBe("Actual user message");
151+
});
152+
143153
it("strips an active-memory prompt prefix block from leading-only history views even when earlier text precedes it", () => {
144154
const input = `Queued earlier user turn\n\n${ACTIVE_MEMORY_PREFIX_BLOCK}\n\nWhat should I grab on the way?`;
145155
expect(stripLeadingInboundMetadata(input)).toBe(

src/auto-reply/reply/strip-inbound-meta.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,21 @@ export function stripLeadingInboundMetadata(text: string): string {
282282
return "";
283283
}
284284

285+
const strippedDeliveryHint = isMessageToolDeliveryHintLine(lines[index]);
286+
while (index < lines.length && isMessageToolDeliveryHintLine(lines[index])) {
287+
index++;
288+
while (index < lines.length && lines[index] === "") {
289+
index++;
290+
}
291+
}
292+
if (index >= lines.length) {
293+
return "";
294+
}
295+
285296
if (!isInboundMetaSentinelLine(lines[index])) {
286-
const strippedNoLeading = stripTrailingUntrustedContextSuffix(lines);
297+
const strippedNoLeading = stripTrailingUntrustedContextSuffix(
298+
strippedDeliveryHint ? lines.slice(index) : lines,
299+
);
287300
return strippedNoLeading.join("\n");
288301
}
289302

0 commit comments

Comments
 (0)