Merge branch 'fix/lazy-homedir-env-first'

This commit is contained in:
Mario Zechner 2026-01-09 22:09:27 +01:00
commit 35690f6d1a
4 changed files with 51 additions and 6 deletions

View file

@ -6,13 +6,12 @@ import { fileURLToPath } from "node:url";
const GITHUB_API_RELEASES = "https://api.github.com/repos/openai/codex/releases/latest";
const GITHUB_HTML_RELEASES = "https://github.com/openai/codex/releases/latest";
const DEFAULT_AGENT_DIR = join(homedir(), ".pi", "agent");
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const FALLBACK_PROMPT_PATH = join(__dirname, "codex-instructions.md");
function getAgentDir(): string {
return process.env.PI_CODING_AGENT_DIR || DEFAULT_AGENT_DIR;
return process.env.PI_CODING_AGENT_DIR || join(homedir(), ".pi", "agent");
}
function getCacheDir(): string {

View file

@ -26,13 +26,20 @@ import type {
ThinkingLevel,
} from "./types.js";
const VERTEX_ADC_CREDENTIALS_PATH = join(homedir(), ".config", "gcloud", "application_default_credentials.json");
let cachedVertexAdcCredentialsExists: boolean | null = null;
function hasVertexAdcCredentials(): boolean {
if (cachedVertexAdcCredentialsExists === null) {
cachedVertexAdcCredentialsExists = existsSync(VERTEX_ADC_CREDENTIALS_PATH);
// Check GOOGLE_APPLICATION_CREDENTIALS env var first (standard way)
const gacPath = process.env.GOOGLE_APPLICATION_CREDENTIALS;
if (gacPath) {
cachedVertexAdcCredentialsExists = existsSync(gacPath);
} else {
// Fall back to default ADC path (lazy evaluation)
cachedVertexAdcCredentialsExists = existsSync(
join(homedir(), ".config", "gcloud", "application_default_credentials.json"),
);
}
}
return cachedVertexAdcCredentialsExists;
}