Skip to content

feat(auth): support agy acp --login flow for Antigravity accounts - #10103

Merged
funkpopo merged 5 commits into
farion1231:mainfrom
jimpablo:feat/agy-acp-login
Dec 2, 2026
Merged

funkpopo merged 5 commits into
farion1231:mainfrom
jimpablo:feat/agy-acp-login

Conversation

@jimpablo

@jimpablo jimpablo commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Human Note / 本人说明

按 #10100 的方案保留为 Draft PR:接入官方 agy acp --login 在应用内完成打开/复制登录链接与粘贴授权码/回调地址,支持桌面登录面保持原样、旧版 agy 自动回退到终端登录流程。目前已基于最新 main(含 #9999、#10102、#10122、#10124)完成 rebase 与加固,仍保持 Draft 等待维护者确认方向后再决定是否推进。

Summary / 概述

Proposes in-app Antigravity sign-in via the official agy acp --login command (mirroring t3code's compliant pattern and cc-switch's ClaudeOfficialSection paste box), while preserving desktop sign-in (#10122) and terminal login fallback for older agy binaries. Kept as Draft until maintainers confirm the approach.

  1. 合规边界:
    • 全程委托未经修改的官方 agy acp --login 子进程完成 OAuth 授权与钥匙串写入;CC Switch 不持有/使用 agy 的 OAuth client ID/secret,不直接请求 Google,也不伪造 User-Agent。
  2. 已基于最新 main 完成 Rebase 与对齐:
  3. 浏览器拉起抑制与子进程环境加固(src-tauri/src/services/agy_account/acp_login.rs):
    • Unix:在 0700 私有临时目录放置拦截版 open / xdg-open shim,并通过 libc::access(..., X_OK) 检测 noexec 挂载;若临时目录不可执行,自动回退为过滤 PATH(移除系统 open/xdg-open 所在系统目录,仅保留二进制本身目录),避免用户关闭「登录时自动打开浏览器」时仍被 agy 弹窗。
    • Windows:对原生 .exe 设置 NoDefaultCurrentDirectoryInExePath=1 且 PATH="",屏蔽 SSH_* 与 AGY_CLI_FORCE_FILE_TOKEN_STORAGE 环境变量。
  4. 前端等待卡片与 i18n(AgyOAuthSection.tsx、auth.ts、8 语种 locale):
    • 遵循「登录时自动打开浏览器」偏好(关闭时复制链接到剪贴板并展示 acpLinkNote);开启 AgyPasteBox 支持粘贴授权码或完整回调 URL 提交,保留原终端与桌面登录测试。
  5. Rebase 后本地验证通过:
    • Frontend:pnpm typecheck、pnpm format:check、pnpm knip、pnpm test:unit tests/components/AgyOAuthSection.test.tsx tests/hooks/useManagedAuth.test.tsx(2 files, 51 passed)
    • Backend:cargo fmt --check、cargo clippy --all-targets -- -D warnings、cargo test --lib agy_account(80 passed, 0 failed, 1 ignored)、cargo test --test integration(231 passed, 0 failed)

Related Issue / 关联 Issue

Refs #10100

Screenshots / 截图

Before / 修改前 After / 修改后
CLI 登录路径点击「添加账号」必须弹出系统终端运行 agy,无法复用「登录时自动打开浏览器」偏好 在 Terminal(bin) 路径探测支持 agy acp --login 时,直接应用内展示复制链接 + 粘贴框(关闭自动开浏览器时不弹终端),旧版自动回退终端,Desktop 登录流程保持不变

Checklist / 检查清单

  • pnpm typecheck passes / 通过 TypeScript 类型检查
  • pnpm format:check passes / 通过代码格式检查
  • cargo clippy passes (if Rust code changed) / 通过 Clippy 检查(如修改了 Rust 代码)
  • Updated i18n files if user-facing text changed / 如修改了用户可见文本,已更新国际化文件

@github-actions github-actions Bot added frontend Frontend (React/TypeScript) backend Backend (Rust/Tauri) i18n Internationalization (zh/en/ja) labels Nov 29, 2026
@funkpopo
funkpopo marked this pull request as ready for review December 2, 2026 05:53
@funkpopo

funkpopo commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

统一后台进程与 Windows 隔离策略 — agy_config.rs

background_command 默认注入 AGY_CLI_DISABLE_AUTO_UPDATE=true,防止 agy 在后台触发自更新子进程。
提取 is_windows_native_exe、isolate_windows_background_exe(对原生 .exe 设置 NoDefaultCurrentDirectoryInExePath=1 且清空 PATH,避免解析并拉起 git、rundll32 等外部控制台程序;.cmd/.bat 保留 PATH)与 apply_neutral_current_dir(切换到 temp_dir / home_dir,避免因继承工作目录触发额外仓库探测)。

额度查询防弹窗加固 — subscription_agy.rs

提取 build_usage_command 与 wrap_background_command(保留 CREATE_NO_WINDOW + JobObject + KillOnDrop,并应用禁用自更新、中性工作目录和 Windows .exe 隔离)。

模型列表与协议兜底命令加固

model_fetch.rs:在 get_agy_models 中应用 isolate_windows_background_exe 与中性工作目录。

sync_protocol.rs:为 Windows 下的 Command::new("hostname") 补充 creation_flags(0x0800_0000)。

ACP 登录探测与生命周期对齐 acp_login.rs:

复用 agy_config 的工作目录与 Windows 隔离函数;将 HELP_TIMEOUT 提升至 15s(防止 Windows Defender 冷扫描大型 agy.exe 导致误回退到终端登录);增加基于二进制修改时间和文件大小的 ACP_LOGIN_SUPPORT_CACHE;修正 is_windows_native_exe 重导出为 #[cfg(test)]。

mod.rs:提取 stash_live_before_acp_login,确保 start_login_acp 在开始登录前正确暂存未收集的登录态并在完成时清除。

AgyOAuthSection.tsx 与 8 个语言文件(zh.json、en.json 等):

更新 authCenter.group.agyHelp 提示文案。

回归测试补充

tests.rs 与 subscription_agy.rs:新增测试覆盖 CREATE_NO_WINDOW + JobObject 包装、supports_acp_login 元数据缓存、ACP 登录前后 stash 状态流转以及额度命令隔离。

@YUZHEthefool YUZHEthefool left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

复核了最新的 d60934f;之前测试初始化的问题已修复,下面三个生命周期问题仍能复现。

三个问题的本地修复及 6 项回归测试已完成,目前尚未推送。验证通过:Antigravity 定向测试 91 passed / 1 ignored,Rust 全量单元测试 5288 passed / 12 ignored、集成测试 236 passed,前端 4800 passed,以及 typecheck、format、renderer build 和 Clippy。

@funkpopo
funkpopo merged commit 137f5f7 into farion1231:main Dec 2, 2026
19 of 21 checks passed
@farion1231

Copy link
Copy Markdown
Owner

感谢 @jimpablo 的贡献!从 #10100 的方案到这个实现都考虑得很周全:全程交给官方 agy acp --login 完成授权,旧版 agy 自动回退终端,桌面端登录不受影响。以后添加 Antigravity 账号不用再弹终端了。

也谢谢 @funkpopo 和 @YUZHEthefool 补上的 Windows 后台加固和登录进程生命周期修复。这个改动会随下一个版本发布。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Backend (Rust/Tauri) frontend Frontend (React/TypeScript) i18n Internationalization (zh/en/ja)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants