mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-21 10:16:44 +00:00
fix(matrix): sanitize internal tool-trace lines from outbound text (#97372)
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).
This commit is contained in:
@@ -32,7 +32,10 @@ import {
|
||||
normalizeLowercaseStringOrEmpty,
|
||||
normalizeOptionalString,
|
||||
} from "openclaw/plugin-sdk/string-coerce-runtime";
|
||||
import { chunkTextForOutbound } from "openclaw/plugin-sdk/text-chunking";
|
||||
import {
|
||||
chunkTextForOutbound,
|
||||
sanitizeAssistantVisibleText,
|
||||
} from "openclaw/plugin-sdk/text-chunking";
|
||||
import { matrixMessageActions } from "./actions.js";
|
||||
import { matrixApprovalCapability } from "./approval-native.js";
|
||||
import { createMatrixPairingText, createMatrixProbeAccount } from "./channel-account-paths.js";
|
||||
@@ -336,6 +339,7 @@ const matrixChannelOutbound: ChannelOutboundAdapter = {
|
||||
chunker: chunkTextForOutbound,
|
||||
chunkerMode: "markdown",
|
||||
textChunkLimit: 4000,
|
||||
sanitizeText: ({ text }) => sanitizeAssistantVisibleText(text),
|
||||
deliveryCapabilities: {
|
||||
durableFinal: {
|
||||
text: true,
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
// Matrix outbound must strip assistant internal tool-trace scaffolding, matching
|
||||
// the sibling channel fixes tracked under #90684 (Telegram #95774 / Google Chat
|
||||
// #95084 / IRC #97214). The hook runs before the markdown->HTML render, so a
|
||||
// single sanitize cleans both the plain body and the formatted_body.
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { matrixPlugin } from "./channel.js";
|
||||
|
||||
describe("matrix outbound sanitizeText", () => {
|
||||
it("strips internal tool-trace banners before outbound delivery", () => {
|
||||
const text = "Done.\n⚠️ 🛠️ `search repos (agent)` failed";
|
||||
|
||||
expect(matrixPlugin.outbound?.sanitizeText?.({ text, payload: { text } })).toBe("Done.");
|
||||
});
|
||||
|
||||
it("preserves ordinary assistant prose while sanitizing", () => {
|
||||
const text = "The pipeline has 3 open deals.";
|
||||
|
||||
expect(matrixPlugin.outbound?.sanitizeText?.({ text, payload: { text } })).toBe(text);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user