Wave 2: 五件套打通全链路(安装/检测/配置/授权/诊断)

- 五个适配器 YAML 全字段补齐(codex/claude-code/gemini/kimi/opencode)
- agentdock-config:TOML/JSON 编解码 + 原子写 + 自动备份
- agentdock-diag:PATH/依赖版本/版本冲突/配置损坏四类规则
- agentdock-core:detectCli/previewAction/runAction 流式/readConfig/writeConfig/authStatus/diagnose
- Tauri IPC 命令 + CLI 详情页/安装确认弹窗/配置表单/诊断页
- cargo test 75 项通过(含 4 项真机 ignored 自测),前端 build 通过
This commit is contained in:
leefer
2026-08-25 08:58:38 +08:00
parent c47494180b
commit 01996a80fe
33 changed files with 9404 additions and 152 deletions
+3
View File
@@ -19,3 +19,6 @@ serde_json = "1"
agentdock-platform = { path = "../../../crates/agentdock-platform" }
agentdock-adapter = { path = "../../../crates/agentdock-adapter" }
agentdock-store = { path = "../../../crates/agentdock-store" }
agentdock-core = { path = "../../../crates/agentdock-core" }
agentdock-secrets = { path = "../../../crates/agentdock-secrets" }
agentdock-diag = { path = "../../../crates/agentdock-diag" }
+121
View File
@@ -0,0 +1,121 @@
//! IPC 命令:CLI 全链路(detectCli / previewAction / runAction / readConfig /
//! writeConfig / authStatus / authorize / diagnose,架构 §2 IPC 契约)
//!
//! 编排全部走 `agentdock-core::Engine`。runAction 通过 Tauri 事件流式回传
//! stdout/stderr;敏感输出经 `agentdock-secrets::redact` 脱敏后才进事件。
use std::collections::BTreeMap;
use agentdock_adapter::{AdapterAction, DryRunPlan};
use agentdock_core::{ActionEvent, ActionOpts, AuthStatus, ConfigFormState, DetectResult, Engine, WriteResult};
use agentdock_diag::DiagnosticReport;
use serde_json::json;
use tauri::Emitter;
/// 把 action 字符串映射为 AdapterActionsnake_case,与 IPC 契约一致)。
fn parse_action(action: &str) -> Result<AdapterAction, String> {
match action {
"install" => Ok(AdapterAction::Install),
"update" => Ok(AdapterAction::Update),
"uninstall" => Ok(AdapterAction::Uninstall),
"write_config" => Ok(AdapterAction::WriteConfig),
"authorize" => Ok(AdapterAction::Authorize),
"repair" => Ok(AdapterAction::Repair),
other => Err(format!("未知动作: {other}")),
}
}
/// 读取单个适配器完整定义(CLI 详情页展示文档/渠道/许可用)。
#[tauri::command(rename = "getAdapter")]
pub fn get_adapter(id: String, state: tauri::State<'_, Engine>) -> Result<agentdock_adapter::Adapter, String> {
state.adapter(&id).map_err(|e| e.to_string())
}
/// 检测单个 CLIdetectCli)。
#[tauri::command(rename = "detectCli")]
pub fn detect_cli(id: String, state: tauri::State<'_, Engine>) -> Result<DetectResult, String> {
state.detect(&id).map_err(|e| e.to_string())
}
/// 干燥运行(previewAction):返回将执行的命令与影响面,不真正执行。
#[tauri::command(rename = "previewAction")]
pub fn preview_action(
id: String,
action: String,
channel: Option<String>,
state: tauri::State<'_, Engine>,
) -> Result<DryRunPlan, String> {
let action = parse_action(&action)?;
let mut plan = state.preview(&id, action).map_err(|e| e.to_string())?;
// 渠道覆盖时调整计划里的命令为所选渠道(供确认弹窗展示)
if let Some(ch) = channel {
if let Some(adapter) = state.adapter(&id).ok() {
if let Some(install) = adapter.install.as_ref() {
if let Some(target) = install.channels.iter().find(|c| c.id == ch) {
if !target.command.is_empty() {
plan.commands = vec![target.command.clone()];
plan.elevate = matches!(target.elevate.as_deref(), Some("if_needed") | Some("required"));
plan.elevate_reason_zh = target.elevate_reason_zh.clone();
}
}
}
}
}
Ok(plan)
}
/// 流式执行动作(runAction):事件经 `cli-action-event` 回传。
#[tauri::command(rename = "runAction")]
pub fn run_action(
app: tauri::AppHandle,
id: String,
action: String,
channel: Option<String>,
state: tauri::State<'_, Engine>,
) -> Result<(), String> {
let action = parse_action(&action)?;
let engine = state.inner().clone();
let opts = ActionOpts { channel };
std::thread::spawn(move || {
let cli_id = id.clone();
let result = engine.run(&id, action, &opts, |ev| {
let _ = app.emit("cli-action-event", json!({ "cli_id": cli_id, "event": ev }));
});
if let Err(e) = result {
let _ = app.emit(
"cli-action-event",
json!({ "cli_id": cli_id, "event": ActionEvent::error(e.to_string()) }),
);
}
});
Ok(())
}
/// 读取配置表单状态(readConfig)。
#[tauri::command(rename = "readConfig")]
pub fn read_config(id: String, state: tauri::State<'_, Engine>) -> Result<ConfigFormState, String> {
state.read_config(&id).map_err(|e| e.to_string())
}
/// 写配置(writeConfig):patch 为 { field_id: value }。
#[tauri::command(rename = "writeConfig")]
pub fn write_config(
id: String,
patch: BTreeMap<String, String>,
state: tauri::State<'_, Engine>,
) -> Result<WriteResult, String> {
state.write_config(&id, &patch).map_err(|e| e.to_string())
}
/// 授权状态(authStatus)。
#[tauri::command(rename = "authStatus")]
pub fn auth_status(id: String, state: tauri::State<'_, Engine>) -> Result<AuthStatus, String> {
state.auth_status(&id).map_err(|e| e.to_string())
}
/// 诊断(diagnose):内部实时取本机环境快照。
#[tauri::command(rename = "diagnose")]
pub fn diagnose(id: String, state: tauri::State<'_, Engine>) -> Result<DiagnosticReport, String> {
let env = agentdock_platform::detect::detect_env();
state.diagnose(&id, &env).map_err(|e| e.to_string())
}
@@ -1,2 +1,3 @@
pub mod catalog;
pub mod cli;
pub mod env;
+20 -1
View File
@@ -1,6 +1,12 @@
mod commands;
use std::path::PathBuf;
use std::sync::Arc;
use tauri::Manager;
use agentdock_core::Engine;
use agentdock_secrets::KeyringSecretStore;
/// 解析适配器目录。
/// 优先级:环境变量 AGENTDOCK_ADAPTERS_DIR > CWD 相对路径(tauri dev 时 CWD=apps/desktop
@@ -26,16 +32,29 @@ fn adapters_dir() -> PathBuf {
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
tauri::Builder::default()
.setup(|_app| {
.setup(|app| {
// 自测标记:`tauri dev` 启动后日志出现该行即代表壳已就绪
println!("[agentdock] window-ready");
// Wave 0:初始化 SQLite 空库(架构 §2 状态存储层)
let _ = agentdock_store::Store::open_default();
// Wave 2:初始化编排引擎(适配器目录 + 系统密钥库)
let secrets: Arc<dyn agentdock_secrets::SecretStore> = Arc::new(KeyringSecretStore::new());
let engine = Engine::new(adapters_dir(), secrets);
app.manage(engine);
Ok(())
})
.invoke_handler(tauri::generate_handler![
commands::env::detect_env,
commands::catalog::list_catalog,
commands::cli::detect_cli,
commands::cli::get_adapter,
commands::cli::preview_action,
commands::cli::run_action,
commands::cli::read_config,
commands::cli::write_config,
commands::cli::auth_status,
commands::cli::diagnose,
])
.run(tauri::generate_context!())
.expect("error while running tauri application");