feat(desktop): GitHub Device Flow 登录与工作区 PR 面板#115
Merged
Conversation
引入 host-internal github 子模块(PKCE、OAuth、remote 解析、PR API)及 Desktop keyring 存储封装。
Electron main 进程通过 loopback 回调完成 OAuth,host 命令暴露连接状态与登录/断开能力。
基于 origin 远程与当前分支调用 GitHub API,host 命令返回 PR 摘要与详情并处理认证错误。
右侧工具栏可通过 + 菜单开启 PR 面板,展示 GitHub 连接状态、示例数据与当前分支 PR 信息。
从仓库移除硬编码 Client ID,改为读取 apps/desktop/.env 中的 SPIRIT_GITHUB_OAUTH_CLIENT_ID;提供 .env.example 供协作参考。
OAuth App 的 authorization code 换 token 仍需 client_secret;改用设备流, 仅需 client_id 并在 UI 展示验证码。
PR 查询遇到 401 时清除 keyring 中的 OAuth token,面板在错误后重新拉取 auth status,避免仍显示已连接。
为 pending device auth 绑定 AbortController,disconnect 或 cancel 时 abort 轮询,避免 clearPending 后仍继续请求 GitHub。
覆盖 device code 请求、authorization_pending 轮询、abort 取消与 access_denied 错误映射。
新增 cancelGitHubDeviceLogin host 命令并在 PR 面板显示取消按钮, 登录等待期间可中止轮询而不必断开已保存的凭证。
与 401 一致,403(含 org SSO 未授权 token)时清除 keyring 中的 token, 避免 UI 仍显示已连接但 API 持续失败。
登录已统一走 Device Flow;删除 pkce 模块、authorization code 换 token 与 loopback redirect 相关常量及实现。
N123999
added a commit
that referenced
this pull request
Jul 1, 2026
feat(desktop): GitHub Device Flow 登录与工作区 PR 面板
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
host-internal增加 GitHub remote 解析、PR API 与 Device Flow 模块;OAuth token 存 keyring,Client ID 通过apps/desktop/.env配置(见.env.example)。Test plan
apps/desktop/.env.example为.env并配置SPIRIT_GITHUB_OAUTH_CLIENT_ID(OAuth App 已启用 Device Flow)packages/host-internalDevice Flow / remote / PR mapping 单测通过apps/desktopnpm run test:lib通过