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.
Цей коміт міститься в:
l0ng-ai committed 2026-11-27 06:32:22 +08:00
1 джерело dd1ab68e11
коміт 1a1c3174ae
6 files changed
+42 -26

No files matched your search

+16
Переглянути файл
@@ -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() {
+7 -22
Переглянути файл
@@ -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<TerminalId>;
}
const defaultSpawner: Required<SignInSpawner> = {
loginSpawn: async (id, cols, rows, onEvent) => {
const channel = new Channel<AgentLoginEvent>();
channel.onmessage = onEvent;
const info = await call(commands.agentLoginSpawn(id, cols, rows, channel));
return info.id;
},
};
async function loadTerminalFactory(): Promise<EmbeddedTerminalFactory> {
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,
+3 -2
Переглянути файл
@@ -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 (
<div className={styles.error} role="alert">
+2 -1
Переглянути файл
@@ -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."
}
+2 -1
Переглянути файл
@@ -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.": "此窗口中无法使用终端。"
}
+12
Переглянути файл
@@ -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],