Skip to content

Commit 1616054

Browse files
committed
refactor(subagents): reuse canonical status label truncation
1 parent 79a978a commit 1616054

1 file changed

Lines changed: 7 additions & 13 deletions

File tree

‎src/agents/internal-events.ts‎

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* blocks or plain prompt text.
55
*/
66
import { normalizeOptionalString } from "@openclaw/normalization-core/string-coerce";
7-
import { truncateUtf16Safe } from "@openclaw/normalization-core/utf16-slice";
7+
import { truncateWithMarker } from "@openclaw/normalization-core/utf16-slice";
88
import {
99
formatGeneratedAttachmentLines,
1010
mediaUrlsFromGeneratedAttachments,
@@ -109,16 +109,6 @@ function sanitizeSingleLineField(value: string, fallback: string): string {
109109
return sanitized || fallback;
110110
}
111111

112-
function truncateSingleLineField(value: string, maxChars: number, marker: string): string {
113-
if (value.length <= maxChars) {
114-
return value;
115-
}
116-
const keep = Math.max(0, maxChars - marker.length);
117-
// truncateUtf16Safe never splits a surrogate pair, so astral characters in
118-
// provider/lifecycle error text cannot leave a dangling half in the prompt.
119-
return `${truncateUtf16Safe(value, keep).trimEnd()}${marker}`;
120-
}
121-
122112
function sanitizeMultilineField(value: string, fallback: string): string {
123113
const sanitized = escapeInternalRuntimeContextDelimiters(value).replace(/\r\n/g, "\n").trim();
124114
return sanitized || fallback;
@@ -169,10 +159,14 @@ function formatTaskCompletionEvent(
169159
const sessionId = sanitizeSingleLineField(event.childSessionId ?? "unknown", "unknown");
170160
const announceType = sanitizeSingleLineField(event.announceType, "unknown");
171161
const taskLabel = sanitizeSingleLineField(event.taskLabel, "unnamed task");
172-
const statusLabel = truncateSingleLineField(
162+
const statusLabel = truncateWithMarker(
173163
sanitizeSingleLineField(event.statusLabel, event.status),
174164
MAX_TASK_COMPLETION_STATUS_LABEL_CHARS,
175-
TASK_COMPLETION_STATUS_LABEL_TRUNCATION_MARKER,
165+
{
166+
marker: TASK_COMPLETION_STATUS_LABEL_TRUNCATION_MARKER,
167+
reserve: TASK_COMPLETION_STATUS_LABEL_TRUNCATION_MARKER.length,
168+
trimEnd: true,
169+
},
176170
);
177171
const result = formatChildResultDataBlock(event.result);
178172
const attachmentLines = formatGeneratedAttachmentLines(event.attachments);

0 commit comments

Comments
 (0)