Skip to content

Commit 770b19f

Browse files
ly-wang19claude
andauthored
fix(imessage): only strip standalone role-turn markers, not prose ending in a role word (#96392)
ROLE_TURN_MARKER_RE anchored only the end of the line (\b...:\s*$), so any outbound line that merely ended with 'user:'/'system:'/'assistant:' was truncated — e.g. 'Please send this reply to the user:' lost its last word. Anchor the marker to the whole line so only a standalone leaked turn marker (its own line) is stripped; standalone-marker behavior is unchanged. Co-authored-by: ly-wang19 <[email protected]> Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
1 parent 793b604 commit 770b19f

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

extensions/imessage/src/monitor/sanitize-outbound.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,15 @@ describe("sanitizeOutboundText", () => {
4949
expect(result).not.toMatch(/^assistant:$/m);
5050
});
5151

52+
it("preserves prose lines that merely end with 'user:'/'system:'", () => {
53+
expect(sanitizeOutboundText("Please send this reply to the user:")).toBe(
54+
"Please send this reply to the user:",
55+
);
56+
expect(sanitizeOutboundText("Here is a note for the system:")).toBe(
57+
"Here is a note for the system:",
58+
);
59+
});
60+
5261
it("collapses excessive blank lines after stripping", () => {
5362
const text = "Hello\n\n\n\n\nWorld";
5463
expect(sanitizeOutboundText(text)).toBe("Hello\n\nWorld");

extensions/imessage/src/monitor/sanitize-outbound.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ import { stripAssistantInternalScaffolding } from "openclaw/plugin-sdk/text-chun
77
*/
88
const INTERNAL_SEPARATOR_RE = /(?:#\+){2,}#?/g;
99
const ASSISTANT_ROLE_MARKER_RE = /\bassistant\s+to\s*=\s*\w+/gi;
10-
const ROLE_TURN_MARKER_RE = /\b(?:user|system|assistant)\s*:\s*$/gm;
10+
// Only a standalone role marker on its own line (a leaked turn boundary) — not
11+
// any line that merely ends with the word "user/system/assistant:" in prose.
12+
const ROLE_TURN_MARKER_RE = /^[ \t]*(?:user|system|assistant)\s*:\s*$/gm;
1113

1214
/**
1315
* Strip all assistant-internal scaffolding from outbound text before delivery.

0 commit comments

Comments
 (0)