From bde246e7aff8b22d7bd4afb3e425023af2c0666a Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Mon, 13 Apr 2026 17:23:59 +0100 Subject: [PATCH] perf(auth-profiles): narrow source check path imports --- src/agents/auth-profiles/constants.ts | 8 ++-- src/agents/auth-profiles/path-constants.ts | 3 ++ src/agents/auth-profiles/path-resolve.ts | 33 ++++++++++++++ src/agents/auth-profiles/paths.ts | 43 ++++--------------- src/agents/auth-profiles/runtime-snapshots.ts | 2 +- src/agents/auth-profiles/source-check.ts | 6 ++- 6 files changed, 56 insertions(+), 39 deletions(-) create mode 100644 src/agents/auth-profiles/path-constants.ts create mode 100644 src/agents/auth-profiles/path-resolve.ts diff --git a/src/agents/auth-profiles/constants.ts b/src/agents/auth-profiles/constants.ts index 83f1e4ba584..f752377fb4f 100644 --- a/src/agents/auth-profiles/constants.ts +++ b/src/agents/auth-profiles/constants.ts @@ -1,9 +1,11 @@ import { createSubsystemLogger } from "../../logging/subsystem.js"; +export { + AUTH_PROFILE_FILENAME, + AUTH_STATE_FILENAME, + LEGACY_AUTH_FILENAME, +} from "./path-constants.js"; export const AUTH_STORE_VERSION = 1; -export const AUTH_PROFILE_FILENAME = "auth-profiles.json"; -export const AUTH_STATE_FILENAME = "auth-state.json"; -export const LEGACY_AUTH_FILENAME = "auth.json"; export const CLAUDE_CLI_PROFILE_ID = "anthropic:claude-cli"; export const CODEX_CLI_PROFILE_ID = "openai-codex:codex-cli"; diff --git a/src/agents/auth-profiles/path-constants.ts b/src/agents/auth-profiles/path-constants.ts new file mode 100644 index 00000000000..d723f34cd0c --- /dev/null +++ b/src/agents/auth-profiles/path-constants.ts @@ -0,0 +1,3 @@ +export const AUTH_PROFILE_FILENAME = "auth-profiles.json"; +export const AUTH_STATE_FILENAME = "auth-state.json"; +export const LEGACY_AUTH_FILENAME = "auth.json"; diff --git a/src/agents/auth-profiles/path-resolve.ts b/src/agents/auth-profiles/path-resolve.ts new file mode 100644 index 00000000000..057ecc6a834 --- /dev/null +++ b/src/agents/auth-profiles/path-resolve.ts @@ -0,0 +1,33 @@ +import path from "node:path"; +import { resolveUserPath } from "../../utils.js"; +import { resolveOpenClawAgentDir } from "../agent-paths.js"; +import { + AUTH_PROFILE_FILENAME, + AUTH_STATE_FILENAME, + LEGACY_AUTH_FILENAME, +} from "./path-constants.js"; + +export function resolveAuthStorePath(agentDir?: string): string { + const resolved = resolveUserPath(agentDir ?? resolveOpenClawAgentDir()); + return path.join(resolved, AUTH_PROFILE_FILENAME); +} + +export function resolveLegacyAuthStorePath(agentDir?: string): string { + const resolved = resolveUserPath(agentDir ?? resolveOpenClawAgentDir()); + return path.join(resolved, LEGACY_AUTH_FILENAME); +} + +export function resolveAuthStatePath(agentDir?: string): string { + const resolved = resolveUserPath(agentDir ?? resolveOpenClawAgentDir()); + return path.join(resolved, AUTH_STATE_FILENAME); +} + +export function resolveAuthStorePathForDisplay(agentDir?: string): string { + const pathname = resolveAuthStorePath(agentDir); + return pathname.startsWith("~") ? pathname : resolveUserPath(pathname); +} + +export function resolveAuthStatePathForDisplay(agentDir?: string): string { + const pathname = resolveAuthStatePath(agentDir); + return pathname.startsWith("~") ? pathname : resolveUserPath(pathname); +} diff --git a/src/agents/auth-profiles/paths.ts b/src/agents/auth-profiles/paths.ts index 5430fc631cf..58cad55dc53 100644 --- a/src/agents/auth-profiles/paths.ts +++ b/src/agents/auth-profiles/paths.ts @@ -1,40 +1,15 @@ import fs from "node:fs"; -import path from "node:path"; import { saveJsonFile } from "../../infra/json-file.js"; -import { resolveUserPath } from "../../utils.js"; -import { resolveOpenClawAgentDir } from "../agent-paths.js"; -import { - AUTH_PROFILE_FILENAME, - AUTH_STATE_FILENAME, - AUTH_STORE_VERSION, - LEGACY_AUTH_FILENAME, -} from "./constants.js"; +import { AUTH_STORE_VERSION } from "./constants.js"; +import { resolveAuthStatePath, resolveAuthStorePath } from "./path-resolve.js"; import type { AuthProfileSecretsStore } from "./types.js"; - -export function resolveAuthStorePath(agentDir?: string): string { - const resolved = resolveUserPath(agentDir ?? resolveOpenClawAgentDir()); - return path.join(resolved, AUTH_PROFILE_FILENAME); -} - -export function resolveLegacyAuthStorePath(agentDir?: string): string { - const resolved = resolveUserPath(agentDir ?? resolveOpenClawAgentDir()); - return path.join(resolved, LEGACY_AUTH_FILENAME); -} - -export function resolveAuthStatePath(agentDir?: string): string { - const resolved = resolveUserPath(agentDir ?? resolveOpenClawAgentDir()); - return path.join(resolved, AUTH_STATE_FILENAME); -} - -export function resolveAuthStorePathForDisplay(agentDir?: string): string { - const pathname = resolveAuthStorePath(agentDir); - return pathname.startsWith("~") ? pathname : resolveUserPath(pathname); -} - -export function resolveAuthStatePathForDisplay(agentDir?: string): string { - const pathname = resolveAuthStatePath(agentDir); - return pathname.startsWith("~") ? pathname : resolveUserPath(pathname); -} +export { + resolveAuthStatePath, + resolveAuthStatePathForDisplay, + resolveAuthStorePath, + resolveAuthStorePathForDisplay, + resolveLegacyAuthStorePath, +} from "./path-resolve.js"; export function ensureAuthStoreFile(pathname: string) { if (fs.existsSync(pathname)) { diff --git a/src/agents/auth-profiles/runtime-snapshots.ts b/src/agents/auth-profiles/runtime-snapshots.ts index 2cf56e5c790..a7de3d46f86 100644 --- a/src/agents/auth-profiles/runtime-snapshots.ts +++ b/src/agents/auth-profiles/runtime-snapshots.ts @@ -1,4 +1,4 @@ -import { resolveAuthStorePath } from "./paths.js"; +import { resolveAuthStorePath } from "./path-resolve.js"; import type { AuthProfileStore } from "./types.js"; const runtimeAuthStoreSnapshots = new Map(); diff --git a/src/agents/auth-profiles/source-check.ts b/src/agents/auth-profiles/source-check.ts index 472f772243b..9e20baec0c4 100644 --- a/src/agents/auth-profiles/source-check.ts +++ b/src/agents/auth-profiles/source-check.ts @@ -1,5 +1,9 @@ import fs from "node:fs"; -import { resolveAuthStatePath, resolveAuthStorePath, resolveLegacyAuthStorePath } from "./paths.js"; +import { + resolveAuthStatePath, + resolveAuthStorePath, + resolveLegacyAuthStorePath, +} from "./path-resolve.js"; import { hasAnyRuntimeAuthProfileStoreSource } from "./runtime-snapshots.js"; function hasStoredAuthProfileFiles(agentDir?: string): boolean {