mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-08 11:02:26 +00:00
fix(channels): strip dangling progress italics
This commit is contained in:
@@ -901,6 +901,23 @@ function removeUnbalancedInlineBackticks(value: string): string {
|
||||
return value.trimStart().startsWith("`") ? value.replaceAll("`", "'") : value.replaceAll("`", "");
|
||||
}
|
||||
|
||||
function repairCompactedProgressMarkdown(value: string): string {
|
||||
const withoutDanglingBackticks = removeUnbalancedInlineBackticks(value);
|
||||
const trimmedStart = withoutDanglingBackticks.trimStart();
|
||||
if (!trimmedStart.startsWith("_") || trimmedStart.endsWith("_")) {
|
||||
return withoutDanglingBackticks;
|
||||
}
|
||||
const underscoreCount = Array.from(trimmedStart).filter((char) => char === "_").length;
|
||||
if (underscoreCount % 2 === 0) {
|
||||
return withoutDanglingBackticks;
|
||||
}
|
||||
const leadingWhitespace = withoutDanglingBackticks.slice(
|
||||
0,
|
||||
withoutDanglingBackticks.length - trimmedStart.length,
|
||||
);
|
||||
return `${leadingWhitespace}${trimmedStart.slice(1)}`;
|
||||
}
|
||||
|
||||
function compactPlainProgressLine(line: string, maxChars: number): string {
|
||||
const head = sliceCodePoints(line, 0, maxChars - 1).trimEnd();
|
||||
const boundary = head.search(/\s+\S*$/u);
|
||||
@@ -931,7 +948,7 @@ function compactChannelProgressDraftLine(line: string, maxChars: number): string
|
||||
}
|
||||
// Keep the stable tool label/icon visible while trimming volatile command
|
||||
// detail; this reduces progress draft edit churn in chat UIs.
|
||||
return removeUnbalancedInlineBackticks(
|
||||
return repairCompactedProgressMarkdown(
|
||||
`${prefix}${compactProgressLineDetail(detail, detailLimit)}`,
|
||||
);
|
||||
};
|
||||
@@ -954,7 +971,7 @@ function compactChannelProgressDraftLine(line: string, maxChars: number): string
|
||||
}
|
||||
}
|
||||
|
||||
return removeUnbalancedInlineBackticks(compactPlainProgressLine(normalized, maxChars));
|
||||
return repairCompactedProgressMarkdown(compactPlainProgressLine(normalized, maxChars));
|
||||
}
|
||||
|
||||
function getProgressDraftLineText(line: string | ChannelProgressDraftLine): string {
|
||||
|
||||
@@ -361,6 +361,22 @@ describe("channel-streaming", () => {
|
||||
).toBe("Shelling\n\n• I'm checking whether the generated video exists or if the…");
|
||||
});
|
||||
|
||||
it("falls back to plain commentary when compaction drops the closing italic marker", () => {
|
||||
expect(
|
||||
formatChannelProgressDraftText({
|
||||
entry: { streaming: { progress: { label: false, maxLineChars: 32 } } },
|
||||
lines: [
|
||||
{
|
||||
kind: "item",
|
||||
text: `_${"x".repeat(80)}_`,
|
||||
label: "Commentary",
|
||||
prefix: false,
|
||||
},
|
||||
],
|
||||
}),
|
||||
).toBe(`${"x".repeat(30)}…`);
|
||||
});
|
||||
|
||||
it("keeps compacted raw progress lines from leaking unmatched markdown backticks", () => {
|
||||
const line = buildChannelProgressDraftLine(
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user