Skip to content

[Feature Request] 支持设置默认 ACP Agent(如 Codex),替代硬编码的 "One Agent" #318

Description

@w582745483

[Feature Request] 支持设置默认 ACP Agent(如 Codex),替代硬编码的 "One Agent"

背景

Navop 的 AI 对话面板(DefaultAgentChatPanel → AgentChatView)在每次打开时固定默认选中内置的 "One Agent"(Backend::Local),外部 ACP agent(如 Codex)排在第二位。

对于以 Codex 等外部 ACP agent 为主要工作流的用户,每次打开 AI 对话都必须手动切换一次,体验割裂。

现状(源码分析,main 分支)

默认选中 "One Agent" 是硬编码行为,与配置无关:

  1. crates/ai_chat_view/src/agent_view.rs(~L1080) —— 新建视图时 backend 固定初始化为 Backend::Local:

    backend: Backend::Local,
    current_acp_id: None,
  2. crates/ai_chat_view/src/agent_view/acp_options.rs —— "One Agent" 永远是第一个且默认选中:

    pub(super) fn composer_agent_options(...) -> Vec<ComposerAgentOption> {
        let mut options = vec![ComposerAgentOption::local(
            "One Agent",
            backend == Backend::Local,   // 只要 backend==Local 就是选中态
            acp_connecting,
        )];
        options.extend(acp_agents.iter().map(...));  // Codex 等排其后
        options
    }
  3. AgentChatViewConfig(agent_view.rs ~L561) —— 所有字段均已核对,无 initial_backend / default_acp_agent_id 之类字段:

    pub struct AgentChatViewConfig {
        pub runtime: Arc<Runtime>,
        pub resources: ResourceContext,
        ...
        pub acp_agents: Vec<AcpAgentEntry>,   // 仅决定"有哪些可切换",不决定默认
        ...
    }
  4. AcpAgentEntry(acp/config/model.rs ~L69) —— 仅 id / name / config / diagnostic 四个字段,无 default / preferred / sort_order 标记。

  5. 无持久化机制 —— 全库搜索无 last_acp_id / saved_backend / default_target 相关字段;select_local_backend(acp_ui.rs ~L40)还会在会话/连接断开时主动把 backend 重置回 Backend::Local。用户手动切一次 Codex,也无法跨会话/跨面板记住。

期望行为

提供至少一种方式让用户设置默认 agent,例如:

  • 设置项(优先级最高):在设置(settings.json)中新增一个键,如 ai_chat.default_agent_id / ai_chat.default_backend,值为 "local" 或某个 ACP agent id。打开 AI 对话面板时,若该 agent 可用,则默认选中它(backend = Backend::Acp; current_acp_id = Some(id) 并触发连接)。
  • 或 AcpAgentConfig 增加 default: bool 标记,build_acp_agent_entries 返回时若存在 default 条目则优先作为初始选中。
  • 或(最简)在 AgentChatViewConfig 增加可选字段 initial_backend: Option<Backend> / initial_acp_agent_id: Option<SharedString>,由宿主(设置面板 / 扩展)注入。

建议实现(参考,改动很小)

  1. agent_view.rs AgentChatView::new / view_with_config:

    // 从 config 读取初始 agent(而非固定 Local)
    let initial_acp_id = config.initial_acp_agent_id.clone();
    ...
    backend: if initial_acp_id.is_some() { Backend::Acp } else { Backend::Local },
    current_acp_id: initial_acp_id,

    并在视图构建完成后若 current_acp_id 存在则触发 spawn_acp_connect(复用现有 select_acp_backend 的连接逻辑)。

  2. AgentChatViewConfig 增加:

    /// 初始选中的 ACP agent id;None = One Agent(保持现状)。
    pub initial_acp_agent_id: Option<SharedString>,
  3. 宿主侧(注册 AcpAgentConfigProvider 的地方)从 settings.json(如 ai_chat.default_agent)读取默认 id,填充到 config。

备选/临时 workaround(不需要改代码)

  • 每次打开面板手动在下拉中选择 Codex(当前唯一方式)。
  • 或对每个会话保持 Codex 不切走(同一面板内会话切换不重置 backend,但新建面板 / 连接断开会重置)。

环境

  • Navop 版本:v0.19.2(本机)
  • ACP agent:codex-acp(stdio),acp_agent.json 位于 ~/.config/navop/extensions/acp_agents/codex-acp/

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions