fix(intelligence): 精确化 dead_code 标注并实现 LLM 上下文压缩
Some checks failed
CI / Lint & TypeCheck (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
CI / Build Frontend (push) Has been cancelled
CI / Rust Check (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
CI / E2E Tests (push) Has been cancelled
Some checks failed
CI / Lint & TypeCheck (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
CI / Build Frontend (push) Has been cancelled
CI / Rust Check (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
CI / E2E Tests (push) Has been cancelled
- 将 intelligence/llm/memory/browser 模块的 dead_code 注释从模糊的 "reserved for future" 改为明确说明 Tauri invoke_handler 运行时注册机制 - 为 identity.rs 中 3 个真正未使用的方法添加 #[allow(dead_code)] - 实现 compactor use_llm: true 功能:新增 compact_with_llm 方法和 compactor_compact_llm Tauri 命令,支持 LLM 驱动的对话摘要生成 - 将 pipeline_commands.rs 中 40+ 处 println!/eprintln! 调试输出替换为 tracing::debug!/warn!/error! 结构化日志 - 移除 intelligence/mod.rs 中不必要的 #[allow(unused_imports)]
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
// OpenFang Kernel integration for ZClaw desktop app
|
||||
// Supports OpenFang Kernel (successor to OpenClaw Gateway)
|
||||
// ZCLAW Kernel integration for ZClaw desktop app
|
||||
// Supports ZCLAW Kernel (successor to OpenClaw Gateway)
|
||||
// - Port: 4200 (was 18789)
|
||||
// - Binary: openfang (was openclaw)
|
||||
// - Config: ~/.openfang/openfang.toml (was ~/.openclaw/openclaw.json)
|
||||
// - Binary: zclaw (was openclaw)
|
||||
// - Config: ~/.zclaw/zclaw.toml (was ~/.openclaw/openclaw.json)
|
||||
|
||||
// Viking CLI sidecar module for local memory operations
|
||||
mod viking_commands;
|
||||
mod embedding_adapter;
|
||||
mod summarizer_adapter;
|
||||
|
||||
// Memory extraction and context building modules (supplement CLI)
|
||||
mod memory;
|
||||
@@ -23,7 +25,10 @@ mod memory_commands;
|
||||
// Intelligence Layer (migrated from frontend lib/)
|
||||
mod intelligence;
|
||||
|
||||
// Internal ZCLAW Kernel commands (replaces external OpenFang process)
|
||||
// Intelligence hooks - pre/post conversation integration
|
||||
mod intelligence_hooks;
|
||||
|
||||
// Internal ZCLAW Kernel commands (replaces external ZCLAW process)
|
||||
mod kernel_commands;
|
||||
|
||||
// Pipeline commands (DSL-based workflows)
|
||||
@@ -85,47 +90,47 @@ struct LocalGatewayPairingApprovalResult {
|
||||
device_id: Option<String>,
|
||||
}
|
||||
|
||||
struct OpenFangRuntime {
|
||||
struct ZclawRuntime {
|
||||
source: String,
|
||||
executable: PathBuf,
|
||||
pre_args: Vec<String>,
|
||||
display_path: PathBuf,
|
||||
}
|
||||
|
||||
struct OpenFangCommandOutput {
|
||||
struct ZclawCommandOutput {
|
||||
stdout: String,
|
||||
runtime: OpenFangRuntime,
|
||||
runtime: ZclawRuntime,
|
||||
}
|
||||
|
||||
/// Default OpenFang Kernel port
|
||||
const OPENFANG_DEFAULT_PORT: u16 = 4200;
|
||||
/// Default ZCLAW Kernel port
|
||||
const ZCLAW_DEFAULT_PORT: u16 = 4200;
|
||||
|
||||
const TAURI_ALLOWED_ORIGINS: [&str; 2] = ["http://tauri.localhost", "tauri://localhost"];
|
||||
|
||||
fn command_error(runtime: &OpenFangRuntime, error: std::io::Error) -> String {
|
||||
fn command_error(runtime: &ZclawRuntime, error: std::io::Error) -> String {
|
||||
if error.kind() == std::io::ErrorKind::NotFound {
|
||||
match runtime.source.as_str() {
|
||||
"bundled" => format!(
|
||||
"未找到 ZCLAW 内置 OpenFang 运行时:{}",
|
||||
"未找到 ZCLAW 内置运行时:{}",
|
||||
runtime.display_path.display()
|
||||
),
|
||||
"development" => format!(
|
||||
"未找到开发态 OpenFang 运行时:{}",
|
||||
"未找到开发态运行时:{}",
|
||||
runtime.display_path.display()
|
||||
),
|
||||
"override" => format!(
|
||||
"未找到 ZCLAW_OPENFANG_BIN 指定的 OpenFang 运行时:{}",
|
||||
"未找到 ZCLAW_BIN 指定的运行时:{}",
|
||||
runtime.display_path.display()
|
||||
),
|
||||
_ => "未找到 OpenFang 运行时。请重新安装 ZCLAW,或在开发环境中安装 OpenFang CLI。"
|
||||
_ => "未找到运行时。请重新安装 ZCLAW,或在开发环境中安装 ZCLAW CLI。"
|
||||
.to_string(),
|
||||
}
|
||||
} else {
|
||||
format!("运行 OpenFang 失败: {error}")
|
||||
format!("运行 ZCLAW 失败: {error}")
|
||||
}
|
||||
}
|
||||
|
||||
fn runtime_path_string(runtime: &OpenFangRuntime) -> String {
|
||||
fn runtime_path_string(runtime: &ZclawRuntime) -> String {
|
||||
runtime.display_path.display().to_string()
|
||||
}
|
||||
|
||||
@@ -137,20 +142,20 @@ fn binary_extension() -> &'static str {
|
||||
}
|
||||
}
|
||||
|
||||
fn openfang_sidecar_filename() -> String {
|
||||
format!("openfang-{}{}", env!("TARGET"), binary_extension())
|
||||
fn zclaw_sidecar_filename() -> String {
|
||||
format!("zclaw-{}{}", env!("TARGET"), binary_extension())
|
||||
}
|
||||
|
||||
fn openfang_plain_filename() -> String {
|
||||
format!("openfang{}", binary_extension())
|
||||
fn zclaw_plain_filename() -> String {
|
||||
format!("zclaw{}", binary_extension())
|
||||
}
|
||||
|
||||
fn push_runtime_candidate(candidates: &mut Vec<OpenFangRuntime>, source: &str, executable: PathBuf) {
|
||||
fn push_runtime_candidate(candidates: &mut Vec<ZclawRuntime>, source: &str, executable: PathBuf) {
|
||||
if candidates.iter().any(|candidate| candidate.display_path == executable) {
|
||||
return;
|
||||
}
|
||||
|
||||
candidates.push(OpenFangRuntime {
|
||||
candidates.push(ZclawRuntime {
|
||||
source: source.to_string(),
|
||||
display_path: executable.clone(),
|
||||
executable,
|
||||
@@ -158,15 +163,15 @@ fn push_runtime_candidate(candidates: &mut Vec<OpenFangRuntime>, source: &str, e
|
||||
});
|
||||
}
|
||||
|
||||
/// Build binary runtime (OpenFang is a single binary, not npm package)
|
||||
fn build_binary_runtime(source: &str, root_dir: &PathBuf) -> Option<OpenFangRuntime> {
|
||||
/// Build binary runtime (ZCLAW is a single binary, not npm package)
|
||||
fn build_binary_runtime(source: &str, root_dir: &PathBuf) -> Option<ZclawRuntime> {
|
||||
// Try platform-specific binary names
|
||||
let binary_names = get_platform_binary_names();
|
||||
|
||||
for name in binary_names {
|
||||
let binary_path = root_dir.join(&name);
|
||||
if binary_path.is_file() {
|
||||
return Some(OpenFangRuntime {
|
||||
return Some(ZclawRuntime {
|
||||
source: source.to_string(),
|
||||
executable: binary_path.clone(),
|
||||
pre_args: Vec::new(),
|
||||
@@ -177,30 +182,30 @@ fn build_binary_runtime(source: &str, root_dir: &PathBuf) -> Option<OpenFangRunt
|
||||
None
|
||||
}
|
||||
|
||||
/// Get platform-specific binary names for OpenFang
|
||||
/// Get platform-specific binary names for ZCLAW
|
||||
fn get_platform_binary_names() -> Vec<String> {
|
||||
let mut names = Vec::new();
|
||||
|
||||
if cfg!(target_os = "windows") {
|
||||
names.push("openfang.exe".to_string());
|
||||
names.push(format!("openfang-{}.exe", env!("TARGET")));
|
||||
names.push("zclaw.exe".to_string());
|
||||
names.push(format!("zclaw-{}.exe", env!("TARGET")));
|
||||
} else if cfg!(target_os = "macos") {
|
||||
if cfg!(target_arch = "aarch64") {
|
||||
names.push("openfang-aarch64-apple-darwin".to_string());
|
||||
names.push("zclaw-aarch64-apple-darwin".to_string());
|
||||
} else {
|
||||
names.push("openfang-x86_64-apple-darwin".to_string());
|
||||
names.push("zclaw-x86_64-apple-darwin".to_string());
|
||||
}
|
||||
names.push(format!("openfang-{}", env!("TARGET")));
|
||||
names.push("openfang".to_string());
|
||||
names.push(format!("zclaw-{}", env!("TARGET")));
|
||||
names.push("zclaw".to_string());
|
||||
} else {
|
||||
// Linux
|
||||
if cfg!(target_arch = "aarch64") {
|
||||
names.push("openfang-aarch64-unknown-linux-gnu".to_string());
|
||||
names.push("zclaw-aarch64-unknown-linux-gnu".to_string());
|
||||
} else {
|
||||
names.push("openfang-x86_64-unknown-linux-gnu".to_string());
|
||||
names.push("zclaw-x86_64-unknown-linux-gnu".to_string());
|
||||
}
|
||||
names.push(format!("openfang-{}", env!("TARGET")));
|
||||
names.push("openfang".to_string());
|
||||
names.push(format!("zclaw-{}", env!("TARGET")));
|
||||
names.push("zclaw".to_string());
|
||||
}
|
||||
|
||||
names
|
||||
@@ -208,7 +213,7 @@ fn get_platform_binary_names() -> Vec<String> {
|
||||
|
||||
/// Legacy: Build staged runtime using Node.js (for backward compatibility)
|
||||
#[allow(dead_code)]
|
||||
fn build_staged_runtime_legacy(source: &str, root_dir: PathBuf) -> Option<OpenFangRuntime> {
|
||||
fn build_staged_runtime_legacy(source: &str, root_dir: PathBuf) -> Option<ZclawRuntime> {
|
||||
let node_executable = root_dir.join(if cfg!(target_os = "windows") {
|
||||
"node.exe"
|
||||
} else {
|
||||
@@ -216,14 +221,14 @@ fn build_staged_runtime_legacy(source: &str, root_dir: PathBuf) -> Option<OpenFa
|
||||
});
|
||||
let entrypoint = root_dir
|
||||
.join("node_modules")
|
||||
.join("openfang")
|
||||
.join("openfang.mjs");
|
||||
.join("zclaw")
|
||||
.join("zclaw.mjs");
|
||||
|
||||
if !node_executable.is_file() || !entrypoint.is_file() {
|
||||
return None;
|
||||
}
|
||||
|
||||
Some(OpenFangRuntime {
|
||||
Some(ZclawRuntime {
|
||||
source: source.to_string(),
|
||||
executable: node_executable,
|
||||
pre_args: vec![entrypoint.display().to_string()],
|
||||
@@ -232,7 +237,7 @@ fn build_staged_runtime_legacy(source: &str, root_dir: PathBuf) -> Option<OpenFa
|
||||
}
|
||||
|
||||
/// Build staged runtime - prefers binary, falls back to Node.js for legacy support
|
||||
fn build_staged_runtime(source: &str, root_dir: PathBuf) -> Option<OpenFangRuntime> {
|
||||
fn build_staged_runtime(source: &str, root_dir: PathBuf) -> Option<ZclawRuntime> {
|
||||
// First, try to find the binary directly
|
||||
if let Some(runtime) = build_binary_runtime(source, &root_dir) {
|
||||
return Some(runtime);
|
||||
@@ -242,7 +247,7 @@ fn build_staged_runtime(source: &str, root_dir: PathBuf) -> Option<OpenFangRunti
|
||||
build_staged_runtime_legacy(source, root_dir)
|
||||
}
|
||||
|
||||
fn push_staged_runtime_candidate(candidates: &mut Vec<OpenFangRuntime>, source: &str, root_dir: PathBuf) {
|
||||
fn push_staged_runtime_candidate(candidates: &mut Vec<ZclawRuntime>, source: &str, root_dir: PathBuf) {
|
||||
if candidates.iter().any(|candidate| candidate.display_path == root_dir) {
|
||||
return;
|
||||
}
|
||||
@@ -252,18 +257,18 @@ fn push_staged_runtime_candidate(candidates: &mut Vec<OpenFangRuntime>, source:
|
||||
}
|
||||
}
|
||||
|
||||
fn bundled_runtime_candidates(app: &AppHandle) -> Vec<OpenFangRuntime> {
|
||||
fn bundled_runtime_candidates(app: &AppHandle) -> Vec<ZclawRuntime> {
|
||||
let mut candidates = Vec::new();
|
||||
let sidecar_name = openfang_sidecar_filename();
|
||||
let plain_name = openfang_plain_filename();
|
||||
let sidecar_name = zclaw_sidecar_filename();
|
||||
let plain_name = zclaw_plain_filename();
|
||||
let platform_names = get_platform_binary_names();
|
||||
|
||||
if let Ok(resource_dir) = app.path().resource_dir() {
|
||||
// Primary: openfang-runtime directory (contains binary + manifest)
|
||||
// Primary: zclaw-runtime directory (contains binary + manifest)
|
||||
push_staged_runtime_candidate(
|
||||
&mut candidates,
|
||||
"bundled",
|
||||
resource_dir.join("openfang-runtime"),
|
||||
resource_dir.join("zclaw-runtime"),
|
||||
);
|
||||
|
||||
// Alternative: binaries directory
|
||||
@@ -286,7 +291,7 @@ fn bundled_runtime_candidates(app: &AppHandle) -> Vec<OpenFangRuntime> {
|
||||
push_staged_runtime_candidate(
|
||||
&mut candidates,
|
||||
"bundled",
|
||||
exe_dir.join("resources").join("openfang-runtime"),
|
||||
exe_dir.join("resources").join("zclaw-runtime"),
|
||||
);
|
||||
|
||||
// Alternative: binaries next to exe
|
||||
@@ -308,7 +313,7 @@ fn bundled_runtime_candidates(app: &AppHandle) -> Vec<OpenFangRuntime> {
|
||||
push_staged_runtime_candidate(
|
||||
&mut candidates,
|
||||
"development",
|
||||
manifest_dir.join("resources").join("openfang-runtime"),
|
||||
manifest_dir.join("resources").join("zclaw-runtime"),
|
||||
);
|
||||
|
||||
for name in &platform_names {
|
||||
@@ -322,10 +327,10 @@ fn bundled_runtime_candidates(app: &AppHandle) -> Vec<OpenFangRuntime> {
|
||||
candidates
|
||||
}
|
||||
|
||||
/// Resolve OpenFang runtime location
|
||||
/// Priority: ZCLAW_OPENFANG_BIN env > bundled > system PATH
|
||||
fn resolve_openfang_runtime(app: &AppHandle) -> OpenFangRuntime {
|
||||
if let Ok(override_path) = std::env::var("ZCLAW_OPENFANG_BIN") {
|
||||
/// Resolve ZCLAW runtime location
|
||||
/// Priority: ZCLAW_BIN env > bundled > system PATH
|
||||
fn resolve_zclaw_runtime(app: &AppHandle) -> ZclawRuntime {
|
||||
if let Ok(override_path) = std::env::var("ZCLAW_BIN") {
|
||||
let override_path = PathBuf::from(override_path);
|
||||
if override_path.is_dir() {
|
||||
if let Some(runtime) = build_staged_runtime("override", override_path.clone()) {
|
||||
@@ -333,7 +338,7 @@ fn resolve_openfang_runtime(app: &AppHandle) -> OpenFangRuntime {
|
||||
}
|
||||
}
|
||||
|
||||
return OpenFangRuntime {
|
||||
return ZclawRuntime {
|
||||
source: "override".to_string(),
|
||||
display_path: override_path.clone(),
|
||||
executable: override_path,
|
||||
@@ -348,27 +353,27 @@ fn resolve_openfang_runtime(app: &AppHandle) -> OpenFangRuntime {
|
||||
return runtime;
|
||||
}
|
||||
|
||||
OpenFangRuntime {
|
||||
ZclawRuntime {
|
||||
source: "system".to_string(),
|
||||
display_path: PathBuf::from("openfang"),
|
||||
executable: PathBuf::from("openfang"),
|
||||
display_path: PathBuf::from("zclaw"),
|
||||
executable: PathBuf::from("zclaw"),
|
||||
pre_args: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Resolve OpenFang config path (TOML format)
|
||||
/// Priority: OPENFANG_HOME env > ~/.openfang/
|
||||
fn resolve_openfang_config_path() -> Option<PathBuf> {
|
||||
if let Ok(value) = std::env::var("OPENFANG_HOME") {
|
||||
return Some(PathBuf::from(value).join("openfang.toml"));
|
||||
/// Resolve ZCLAW config path (TOML format)
|
||||
/// Priority: ZCLAW_HOME env > ~/.zclaw/
|
||||
fn resolve_zclaw_config_path() -> Option<PathBuf> {
|
||||
if let Ok(value) = std::env::var("ZCLAW_HOME") {
|
||||
return Some(PathBuf::from(value).join("zclaw.toml"));
|
||||
}
|
||||
|
||||
if let Ok(value) = std::env::var("HOME") {
|
||||
return Some(PathBuf::from(value).join(".openfang").join("openfang.toml"));
|
||||
return Some(PathBuf::from(value).join(".zclaw").join("zclaw.toml"));
|
||||
}
|
||||
|
||||
if let Ok(value) = std::env::var("USERPROFILE") {
|
||||
return Some(PathBuf::from(value).join(".openfang").join("openfang.toml"));
|
||||
return Some(PathBuf::from(value).join(".zclaw").join("zclaw.toml"));
|
||||
}
|
||||
|
||||
None
|
||||
@@ -376,10 +381,10 @@ fn resolve_openfang_config_path() -> Option<PathBuf> {
|
||||
|
||||
/// Parse TOML config and extract gateway token
|
||||
fn read_local_gateway_auth() -> Result<LocalGatewayAuth, String> {
|
||||
let config_path = resolve_openfang_config_path()
|
||||
.ok_or_else(|| "未找到 OpenFang 配置目录。".to_string())?;
|
||||
let config_path = resolve_zclaw_config_path()
|
||||
.ok_or_else(|| "未找到 ZCLAW 配置目录。".to_string())?;
|
||||
let config_text = fs::read_to_string(&config_path)
|
||||
.map_err(|error| format!("读取 OpenFang 配置失败: {error}"))?;
|
||||
.map_err(|error| format!("读取 ZCLAW 配置失败: {error}"))?;
|
||||
|
||||
// Parse TOML format - simple extraction for gateway.token
|
||||
let gateway_token = extract_toml_token(&config_text);
|
||||
@@ -419,7 +424,7 @@ fn extract_toml_token(config_text: &str) -> Option<String> {
|
||||
None
|
||||
}
|
||||
|
||||
/// Ensure Tauri origins are allowed in OpenFang config
|
||||
/// Ensure Tauri origins are allowed in ZCLAW config
|
||||
fn ensure_tauri_allowed_origins(config_text: &str) -> (String, bool) {
|
||||
let mut lines: Vec<String> = config_text.lines().map(|s| s.to_string()).collect();
|
||||
let mut changed = false;
|
||||
@@ -489,23 +494,23 @@ fn ensure_tauri_allowed_origins(config_text: &str) -> (String, bool) {
|
||||
}
|
||||
|
||||
fn ensure_local_gateway_ready_for_tauri(app: &AppHandle) -> Result<LocalGatewayPrepareResult, String> {
|
||||
let config_path = resolve_openfang_config_path()
|
||||
.ok_or_else(|| "未找到 OpenFang 配置目录。".to_string())?;
|
||||
let config_path = resolve_zclaw_config_path()
|
||||
.ok_or_else(|| "未找到 ZCLAW 配置目录。".to_string())?;
|
||||
let config_text = fs::read_to_string(&config_path)
|
||||
.map_err(|error| format!("读取 OpenFang 配置失败: {error}"))?;
|
||||
.map_err(|error| format!("读取 ZCLAW 配置失败: {error}"))?;
|
||||
|
||||
let (updated_config, origins_updated) = ensure_tauri_allowed_origins(&config_text);
|
||||
|
||||
if origins_updated {
|
||||
fs::write(&config_path, format!("{}\n", updated_config))
|
||||
.map_err(|error| format!("写入 OpenFang 配置失败: {error}"))?;
|
||||
.map_err(|error| format!("写入 ZCLAW 配置失败: {error}"))?;
|
||||
}
|
||||
|
||||
let mut gateway_restarted = false;
|
||||
if origins_updated {
|
||||
if let Ok(status) = read_gateway_status(app) {
|
||||
if status.port_status.as_deref() == Some("busy") || !status.listener_pids.is_empty() {
|
||||
run_openfang(app, &["gateway", "restart", "--json"])?;
|
||||
run_zclaw(app, &["gateway", "restart", "--json"])?;
|
||||
thread::sleep(Duration::from_millis(1200));
|
||||
gateway_restarted = true;
|
||||
}
|
||||
@@ -530,7 +535,7 @@ fn approve_local_device_pairing(
|
||||
.gateway_token
|
||||
.ok_or_else(|| "本地 Gateway token 不可用,无法自动批准设备配对。".to_string())?;
|
||||
|
||||
let devices_output = run_openfang(app, &["devices", "list", "--json"])?;
|
||||
let devices_output = run_zclaw(app, &["devices", "list", "--json"])?;
|
||||
let devices_json = parse_json_output(&devices_output.stdout)?;
|
||||
let pending = devices_json
|
||||
.get("pending")
|
||||
@@ -556,7 +561,7 @@ fn approve_local_device_pairing(
|
||||
.ok_or_else(|| "待批准设备缺少 requestId。".to_string())?
|
||||
.to_string();
|
||||
|
||||
// Use OpenFang default port 4200
|
||||
// Use ZCLAW default port 4200
|
||||
let gateway_url = url.unwrap_or("ws://127.0.0.1:4200").to_string();
|
||||
let args = vec![
|
||||
"devices".to_string(),
|
||||
@@ -569,7 +574,7 @@ fn approve_local_device_pairing(
|
||||
gateway_url,
|
||||
];
|
||||
let arg_refs = args.iter().map(|value| value.as_str()).collect::<Vec<_>>();
|
||||
run_openfang(app, &arg_refs)?;
|
||||
run_zclaw(app, &arg_refs)?;
|
||||
thread::sleep(Duration::from_millis(300));
|
||||
|
||||
Ok(LocalGatewayPairingApprovalResult {
|
||||
@@ -579,14 +584,14 @@ fn approve_local_device_pairing(
|
||||
})
|
||||
}
|
||||
|
||||
fn run_openfang(app: &AppHandle, args: &[&str]) -> Result<OpenFangCommandOutput, String> {
|
||||
let runtime = resolve_openfang_runtime(app);
|
||||
fn run_zclaw(app: &AppHandle, args: &[&str]) -> Result<ZclawCommandOutput, String> {
|
||||
let runtime = resolve_zclaw_runtime(app);
|
||||
let mut command = Command::new(&runtime.executable);
|
||||
command.args(&runtime.pre_args).args(args);
|
||||
let output = command.output().map_err(|error| command_error(&runtime, error))?;
|
||||
|
||||
if output.status.success() {
|
||||
Ok(OpenFangCommandOutput {
|
||||
Ok(ZclawCommandOutput {
|
||||
stdout: String::from_utf8_lossy(&output.stdout).trim().to_string(),
|
||||
runtime,
|
||||
})
|
||||
@@ -602,7 +607,7 @@ fn run_openfang(app: &AppHandle, args: &[&str]) -> Result<OpenFangCommandOutput,
|
||||
};
|
||||
|
||||
if message.is_empty() {
|
||||
Err(format!("OpenFang {:?} 执行失败: {}", args, output.status))
|
||||
Err(format!("ZCLAW {:?} 执行失败: {}", args, output.status))
|
||||
} else {
|
||||
Err(message)
|
||||
}
|
||||
@@ -623,7 +628,7 @@ fn parse_json_output(stdout: &str) -> Result<Value, String> {
|
||||
Err("Gateway 状态输出不包含可解析的 JSON。".to_string())
|
||||
}
|
||||
|
||||
fn unavailable_status(error: String, runtime: Option<&OpenFangRuntime>) -> LocalGatewayStatus {
|
||||
fn unavailable_status(error: String, runtime: Option<&ZclawRuntime>) -> LocalGatewayStatus {
|
||||
LocalGatewayStatus {
|
||||
supported: true,
|
||||
cli_available: false,
|
||||
@@ -642,7 +647,7 @@ fn unavailable_status(error: String, runtime: Option<&OpenFangRuntime>) -> Local
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_gateway_status(raw: Value, runtime: &OpenFangRuntime) -> LocalGatewayStatus {
|
||||
fn parse_gateway_status(raw: Value, runtime: &ZclawRuntime) -> LocalGatewayStatus {
|
||||
let listener_pids = raw
|
||||
.get("port")
|
||||
.and_then(|port| port.get("listeners"))
|
||||
@@ -688,7 +693,7 @@ fn parse_gateway_status(raw: Value, runtime: &OpenFangRuntime) -> LocalGatewaySt
|
||||
.and_then(|gateway| gateway.get("port"))
|
||||
.and_then(Value::as_u64)
|
||||
.and_then(|port| u16::try_from(port).ok())
|
||||
.or(Some(OPENFANG_DEFAULT_PORT)),
|
||||
.or(Some(ZCLAW_DEFAULT_PORT)),
|
||||
port_status: raw
|
||||
.get("port")
|
||||
.and_then(|port| port.get("status"))
|
||||
@@ -706,69 +711,69 @@ fn parse_gateway_status(raw: Value, runtime: &OpenFangRuntime) -> LocalGatewaySt
|
||||
}
|
||||
|
||||
fn read_gateway_status(app: &AppHandle) -> Result<LocalGatewayStatus, String> {
|
||||
match run_openfang(app, &["gateway", "status", "--json", "--no-probe"]) {
|
||||
match run_zclaw(app, &["gateway", "status", "--json", "--no-probe"]) {
|
||||
Ok(result) => {
|
||||
let raw = parse_json_output(&result.stdout)?;
|
||||
Ok(parse_gateway_status(raw, &result.runtime))
|
||||
}
|
||||
Err(error) => {
|
||||
let runtime = resolve_openfang_runtime(app);
|
||||
let runtime = resolve_zclaw_runtime(app);
|
||||
Ok(unavailable_status(error, Some(&runtime)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Tauri Commands - OpenFang (with backward-compatible aliases)
|
||||
// Tauri Commands - ZCLAW (with backward-compatible aliases)
|
||||
// ============================================================================
|
||||
|
||||
/// Get OpenFang Kernel status
|
||||
/// Get ZCLAW Kernel status
|
||||
#[tauri::command]
|
||||
fn openfang_status(app: AppHandle) -> Result<LocalGatewayStatus, String> {
|
||||
fn zclaw_status(app: AppHandle) -> Result<LocalGatewayStatus, String> {
|
||||
read_gateway_status(&app)
|
||||
}
|
||||
|
||||
/// Start OpenFang Kernel
|
||||
/// Start ZCLAW Kernel
|
||||
#[tauri::command]
|
||||
fn openfang_start(app: AppHandle) -> Result<LocalGatewayStatus, String> {
|
||||
fn zclaw_start(app: AppHandle) -> Result<LocalGatewayStatus, String> {
|
||||
ensure_local_gateway_ready_for_tauri(&app)?;
|
||||
run_openfang(&app, &["gateway", "start", "--json"])?;
|
||||
run_zclaw(&app, &["gateway", "start", "--json"])?;
|
||||
thread::sleep(Duration::from_millis(800));
|
||||
read_gateway_status(&app)
|
||||
}
|
||||
|
||||
/// Stop OpenFang Kernel
|
||||
/// Stop ZCLAW Kernel
|
||||
#[tauri::command]
|
||||
fn openfang_stop(app: AppHandle) -> Result<LocalGatewayStatus, String> {
|
||||
run_openfang(&app, &["gateway", "stop", "--json"])?;
|
||||
fn zclaw_stop(app: AppHandle) -> Result<LocalGatewayStatus, String> {
|
||||
run_zclaw(&app, &["gateway", "stop", "--json"])?;
|
||||
thread::sleep(Duration::from_millis(800));
|
||||
read_gateway_status(&app)
|
||||
}
|
||||
|
||||
/// Restart OpenFang Kernel
|
||||
/// Restart ZCLAW Kernel
|
||||
#[tauri::command]
|
||||
fn openfang_restart(app: AppHandle) -> Result<LocalGatewayStatus, String> {
|
||||
fn zclaw_restart(app: AppHandle) -> Result<LocalGatewayStatus, String> {
|
||||
ensure_local_gateway_ready_for_tauri(&app)?;
|
||||
run_openfang(&app, &["gateway", "restart", "--json"])?;
|
||||
run_zclaw(&app, &["gateway", "restart", "--json"])?;
|
||||
thread::sleep(Duration::from_millis(1200));
|
||||
read_gateway_status(&app)
|
||||
}
|
||||
|
||||
/// Get local auth token from OpenFang config
|
||||
/// Get local auth token from ZCLAW config
|
||||
#[tauri::command]
|
||||
fn openfang_local_auth() -> Result<LocalGatewayAuth, String> {
|
||||
fn zclaw_local_auth() -> Result<LocalGatewayAuth, String> {
|
||||
read_local_gateway_auth()
|
||||
}
|
||||
|
||||
/// Prepare OpenFang for Tauri (update allowed origins)
|
||||
/// Prepare ZCLAW for Tauri (update allowed origins)
|
||||
#[tauri::command]
|
||||
fn openfang_prepare_for_tauri(app: AppHandle) -> Result<LocalGatewayPrepareResult, String> {
|
||||
fn zclaw_prepare_for_tauri(app: AppHandle) -> Result<LocalGatewayPrepareResult, String> {
|
||||
ensure_local_gateway_ready_for_tauri(&app)
|
||||
}
|
||||
|
||||
/// Approve device pairing request
|
||||
#[tauri::command]
|
||||
fn openfang_approve_device_pairing(
|
||||
fn zclaw_approve_device_pairing(
|
||||
app: AppHandle,
|
||||
device_id: String,
|
||||
public_key_base64: String,
|
||||
@@ -777,10 +782,10 @@ fn openfang_approve_device_pairing(
|
||||
approve_local_device_pairing(&app, &device_id, &public_key_base64, url.as_deref())
|
||||
}
|
||||
|
||||
/// Run OpenFang doctor to diagnose issues
|
||||
/// Run ZCLAW doctor to diagnose issues
|
||||
#[tauri::command]
|
||||
fn openfang_doctor(app: AppHandle) -> Result<String, String> {
|
||||
let result = run_openfang(&app, &["doctor", "--json"])?;
|
||||
fn zclaw_doctor(app: AppHandle) -> Result<String, String> {
|
||||
let result = run_zclaw(&app, &["doctor", "--json"])?;
|
||||
Ok(result.stdout)
|
||||
}
|
||||
|
||||
@@ -830,10 +835,10 @@ struct VersionResponse {
|
||||
raw: Value,
|
||||
}
|
||||
|
||||
/// List OpenFang processes
|
||||
/// List ZCLAW processes
|
||||
#[tauri::command]
|
||||
fn openfang_process_list(app: AppHandle) -> Result<ProcessListResponse, String> {
|
||||
let result = run_openfang(&app, &["process", "list", "--json"])?;
|
||||
fn zclaw_process_list(app: AppHandle) -> Result<ProcessListResponse, String> {
|
||||
let result = run_zclaw(&app, &["process", "list", "--json"])?;
|
||||
|
||||
let raw = parse_json_output(&result.stdout).unwrap_or_else(|_| json!({"processes": []}));
|
||||
|
||||
@@ -867,9 +872,9 @@ fn openfang_process_list(app: AppHandle) -> Result<ProcessListResponse, String>
|
||||
})
|
||||
}
|
||||
|
||||
/// Get OpenFang process logs
|
||||
/// Get ZCLAW process logs
|
||||
#[tauri::command]
|
||||
fn openfang_process_logs(
|
||||
fn zclaw_process_logs(
|
||||
app: AppHandle,
|
||||
pid: Option<u32>,
|
||||
lines: Option<usize>,
|
||||
@@ -900,7 +905,7 @@ fn openfang_process_logs(
|
||||
|
||||
// Convert to &str for the command
|
||||
let args_refs: Vec<&str> = args.iter().map(|s| s.as_str()).collect();
|
||||
let result = run_openfang(&app, &args_refs)?;
|
||||
let result = run_zclaw(&app, &args_refs)?;
|
||||
|
||||
// Parse the logs - could be JSON array or plain text
|
||||
let logs = if let Ok(json) = parse_json_output(&result.stdout) {
|
||||
@@ -930,10 +935,10 @@ fn openfang_process_logs(
|
||||
})
|
||||
}
|
||||
|
||||
/// Get OpenFang version information
|
||||
/// Get ZCLAW version information
|
||||
#[tauri::command]
|
||||
fn openfang_version(app: AppHandle) -> Result<VersionResponse, String> {
|
||||
let result = run_openfang(&app, &["--version", "--json"])?;
|
||||
fn zclaw_version(app: AppHandle) -> Result<VersionResponse, String> {
|
||||
let result = run_zclaw(&app, &["--version", "--json"])?;
|
||||
|
||||
let raw = parse_json_output(&result.stdout).unwrap_or_else(|_| {
|
||||
// Fallback: try to parse plain text version output
|
||||
@@ -1071,14 +1076,14 @@ fn get_process_uptime(status: &LocalGatewayStatus) -> Option<u64> {
|
||||
.and_then(Value::as_u64)
|
||||
}
|
||||
|
||||
/// Perform comprehensive health check on OpenFang Kernel
|
||||
/// Perform comprehensive health check on ZCLAW Kernel
|
||||
#[tauri::command]
|
||||
fn openfang_health_check(
|
||||
fn zclaw_health_check(
|
||||
app: AppHandle,
|
||||
port: Option<u16>,
|
||||
timeout_ms: Option<u64>,
|
||||
) -> Result<HealthCheckResponse, String> {
|
||||
let check_port = port.unwrap_or(OPENFANG_DEFAULT_PORT);
|
||||
let check_port = port.unwrap_or(ZCLAW_DEFAULT_PORT);
|
||||
let timeout = timeout_ms.unwrap_or(3000);
|
||||
let mut checks_performed = Vec::new();
|
||||
let mut issues = Vec::new();
|
||||
@@ -1089,8 +1094,8 @@ fn openfang_health_check(
|
||||
.map(|d| d.as_secs())
|
||||
.unwrap_or(0);
|
||||
|
||||
// 1. Check if OpenFang CLI is available
|
||||
let runtime = resolve_openfang_runtime(&app);
|
||||
// 1. Check if ZCLAW CLI is available
|
||||
let runtime = resolve_zclaw_runtime(&app);
|
||||
let cli_available = runtime.executable.is_file();
|
||||
|
||||
if !cli_available {
|
||||
@@ -1108,12 +1113,12 @@ fn openfang_health_check(
|
||||
port: check_port,
|
||||
accessible: false,
|
||||
latency_ms: None,
|
||||
error: Some("OpenFang CLI not available".to_string()),
|
||||
error: Some("ZCLAW CLI not available".to_string()),
|
||||
},
|
||||
last_check_timestamp,
|
||||
checks_performed: vec!["cli_availability".to_string()],
|
||||
issues: vec![format!(
|
||||
"OpenFang runtime not found at: {}",
|
||||
"ZCLAW runtime not found at: {}",
|
||||
runtime.display_path.display()
|
||||
)],
|
||||
runtime_source: Some(runtime.source),
|
||||
@@ -1148,7 +1153,7 @@ fn openfang_health_check(
|
||||
let pid = gateway_status.listener_pids[0];
|
||||
|
||||
// Try to get detailed process info from process list
|
||||
let process_info = run_openfang(&app, &["process", "list", "--json"])
|
||||
let process_info = run_zclaw(&app, &["process", "list", "--json"])
|
||||
.ok()
|
||||
.and_then(|result| parse_json_output(&result.stdout).ok())
|
||||
.and_then(|json| json.get("processes").and_then(Value::as_array).cloned());
|
||||
@@ -1171,7 +1176,7 @@ fn openfang_health_check(
|
||||
|
||||
ProcessHealthDetails {
|
||||
pid: Some(pid),
|
||||
name: Some("openfang".to_string()),
|
||||
name: Some("zclaw".to_string()),
|
||||
status: Some(
|
||||
gateway_status
|
||||
.service_status
|
||||
@@ -1225,17 +1230,17 @@ fn openfang_health_check(
|
||||
})
|
||||
}
|
||||
|
||||
/// Quick ping to check if OpenFang is alive (lightweight check)
|
||||
/// Quick ping to check if ZCLAW is alive (lightweight check)
|
||||
#[tauri::command]
|
||||
fn openfang_ping(app: AppHandle) -> Result<bool, String> {
|
||||
let port_check = check_port_accessibility("127.0.0.1", OPENFANG_DEFAULT_PORT, 1000);
|
||||
fn zclaw_ping(app: AppHandle) -> Result<bool, String> {
|
||||
let port_check = check_port_accessibility("127.0.0.1", ZCLAW_DEFAULT_PORT, 1000);
|
||||
|
||||
if port_check.accessible {
|
||||
return Ok(true);
|
||||
}
|
||||
|
||||
// Fallback: check via status command
|
||||
match run_openfang(&app, &["gateway", "status", "--json", "--no-probe"]) {
|
||||
match run_zclaw(&app, &["gateway", "status", "--json", "--no-probe"]) {
|
||||
Ok(result) => {
|
||||
if let Ok(status) = parse_json_output(&result.stdout) {
|
||||
// Check if there are any listener PIDs
|
||||
@@ -1257,37 +1262,37 @@ fn openfang_ping(app: AppHandle) -> Result<bool, String> {
|
||||
|
||||
// ============================================================================
|
||||
// Backward-compatible aliases (OpenClaw naming)
|
||||
// These delegate to OpenFang commands for backward compatibility
|
||||
// These delegate to ZCLAW commands for backward compatibility
|
||||
// ============================================================================
|
||||
|
||||
#[tauri::command]
|
||||
fn gateway_status(app: AppHandle) -> Result<LocalGatewayStatus, String> {
|
||||
openfang_status(app)
|
||||
zclaw_status(app)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn gateway_start(app: AppHandle) -> Result<LocalGatewayStatus, String> {
|
||||
openfang_start(app)
|
||||
zclaw_start(app)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn gateway_stop(app: AppHandle) -> Result<LocalGatewayStatus, String> {
|
||||
openfang_stop(app)
|
||||
zclaw_stop(app)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn gateway_restart(app: AppHandle) -> Result<LocalGatewayStatus, String> {
|
||||
openfang_restart(app)
|
||||
zclaw_restart(app)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn gateway_local_auth() -> Result<LocalGatewayAuth, String> {
|
||||
openfang_local_auth()
|
||||
zclaw_local_auth()
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn gateway_prepare_for_tauri(app: AppHandle) -> Result<LocalGatewayPrepareResult, String> {
|
||||
openfang_prepare_for_tauri(app)
|
||||
zclaw_prepare_for_tauri(app)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
@@ -1297,12 +1302,12 @@ fn gateway_approve_device_pairing(
|
||||
public_key_base64: String,
|
||||
url: Option<String>,
|
||||
) -> Result<LocalGatewayPairingApprovalResult, String> {
|
||||
openfang_approve_device_pairing(app, device_id, public_key_base64, url)
|
||||
zclaw_approve_device_pairing(app, device_id, public_key_base64, url)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn gateway_doctor(app: AppHandle) -> Result<String, String> {
|
||||
openfang_doctor(app)
|
||||
zclaw_doctor(app)
|
||||
}
|
||||
|
||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||
@@ -1350,7 +1355,6 @@ pub fn run() {
|
||||
let heartbeat_state: intelligence::HeartbeatEngineState = std::sync::Arc::new(tokio::sync::Mutex::new(std::collections::HashMap::new()));
|
||||
let reflection_state: intelligence::ReflectionEngineState = std::sync::Arc::new(tokio::sync::Mutex::new(intelligence::ReflectionEngine::new(None)));
|
||||
let identity_state: intelligence::IdentityManagerState = std::sync::Arc::new(tokio::sync::Mutex::new(intelligence::AgentIdentityManager::new()));
|
||||
let persona_evolver_state: intelligence::PersonaEvolverStateHandle = std::sync::Arc::new(tokio::sync::Mutex::new(intelligence::PersonaEvolver::new(None)));
|
||||
|
||||
// Initialize internal ZCLAW Kernel state
|
||||
let kernel_state = kernel_commands::create_kernel_state();
|
||||
@@ -1365,7 +1369,6 @@ pub fn run() {
|
||||
.manage(heartbeat_state)
|
||||
.manage(reflection_state)
|
||||
.manage(identity_state)
|
||||
.manage(persona_evolver_state)
|
||||
.manage(kernel_state)
|
||||
.manage(pipeline_state)
|
||||
.invoke_handler(tauri::generate_handler![
|
||||
@@ -1386,6 +1389,11 @@ pub fn run() {
|
||||
// Hands commands (autonomous capabilities)
|
||||
kernel_commands::hand_list,
|
||||
kernel_commands::hand_execute,
|
||||
kernel_commands::hand_approve,
|
||||
kernel_commands::hand_cancel,
|
||||
// Scheduled task commands
|
||||
kernel_commands::scheduled_task_create,
|
||||
kernel_commands::scheduled_task_list,
|
||||
// Pipeline commands (DSL-based workflows)
|
||||
pipeline_commands::pipeline_list,
|
||||
pipeline_commands::pipeline_get,
|
||||
@@ -1397,22 +1405,22 @@ pub fn run() {
|
||||
pipeline_commands::pipeline_refresh,
|
||||
pipeline_commands::route_intent,
|
||||
pipeline_commands::analyze_presentation,
|
||||
// OpenFang commands (new naming)
|
||||
openfang_status,
|
||||
openfang_start,
|
||||
openfang_stop,
|
||||
openfang_restart,
|
||||
openfang_local_auth,
|
||||
openfang_prepare_for_tauri,
|
||||
openfang_approve_device_pairing,
|
||||
openfang_doctor,
|
||||
openfang_health_check,
|
||||
// ZCLAW commands (new naming)
|
||||
zclaw_status,
|
||||
zclaw_start,
|
||||
zclaw_stop,
|
||||
zclaw_restart,
|
||||
zclaw_local_auth,
|
||||
zclaw_prepare_for_tauri,
|
||||
zclaw_approve_device_pairing,
|
||||
zclaw_doctor,
|
||||
zclaw_health_check,
|
||||
// Process monitoring commands
|
||||
openfang_process_list,
|
||||
openfang_process_logs,
|
||||
openfang_version,
|
||||
zclaw_process_list,
|
||||
zclaw_process_logs,
|
||||
zclaw_version,
|
||||
// Health check commands
|
||||
openfang_ping,
|
||||
zclaw_ping,
|
||||
// Backward-compatible aliases (OpenClaw naming)
|
||||
gateway_status,
|
||||
gateway_start,
|
||||
@@ -1433,6 +1441,9 @@ pub fn run() {
|
||||
viking_commands::viking_remove,
|
||||
viking_commands::viking_tree,
|
||||
viking_commands::viking_inject_prompt,
|
||||
viking_commands::viking_configure_embedding,
|
||||
viking_commands::viking_configure_summary_driver,
|
||||
viking_commands::viking_store_with_summaries,
|
||||
// Memory extraction commands (supplement CLI)
|
||||
memory::extractor::extract_session_memories,
|
||||
memory::extractor::extract_and_store_memories,
|
||||
@@ -1491,6 +1502,9 @@ pub fn run() {
|
||||
memory_commands::memory_export,
|
||||
memory_commands::memory_import,
|
||||
memory_commands::memory_db_path,
|
||||
memory_commands::memory_configure_embedding,
|
||||
memory_commands::memory_is_embedding_configured,
|
||||
memory_commands::memory_build_context,
|
||||
// Intelligence Layer commands (Phase 2-3)
|
||||
// Heartbeat Engine
|
||||
intelligence::heartbeat::heartbeat_init,
|
||||
@@ -1508,6 +1522,7 @@ pub fn run() {
|
||||
intelligence::compactor::compactor_estimate_messages_tokens,
|
||||
intelligence::compactor::compactor_check_threshold,
|
||||
intelligence::compactor::compactor_compact,
|
||||
intelligence::compactor::compactor_compact_llm,
|
||||
// Reflection Engine
|
||||
intelligence::reflection::reflection_init,
|
||||
intelligence::reflection::reflection_record_conversation,
|
||||
@@ -1529,24 +1544,7 @@ pub fn run() {
|
||||
intelligence::identity::identity_get_snapshots,
|
||||
intelligence::identity::identity_restore_snapshot,
|
||||
intelligence::identity::identity_list_agents,
|
||||
intelligence::identity::identity_delete_agent,
|
||||
// Adaptive Intelligence Mesh (Phase 4)
|
||||
intelligence::mesh::mesh_init,
|
||||
intelligence::mesh::mesh_analyze,
|
||||
intelligence::mesh::mesh_record_activity,
|
||||
intelligence::mesh::mesh_get_patterns,
|
||||
intelligence::mesh::mesh_update_config,
|
||||
intelligence::mesh::mesh_decay_patterns,
|
||||
intelligence::mesh::mesh_accept_recommendation,
|
||||
intelligence::mesh::mesh_dismiss_recommendation,
|
||||
// Persona Evolver (Phase 4)
|
||||
intelligence::persona_evolver::persona_evolver_init,
|
||||
intelligence::persona_evolver::persona_evolve,
|
||||
intelligence::persona_evolver::persona_evolution_history,
|
||||
intelligence::persona_evolver::persona_evolver_state,
|
||||
intelligence::persona_evolver::persona_evolver_config,
|
||||
intelligence::persona_evolver::persona_evolver_update_config,
|
||||
intelligence::persona_evolver::persona_apply_proposal
|
||||
intelligence::identity::identity_delete_agent
|
||||
])
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
|
||||
Reference in New Issue
Block a user