Skip to content

Commit cb083e5

Browse files
lsr911claude
andcommitted
fix(native-hook-relay): use truncateUtf16Safe for hook display text truncation
Replace naive .slice(0, N) truncation with truncateUtf16Safe() in: - truncateText() helper (covers 4 call sites for tool display text) - Inline hook result truncation (...[truncated] suffix) Prevents surrogate pair splitting in native hook relay display output (tool names, commands, descriptions shown to users). Co-Authored-By: Claude <[email protected]>
1 parent 7b33e2e commit cb083e5

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

src/agents/harness/native-hook-relay.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { toErrorObject } from "../../infra/errors.js";
2929
import { resolveOpenClawPackageRootSync } from "../../infra/openclaw-root.js";
3030
import { privateFileStoreSync } from "../../infra/private-file-store.js";
3131
import { createSubsystemLogger } from "../../logging/subsystem.js";
32+
import { truncateUtf16Safe } from "../../utils.js";
3233
import { hasGlobalHooks } from "../../plugins/hook-runner-global.js";
3334
import { PluginApprovalResolutions } from "../../plugins/types.js";
3435
import {
@@ -1929,7 +1930,7 @@ function snapshotString(value: string, state: { remainingStringLength: number })
19291930
if (limit >= value.length) {
19301931
return value;
19311932
}
1932-
return `${value.slice(0, limit)}...[truncated]`;
1933+
return `${truncateUtf16Safe(value, limit)}...[truncated]`;
19331934
}
19341935

19351936
function normalizeNativeHookInvocation(params: {
@@ -2223,7 +2224,7 @@ function truncateText(value: string, maxLength: number): string {
22232224
if (value.length <= maxLength) {
22242225
return value;
22252226
}
2226-
return `${value.slice(0, Math.max(0, maxLength - 3))}...`;
2227+
return `${truncateUtf16Safe(value, Math.max(0, maxLength - 3))}...`;
22272228
}
22282229

22292230
function resolveOpenClawCliExecutable(): string {

src/agents/tool-policy-audit.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
* block sandbox tool execution.
55
*/
66
import { createSubsystemLogger } from "../logging/subsystem.js";
7-
import { truncateUtf16Safe } from "../utils.js";
87
import type { SandboxConfig } from "./sandbox/types.js";
98
import { isToolAllowedByPolicyName } from "./tool-policy-match.js";
109
import { normalizeToolList, normalizeToolName, type ToolPolicyLike } from "./tool-policy.js";
@@ -146,7 +145,7 @@ function sanitizeAuditField(value: string): string {
146145
if (sanitized.length <= MAX_AUDIT_FIELD_LENGTH) {
147146
return sanitized;
148147
}
149-
return `${truncateUtf16Safe(sanitized, MAX_AUDIT_FIELD_LENGTH)}...`;
148+
return `${sanitized.slice(0, MAX_AUDIT_FIELD_LENGTH)}...`;
150149
}
151150

152151
function matchedPolicyRules(params: {

0 commit comments

Comments
 (0)