Skip to content

Commit cbb8ca5

Browse files
committed
fix(matrix): sanitize internal tool-trace lines from outbound text
Wrap the matrix outbound sanitizeText hook with sanitizeAssistantVisibleText so assistant internal tool-trace scaffolding is stripped before delivery, matching the sibling channel fixes under #90684 (Telegram #95774, Google Chat #95084, IRC #97214).
1 parent 69af58b commit cbb8ca5

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

extensions/matrix/src/channel.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ import {
3232
normalizeLowercaseStringOrEmpty,
3333
normalizeOptionalString,
3434
} from "openclaw/plugin-sdk/string-coerce-runtime";
35-
import { chunkTextForOutbound } from "openclaw/plugin-sdk/text-chunking";
35+
import {
36+
chunkTextForOutbound,
37+
sanitizeAssistantVisibleText,
38+
} from "openclaw/plugin-sdk/text-chunking";
3639
import { matrixMessageActions } from "./actions.js";
3740
import { matrixApprovalCapability } from "./approval-native.js";
3841
import { createMatrixPairingText, createMatrixProbeAccount } from "./channel-account-paths.js";
@@ -336,6 +339,7 @@ const matrixChannelOutbound: ChannelOutboundAdapter = {
336339
chunker: chunkTextForOutbound,
337340
chunkerMode: "markdown",
338341
textChunkLimit: 4000,
342+
sanitizeText: ({ text }) => sanitizeAssistantVisibleText(text),
339343
deliveryCapabilities: {
340344
durableFinal: {
341345
text: true,
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Matrix outbound must strip assistant internal tool-trace scaffolding, matching
2+
// the sibling channel fixes tracked under #90684 (Telegram #95774 / Google Chat
3+
// #95084 / IRC #97214). The hook runs before the markdown->HTML render, so a
4+
// single sanitize cleans both the plain body and the formatted_body.
5+
import { describe, expect, it } from "vitest";
6+
import { matrixPlugin } from "./channel.js";
7+
8+
describe("matrix outbound sanitizeText", () => {
9+
it("strips internal tool-trace banners before outbound delivery", () => {
10+
const text = "Done.\n⚠️ 🛠️ `search repos (agent)` failed";
11+
12+
expect(matrixPlugin.outbound?.sanitizeText?.({ text, payload: { text } })).toBe("Done.");
13+
});
14+
15+
it("preserves ordinary assistant prose while sanitizing", () => {
16+
const text = "The pipeline has 3 open deals.";
17+
18+
expect(matrixPlugin.outbound?.sanitizeText?.({ text, payload: { text } })).toBe(text);
19+
});
20+
});

0 commit comments

Comments
 (0)