export async function isGhInstalled(): Promise { try { await Bun.$`which gh`.quiet(); return true; } catch { return false; } } export async function switchUser(username: string): Promise { await Bun.$`gh auth switch --user ${username}`.quiet(); } export async function addSSHKey(pubKeyPath: string, title: string): Promise { await Bun.$`gh ssh-key add ${pubKeyPath} --title ${title}`.quiet(); } export interface GhUserInfo { login: string; name: string | null; email: string | null; } export async function currentUser(): Promise { try { const result = await Bun.$`gh api user --jq '.login'`.quiet(); return result.text().trim() || null; } catch { return null; } } export async function getUserInfo(): Promise { try { const result = await Bun.$`gh api user --jq '{login: .login, name: .name, email: .email}'`.quiet(); const parsed: unknown = JSON.parse(result.text().trim()); if (!parsed || typeof parsed !== "object") return null; const obj = parsed as Record; if (typeof obj.login !== "string" || !obj.login) return null; return { login: obj.login, name: typeof obj.name === "string" ? obj.name : null, email: typeof obj.email === "string" ? obj.email : null, }; } catch { return null; } }