Skip to content

Commit 53eb0ed

Browse files
author
Peter Steinberger
committed
refactor(imessage): tighten reflection guard coverage
1 parent 6bad92b commit 53eb0ed

2 files changed

Lines changed: 7 additions & 13 deletions

File tree

extensions/imessage/src/monitor/reflection-guard.test.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,11 @@ describe("detectReflectedContent", () => {
3737
expect(result.matchedLabels).toContain("thinking-tag");
3838
});
3939

40-
it("detects Anthropic namespaced <think> tags", () => {
41-
const result = detectReflectedContent("<antml:think>secret</antml:think>visible");
42-
expect(result.isReflection).toBe(true);
43-
expect(result.matchedLabels).toContain("thinking-tag");
44-
});
45-
46-
it("detects MiniMax namespaced <mm:think> tags", () => {
47-
const result = detectReflectedContent("<mm:think>secret</mm:think>visible");
40+
it.each([
41+
{ provider: "Anthropic", tag: "antml:think" },
42+
{ provider: "MiniMax", tag: "mm:think" },
43+
])("detects $provider namespaced reasoning tags", ({ tag }) => {
44+
const result = detectReflectedContent(`<${tag}>secret</${tag}>visible`);
4845
expect(result.isReflection).toBe(true);
4946
expect(result.matchedLabels).toContain("thinking-tag");
5047
});

extensions/imessage/src/monitor/reflection-guard.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,8 @@ import { findCodeRegions, isInsideCode } from "openclaw/plugin-sdk/text-chunking
44
const INTERNAL_SEPARATOR_RE = /(?:#\+){2,}#?/;
55
const ASSISTANT_ROLE_MARKER_RE = /\bassistant\s+to\s*=\s*\w+/i;
66
// Require closing `>` to avoid false-positives on phrases like "<thought experiment>".
7-
// Reasoning tags may carry a model-specific namespace prefix (e.g. Anthropic's
8-
// `antml:`, MiniMax's `mm:`). Accept the known prefixes so namespaced variants
9-
// like `<mm:think>` are still detected as reflected assistant content instead of
10-
// being treated as normal inbound text (matches the shared reasoning-tag contract
11-
// in src/shared/text/reasoning-tags.ts).
7+
// Keep known provider namespaces aligned with the public reasoning-tag contract
8+
// so reflected hidden reasoning cannot re-enter the agent loop.
129
const THINKING_TAG_RE =
1310
/<\s*\/?\s*(?:(?:antml:|mm:)?(?:think(?:ing)?|thought)|antthinking)\b[^<>]*>/i;
1411
const RELEVANT_MEMORIES_TAG_RE = /<\s*\/?\s*relevant[-_]memories\b[^<>]*>/i;

0 commit comments

Comments
 (0)