refactor(approvals): unify structured path display

This commit is contained in:
Peter Steinberger
2026-04-25 02:39:46 +01:00
parent 52ea8eadcb
commit 32dd1ffc5a
13 changed files with 97 additions and 19 deletions

View File

@@ -1,5 +1,6 @@
import {
type AgentApprovalEventData,
formatApprovalDisplayPath,
type EmbeddedRunAttemptParams,
} from "openclaw/plugin-sdk/agent-harness-runtime";
import {
@@ -431,15 +432,10 @@ function sanitizePermissionHostValue(value: string): string {
}
function sanitizePermissionPathValue(value: string): string {
const normalized = sanitizePermissionScalar(value);
const homeCompacted = normalized
.replace(/^\/home\/(?!\.{1,2}(?=\/|$))[^/]+(?=\/|$)/, "~")
.replace(/^\/Users\/(?!\.{1,2}(?=\/|$))[^/]+(?=\/|$)/, "~")
.replace(/^[A-Za-z]:[\\/]Users[\\/](?!\.{1,2}(?=[\\/]|$))[^\\/]+(?=[\\/]|$)/i, "~");
const displayPath = homeCompacted.startsWith("~")
? homeCompacted.replace(/\\/g, "/")
: homeCompacted;
return truncate(displayPath, PERMISSION_VALUE_MAX_LENGTH);
return truncate(
formatApprovalDisplayPath(sanitizePermissionScalar(value)),
PERMISSION_VALUE_MAX_LENGTH,
);
}
function sanitizePermissionScalar(value: string): string {