Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(github): 登录与可用性探测仅检查活动账号
Dashfc93fdb5d02f
diff --git a/apps/desktop/src/main/__tests__/gitContextGhCliTokenSource.test.ts b/apps/desktop/src/main/__tests__/gitContextGhCliTokenSource.test.tsindex c18475a598..a4b9ca070c 100644--- a/apps/desktop/src/main/__tests__/gitContextGhCliTokenSource.test.ts+++ b/apps/desktop/src/main/__tests__/gitContextGhCliTokenSource.test.ts@@ -136,7 +136,7 @@ describe('createGhCliTokenSource', () => {expect(await src.probeAvailability()).toBe(true);expect(execFileFn).toHaveBeenCalledWith(expectedGhExecutable,- ['auth', 'status', '--hostname', 'github.com'],+ ['auth', 'status', '--active', '--hostname', 'github.com'],{ timeout: expect.any(Number) },expect.any(Function),);diff --git a/apps/desktop/src/main/__tests__/githubSetupActiveAccount.test.ts b/apps/desktop/src/main/__tests__/githubSetupActiveAccount.test.tsnew file mode 100644index 0000000000..5655a4c699--- /dev/null+++ b/apps/desktop/src/main/__tests__/githubSetupActiveAccount.test.ts@@ -0,0 +1,35 @@+import { expect, it, vi } from 'vitest';++const mocks = vi.hoisted(() => ({ execFile: vi.fn(), spawn: vi.fn() }));+vi.mock('node:child_process', () => mocks);+vi.mock('../git-context/ghBinary', () => ({ resolveGhBinary: async () => 'gh' }));+vi.mock('../managed-tools/installer', () => ({ installTool: vi.fn() }));+import { createGithubSetup } from '../git-context/githubSetup';+import { createGhCliTokenSource } from '../git-context/ghCliTokenSource';++it('connects with a valid active account even when a secondary account has expired', async () => {+ mocks.execFile.mockImplementation((_binary, args, _options, callback) => {+ const secondaryFailed = args[0] === 'auth' && !args.includes('--active');+ callback(secondaryFailed ? new Error('secondary account expired') : null, '', '');+ });+ mocks.spawn.mockImplementation(() => {+ throw new Error('unexpected login');+ });+ const connected = vi.fn();+ const setup = createGithubSetup('unused', connected);+ setup.start();+ await vi.waitFor(() => expect(setup.snapshot().phase).toBe('connected'));+ expect(connected).toHaveBeenCalledOnce();+ expect(mocks.spawn).not.toHaveBeenCalled();+ const source = createGhCliTokenSource({+ execFileFn: mocks.execFile,+ resolveBinary: async () => 'gh',+ });+ expect(await source.probeAvailability()).toBe(true);+ expect(mocks.execFile).toHaveBeenCalledWith(+ 'gh',+ ['auth', 'status', '--active', '--hostname', 'github.com'],+ expect.any(Object),+ expect.any(Function),+ );+});diff --git a/apps/desktop/src/main/git-context/ghCliTokenSource.ts b/apps/desktop/src/main/git-context/ghCliTokenSource.tsindex 95f2ae30fa..6db649fb20 100644--- a/apps/desktop/src/main/git-context/ghCliTokenSource.ts+++ b/apps/desktop/src/main/git-context/ghCliTokenSource.ts@@ -149,7 +149,7 @@ export function createGhCliTokenSource(deps: GhCliTokenSourceDeps = {}): GhCliTo// stdout/stderr 都不进入日志;该调用只消费退出码,绝不取得 token。execFileFn(bin,- ['auth', 'status', '--hostname', 'github.com'],+ ['auth', 'status', '--active', '--hostname', 'github.com'],{ timeout: GH_PROBE_TIMEOUT_MS },(err) => resolve(err === null),);diff --git a/apps/desktop/src/main/git-context/githubSetup.ts b/apps/desktop/src/main/git-context/githubSetup.tsindex b4edfdd06f..a2c1401f80 100644--- a/apps/desktop/src/main/git-context/githubSetup.ts+++ b/apps/desktop/src/main/git-context/githubSetup.ts@@ -172,7 +172,9 @@ export function createGithubSetup(root: string, connected: () => void): GithubSereturn new GithubSetup({resolveBinary: resolveGhBinary,available: (binary) => check(binary, ['--version']),- authenticated: (binary) => check(binary, ['auth', 'status', '--hostname', 'github.com']),+ // Token reads use the active account; stale secondary accounts must not block setup.+ authenticated: (binary) =>+ check(binary, ['auth', 'status', '--active', '--hostname', 'github.com']),login: loginWithGh,connected,async install(signal, update) {diff --git a/docs/dev-rules/verified-downloads.md b/docs/dev-rules/verified-downloads.mdindex 603c696001..d77266c73b 100644--- a/docs/dev-rules/verified-downloads.md+++ b/docs/dev-rules/verified-downloads.md@@ -60,7 +60,7 @@ Renderer 只接收阶段、进度、设备码和固定 GitHub 授权地址,不安装、下载、授权和完成各有独立文案与操作。下载复用 `DownloadMeter`,成功后只提供「完成」,并停止轮询;再次打开不把上一次成功当作新的登录检查结果。-登录成功用 `gh auth status --hostname github.com` 复核,然后清除 token 和 PR 缓存,+登录前后用 `gh auth status --active --hostname github.com` 检查当前活动账号,避免失效备用账号干扰;成功后清除 token 和 PR 缓存,通过 `git-context:github-connected` 立即刷新顶栏及侧栏。缓存代数隔离登录前的在途响应。安装/登录 IPC 仅限受信本机主窗口,不开放给共享任务或 device-link;SSH/手机远程查看继续使用被控端现有 PR 查询和刷新通道,不会误操作控制端的 GitHub 账号。