mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-12 21:53:00 -06:00
refactor(agents): reuse markdown code span formatter (#113525)
This commit is contained in:
@@ -923,6 +923,23 @@ describe("buildEmbeddedRunPayloads", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("leaves exec metadata unwrapped for plain tool results", () => {
|
||||
const payloads = buildPayloads({
|
||||
lastToolError: {
|
||||
toolName: "exec",
|
||||
meta: "run node inline script, `node -e 'console.log(1, `x`)'`",
|
||||
error: "Command exited with code 1",
|
||||
mutatingAction: true,
|
||||
},
|
||||
toolResultFormat: "plain",
|
||||
});
|
||||
|
||||
expectSinglePayloadSummary(payloads, {
|
||||
text: "⚠️ 🛠️ Exec failed: node -e 'console.log(1, `x`)' (exit 1)",
|
||||
isError: true,
|
||||
});
|
||||
});
|
||||
|
||||
it("preserves raw exec context before trailing raw command metadata", () => {
|
||||
const payloads = buildPayloads({
|
||||
lastToolError: {
|
||||
|
||||
@@ -33,6 +33,7 @@ import {
|
||||
extractAssistantTextForPhase,
|
||||
parseAssistantTextSignature,
|
||||
} from "../../../shared/chat-message-content.js";
|
||||
import { formatInlineCodeSpan } from "../../../shared/markdown-code.js";
|
||||
import {
|
||||
sanitizeAssistantFinalAnswerText,
|
||||
sanitizeAssistantVisibleText,
|
||||
@@ -421,25 +422,7 @@ function formatConciseExecExitSuffix(error: string | undefined): string {
|
||||
return code ? ` (exit ${code})` : "";
|
||||
}
|
||||
function maybeWrapInlineCode(value: string, markdown: boolean): string {
|
||||
if (!markdown) {
|
||||
return value;
|
||||
}
|
||||
const delimiter = "`".repeat(longestBacktickRun(value) + 1);
|
||||
const padding = value.startsWith("`") || value.endsWith("`") || value.includes("\n") ? " " : "";
|
||||
return `${delimiter}${padding}${value}${padding}${delimiter}`;
|
||||
}
|
||||
function longestBacktickRun(value: string): number {
|
||||
let longest = 0;
|
||||
let current = 0;
|
||||
for (const char of value) {
|
||||
if (char === "`") {
|
||||
current += 1;
|
||||
longest = Math.max(longest, current);
|
||||
continue;
|
||||
}
|
||||
current = 0;
|
||||
}
|
||||
return longest;
|
||||
return markdown ? formatInlineCodeSpan(value) : value;
|
||||
}
|
||||
/**
|
||||
* Chooses whether a tool failure needs a separate user-visible warning and
|
||||
|
||||
Reference in New Issue
Block a user