Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
Report a missing gh as gh missing, not signed out, for named GitHub logins
Claude6a36eee4dcec
diff --git a/server/services/githubAccounts.js b/server/services/githubAccounts.jsindex 4f16533c21..f990c46735 100644--- a/server/services/githubAccounts.js+++ b/server/services/githubAccounts.js@@ -168,30 +168,42 @@ export function deleteAccount(id) {const loginCommand = (host) => `gh auth login --hostname ${host} --web --clipboard`;+function classifyError(error) {+ if (error?.ghExitCode !== undefined) return classifyGhProbe({ code: error.ghExitCode, stderr: error.ghStderr });+ if (error?.code) return classifyGhProbe({ spawnError: error });+ return classifyGhProbe({ code: null, stderr: error?.message });+}++// `gh auth token` only reads gh's local credential store, so a non-zero exit+// means "no credential for that login" — unless gh itself is missing or the+// call never finished, which must not be reported as signed out.+const TOKEN_LOOKUP_FAULTS = new Set(['not-installed', 'unreachable']);+/**- * The environment that makes `gh` act as THIS account, or `null` when `gh`- * holds no credential for the named login. A named login is pinned through its- * own token so a second login on the same host works without `gh auth switch`;- * an account with no login uses whichever login is active on that host.+ * `{ env }` that makes `gh` act as THIS account, or `{ status }` when it can't.+ * A named login is pinned through its own token so a second login on the same+ * host works without `gh auth switch`; an account with no login uses whichever+ * login is active on that host.*/async function resolveGitHubAccountEnv(account, { baseEnv = process.env } = {}) {const env = { ...baseEnv, GH_HOST: account.host };- if (!account.login) return env;- const token = await execGh(+ if (!account.login) return { env };+ const lookup = await execGh(['auth', 'token', '--hostname', account.host, '--user', account.login],STATUS_TIMEOUT_MS,{ env },- ).catch(() => null);- if (!token) return null;- return account.host === GITHUB_DOT_COM- ? { ...env, GH_TOKEN: token }- : { ...env, GH_ENTERPRISE_TOKEN: token };-}--function classifyError(error) {- if (error?.ghExitCode !== undefined) return classifyGhProbe({ code: error.ghExitCode, stderr: error.ghStderr });- if (error?.code) return classifyGhProbe({ spawnError: error });- return classifyGhProbe({ code: null, stderr: error?.message });+ )+ .then((token) => ({ token, error: null }))+ .catch((error) => ({ token: null, error }));+ if (!lookup.token) {+ const { status } = classifyError(lookup.error);+ return { status: TOKEN_LOOKUP_FAULTS.has(status) ? status : 'not-authenticated' };+ }+ return {+ env: account.host === GITHUB_DOT_COM+ ? { ...env, GH_TOKEN: lookup.token }+ : { ...env, GH_ENTERPRISE_TOKEN: lookup.token },+ };}/**@@ -202,7 +214,10 @@ export async function getAccountStatus(id) {const account = await getAccount(id);const { host, login } = account;const checkedAt = new Date().toISOString();- const env = await resolveGitHubAccountEnv(account);+ const { env, status: lookupStatus } = await resolveGitHubAccountEnv(account);+ if (lookupStatus && lookupStatus !== 'not-authenticated') {+ return { id, host, status: lookupStatus, login: null, checkedAt, remedy: ghRemedy(lookupStatus, { hostname: host }), command: null };+ }if (!env) {return {id, host, status: 'not-authenticated', login: null, checkedAt,diff --git a/server/services/githubAccounts.test.js b/server/services/githubAccounts.test.jsindex bf005c4792..539bb6ff94 100644--- a/server/services/githubAccounts.test.js+++ b/server/services/githubAccounts.test.js@@ -111,6 +111,13 @@ describe('GitHub accounts API', () => {expect(res.body).toEqual(expect.objectContaining({ status: 'not-authenticated', command: 'gh auth login --hostname github.example.com --web --clipboard' }));});+ it('reports a missing gh binary instead of a sign-out for a named login', async () => {+ const { body: account } = await request(app).post('/api/github/accounts').send({ host: 'github.example.com', login: 'alice' });+ vi.mocked(execGh).mockRejectedValue(Object.assign(new Error('spawn gh ENOENT'), { code: 'ENOENT' }));+ const res = await request(app).get(`/api/github/accounts/${account.id}/status`);+ expect(res.body).toEqual(expect.objectContaining({ status: 'not-installed', command: null }));+ });+it('flags an active login that differs from the configured one', async () => {await request(app).put('/api/github/accounts/github-com').send({ login: 'octocat' });vi.mocked(execGh).mockImplementation(async (args) => (args[0] === 'auth' ? 'gho_example' : 'someone-else'));