import { execFileSync } from "node:child_process"; export function isFetchEnabled(): boolean { const fetchEnabled = (process.env.RTFD_FETCH ?? "true").toLowerCase(); return !["false", "0", "no"].includes(fetchEnabled); } export function getCacheConfig(): [boolean, number] { const enabled = !["false", "0", "no"].includes((process.env.RTFD_CACHE_ENABLED ?? "true").toLowerCase()); const rawTtl = process.env.RTFD_CACHE_TTL ?? "604800"; const ttl = Number.parseFloat(rawTtl); return [enabled, Number.isFinite(ttl) ? ttl : 604800]; } export function getGithubToken(): string | null { const authMethod = (process.env.GITHUB_AUTH ?? "token").toLowerCase(); if (authMethod === "disabled") { return null; } if (authMethod === "token" || authMethod === "auto") { const token = process.env.GITHUB_TOKEN; if (token) { return token; } if (authMethod === "token") { console.warn("GitHub token not found in environment"); return null; } } if (authMethod === "cli" || authMethod === "auto") { try { const output = execFileSync("gh", ["auth", "token"], { encoding: "utf8" }).trim(); if (output) { return output; } } catch { // fall through to the error below } } console.warn("GitHub token not found via configured methods"); return null; }