


























@@ -110,6 +110,7 @@ export const DEFAULT_PROGRESS_DRAFT_LABELS = [
110110] as const;
111111112112export const DEFAULT_PROGRESS_DRAFT_INITIAL_DELAY_MS = 5_000;
113+const DEFAULT_PROGRESS_DRAFT_MAX_LINE_CHARS = 72;
113114114115const NON_WORK_PROGRESS_TOOL_NAMES = new Set([
115116"message",
@@ -537,6 +538,52 @@ export function resolveChannelProgressDraftMaxLines(
537538return configured && configured > 0 ? configured : defaultValue;
538539}
539540541+function sliceCodePoints(value: string, start: number, end?: number): string {
542+return Array.from(value).slice(start, end).join("");
543+}
544+545+function compactProgressLineDetail(detail: string, maxChars: number): string {
546+const chars = Array.from(detail);
547+if (chars.length <= maxChars) {
548+return detail;
549+}
550+if (maxChars <= 1) {
551+return "…";
552+}
553+const keepStart = Math.max(1, Math.ceil((maxChars - 1) * 0.45));
554+const keepEnd = Math.max(1, maxChars - keepStart - 1);
555+const rawStart = chars.slice(0, keepStart).join("").trimEnd();
556+const start =
557+rawStart.length > 8 && /\s+\S+$/.test(rawStart) ? rawStart.replace(/\s+\S+$/, "") : rawStart;
558+return `${start}…${chars.slice(-keepEnd).join("").trimStart()}`;
559+}
560+561+function compactChannelProgressDraftLine(line: string, maxChars: number): string {
562+const normalized = line.replace(/\s+/g, " ").trim();
563+if (!normalized) {
564+return "";
565+}
566+const chars = Array.from(normalized);
567+if (chars.length <= maxChars) {
568+return normalized;
569+}
570+if (maxChars <= 1) {
571+return "…";
572+}
573+574+const splitIndex = normalized.indexOf(": ");
575+if (splitIndex > 0) {
576+const prefix = normalized.slice(0, splitIndex + 2);
577+const prefixChars = Array.from(prefix).length;
578+const detailLimit = maxChars - prefixChars;
579+if (detailLimit >= 8) {
580+return `${prefix}${compactProgressLineDetail(normalized.slice(splitIndex + 2), detailLimit)}`;
581+}
582+}
583+584+return `${sliceCodePoints(normalized, 0, maxChars - 1).trimEnd()}…`;
585+}
586+540587export function formatChannelProgressDraftText(params: {
541588entry?: StreamingCompatEntry | null;
542589lines: string[];
@@ -554,7 +601,7 @@ export function formatChannelProgressDraftText(params: {
554601const formatLine = params.formatLine ?? ((line: string) => line);
555602const bullet = params.bullet ?? "•";
556603const lines = params.lines
557-.map((line) => line.replace(/\s+/g, " ").trim())
604+.map((line) => compactChannelProgressDraftLine(line, DEFAULT_PROGRESS_DRAFT_MAX_LINE_CHARS))
558605.filter((line) => line.length > 0)
559606.slice(-maxLines)
560607.map((line) =>
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。