From 1a1c3174aeda0ea4e140d6c79e16581d8284e025 Mon Sep 17 00:00:00 2001 From: l0ng-ai <24760907+l0ng-ai@users.noreply.github.com> Date: Fri, 27 Nov 2026 06:32:22 +0800 Subject: [PATCH] fix(agents): sign-in dialog without cross-feature imports, gated on canSignIn - The Settings window's boot provides the embedded terminal (lazy), so the Sign In dialog uses embeddedTerminal() only instead of importing features/terminal. - The dialog spawns through the registry's tauriCommands.loginSpawn (one implementation). - The chat banner offers Sign In only for an agent whose login can run in the IDE. - A test pins that every built-in login hint yields the arguments Sign In runs. --- crates/ide-agent/src/provider.rs | 16 +++++++++++++ src/features/agents/AgentSignInDialog.tsx | 29 ++++++----------------- src/features/agents/session/messages.tsx | 5 ++-- src/platform/locales/text/en.json | 3 ++- src/platform/locales/text/zh.json | 3 ++- src/settingsWindowBoot.ts | 12 ++++++++++ 6 files changed, 42 insertions(+), 26 deletions(-) diff --git a/crates/ide-agent/src/provider.rs b/crates/ide-agent/src/provider.rs index 2dfd9e446..e101b0065 100644 --- a/crates/ide-agent/src/provider.rs +++ b/crates/ide-agent/src/provider.rs @@ -976,6 +976,22 @@ mod tests { assert_eq!(reset.env, custom.env); } + #[test] + fn every_builtin_login_hint_yields_the_arguments_sign_in_runs() { + // Sign In runs the arguments in the hint's backticks: rewording a hint must keep that form. + for spec in builtins() { + if matches!(spec.id.as_str(), "claude-acp" | "codex-acp" | "vibe") { + continue; + } + assert!(builtin_login_args(&spec).is_some(), "{}: {}", spec.id, spec.login_hint); + } + let args = |id: &str| builtin_login_args(&builtin_spec(id).unwrap()).unwrap(); + assert_eq!(args("copilot"), ["login"]); + assert_eq!(args("goose"), ["configure"]); + assert_eq!(args("hermes"), ["model"]); + assert!(args("qwen").is_empty()); + } + #[test] fn login_hints_cover_all_builtin_commands_and_preserve_separate_login_tools() { for spec in builtins() { diff --git a/src/features/agents/AgentSignInDialog.tsx b/src/features/agents/AgentSignInDialog.tsx index 87d1df52f..4f623fa22 100644 --- a/src/features/agents/AgentSignInDialog.tsx +++ b/src/features/agents/AgentSignInDialog.tsx @@ -2,14 +2,14 @@ * Interactive sign-in dialog for coding agents (`copilot login`, `codex login`, `claude`, …), * backed by an IDE-managed PTY (`agent_login_spawn`) and a lazily loaded embedded terminal widget. */ -import { Channel } from "@tauri-apps/api/core"; import { useEffect, useRef, useState } from "react"; import type { AgentLoginEvent, TerminalId } from "@/bindings"; import { tx } from "@/platform/i18n"; -import { call, commands } from "@/platform/ipc"; +import { commands } from "@/platform/ipc"; import { Dialog, Spinner, T } from "@/ui"; -import { embeddedTerminal, type EmbeddedTerminal, type EmbeddedTerminalFactory } from "@/workbench/contributions"; +import { embeddedTerminal, type EmbeddedTerminal } from "@/workbench/contributions"; import styles from "./AgentSignInDialog.module.css"; +import { tauriCommands } from "./registry"; export type SignInTarget = { kind: "agent"; id: string; name: string }; @@ -17,22 +17,6 @@ export interface SignInSpawner { loginSpawn?(id: string, cols: number, rows: number, onEvent: (e: AgentLoginEvent) => void): Promise; } -const defaultSpawner: Required = { - loginSpawn: async (id, cols, rows, onEvent) => { - const channel = new Channel(); - channel.onmessage = onEvent; - const info = await call(commands.agentLoginSpawn(id, cols, rows, channel)); - return info.id; - }, -}; - -async function loadTerminalFactory(): Promise { - const registered = embeddedTerminal(); - if (registered) return registered; - const mod = await import("@/features/terminal/embedded"); - return async (host, opts) => mod.createEmbeddedTerminal(host, opts); -} - export function AgentSignInDialog({ target, spawner, @@ -77,8 +61,9 @@ export function AgentSignInDialog({ void (async () => { try { - const factory = await loadTerminalFactory(); - if (disposed) return; + // Provided by the terminal feature (workbench windows) or the Settings window's boot. + const factory = embeddedTerminal(); + if (!factory) throw new Error(tx("The terminal is not available in this window.")); const instance = await factory(el, { onData: (data) => { const id = ptyIdRef.current; @@ -123,7 +108,7 @@ export function AgentSignInDialog({ try { const custom = callbacksRef.current.spawner; - const ptyId = await (custom?.loginSpawn ?? defaultSpawner.loginSpawn)( + const ptyId = await (custom?.loginSpawn ?? tauriCommands.loginSpawn!)( agentId, pendingSize.cols, pendingSize.rows, diff --git a/src/features/agents/session/messages.tsx b/src/features/agents/session/messages.tsx index 3e04d4676..ab0062ef4 100644 --- a/src/features/agents/session/messages.tsx +++ b/src/features/agents/session/messages.tsx @@ -19,7 +19,7 @@ import { formatDuration, formatSentAt, userMessageText } from "../conversation"; import { isSignInErrorMessage, useAgentErrorText } from "../loginHint"; import { isBusy, type ReplyTimes, type ReplyTurn } from "../model"; import { useRevealedText } from "../reveal"; -import { forkTask, refreshProviders, rerunFrom, resendMessage } from "../store"; +import { forkTask, refreshProviders, rerunFrom, resendMessage, useAgents } from "../store"; import { PermissionLine, QuestionForm, type QuestionAnswer } from "./QuestionForm"; import { providerName, samePropsExcept, type UserEntry } from "./shared"; import { SubagentCard, ThoughtEntry, ToolEntry } from "./toolEntries"; @@ -244,7 +244,8 @@ export const Entry = memo( function AgentErrorEntry({ task, message }: { task: AgentTask; message: string }) { const [signingIn, setSigningIn] = useState(false); const text = useAgentErrorText(message); - const canSignIn = isTauri() && isSignInErrorMessage(message); + const providerCanSignIn = useAgents((s) => s.providers.find((p) => p.id === task.provider)?.canSignIn ?? false); + const canSignIn = isTauri() && providerCanSignIn && isSignInErrorMessage(message); const name = providerName(task.provider); return (
diff --git a/src/platform/locales/text/en.json b/src/platform/locales/text/en.json index 51e723201..43827a5a3 100644 --- a/src/platform/locales/text/en.json +++ b/src/platform/locales/text/en.json @@ -4186,5 +4186,6 @@ "Sign-in exited with code {exitCode}.": "Sign-in exited with code {exitCode}.", "Install GitHub CLI": "Install GitHub CLI", "Download manually…": "Download manually…", - "Show Scratches and Consoles": "Show Scratches and Consoles" + "Show Scratches and Consoles": "Show Scratches and Consoles", + "The terminal is not available in this window.": "The terminal is not available in this window." } diff --git a/src/platform/locales/text/zh.json b/src/platform/locales/text/zh.json index d46df2a97..11e667eb3 100644 --- a/src/platform/locales/text/zh.json +++ b/src/platform/locales/text/zh.json @@ -10634,5 +10634,6 @@ "Sign-in exited with code {exitCode}.": "登录已退出,代码为 {exitCode}。", "Install GitHub CLI": "安装 GitHub CLI", "Download manually…": "手动下载…", - "Show Scratches and Consoles": "显示临时文件和控制台" + "Show Scratches and Consoles": "显示临时文件和控制台", + "The terminal is not available in this window.": "此窗口中无法使用终端。" } diff --git a/src/settingsWindowBoot.ts b/src/settingsWindowBoot.ts index 89a45092e..cb260aa5b 100644 --- a/src/settingsWindowBoot.ts +++ b/src/settingsWindowBoot.ts @@ -13,6 +13,17 @@ import { activateSettingsPages as toolsPages } from "./features/tools/settingsPa import { activateSettingsPages as vcsPages } from "./features/vcs/settingsPages"; import { activateSettingsPages as vimPages } from "./features/vim/settingsPages"; import { activateList } from "./windowBoot"; +import { provideEmbeddedTerminal } from "./workbench/contributions"; + +/** The embedded terminal of the agents' Sign In dialog, loaded on first use. */ +function embeddedTerminal(): () => void { + provideEmbeddedTerminal(async (host, options) => + (await import("./features/terminal/loader")) + .loadTerminalRuntime() + .then((rt) => rt.createEmbeddedTerminal(host, options)), + ); + return () => provideEmbeddedTerminal(undefined); +} /** * Native Settings window of project window `parent`: only the settings pages @@ -28,6 +39,7 @@ export function bootSettingsWindow(parent: string): ComponentType { ["plugins", pluginsPages], ["tools", toolsPages], ["agents", agentsPages], + ["terminal", embeddedTerminal], ["vim", vimPages], ["vcs", vcsPages], ["github", githubPages],