mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 12:47:39 +00:00
refactor(infra): reuse shared home prefix expansion
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import crypto from "node:crypto";
|
||||
import fs from "node:fs";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { DEFAULT_AGENT_ID } from "../routing/session-key.js";
|
||||
import { expandHomePrefix } from "./home-dir.js";
|
||||
import { requestJsonlSocket } from "./jsonl-socket.js";
|
||||
export * from "./exec-approvals-analysis.js";
|
||||
export * from "./exec-approvals-allowlist.js";
|
||||
@@ -98,25 +98,12 @@ function hashExecApprovalsRaw(raw: string | null): string {
|
||||
.digest("hex");
|
||||
}
|
||||
|
||||
function expandHome(value: string): string {
|
||||
if (!value) {
|
||||
return value;
|
||||
}
|
||||
if (value === "~") {
|
||||
return os.homedir();
|
||||
}
|
||||
if (value.startsWith("~/")) {
|
||||
return path.join(os.homedir(), value.slice(2));
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
export function resolveExecApprovalsPath(): string {
|
||||
return expandHome(DEFAULT_FILE);
|
||||
return expandHomePrefix(DEFAULT_FILE);
|
||||
}
|
||||
|
||||
export function resolveExecApprovalsSocketPath(): string {
|
||||
return expandHome(DEFAULT_SOCKET);
|
||||
return expandHomePrefix(DEFAULT_SOCKET);
|
||||
}
|
||||
|
||||
function normalizeAllowlistPattern(value: string | undefined): string | null {
|
||||
@@ -370,7 +357,7 @@ export function resolveExecApprovals(
|
||||
agentId,
|
||||
overrides,
|
||||
path: resolveExecApprovalsPath(),
|
||||
socketPath: expandHome(file.socket?.path ?? resolveExecApprovalsSocketPath()),
|
||||
socketPath: expandHomePrefix(file.socket?.path ?? resolveExecApprovalsSocketPath()),
|
||||
token: file.socket?.token ?? "",
|
||||
});
|
||||
}
|
||||
@@ -421,7 +408,7 @@ export function resolveExecApprovalsFromFile(params: {
|
||||
];
|
||||
return {
|
||||
path: params.path ?? resolveExecApprovalsPath(),
|
||||
socketPath: expandHome(
|
||||
socketPath: expandHomePrefix(
|
||||
params.socketPath ?? file.socket?.path ?? resolveExecApprovalsSocketPath(),
|
||||
),
|
||||
token: params.token ?? file.socket?.token ?? "",
|
||||
|
||||
Reference in New Issue
Block a user