refactor(infra): reuse shared home prefix expansion

This commit is contained in:
Peter Steinberger
2026-02-18 17:38:11 +00:00
parent b51166e879
commit b73a2de9f6
3 changed files with 41 additions and 38 deletions

View File

@@ -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 ?? "",