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
- Enable multi-agent feature by default in desktop build - Add butler delegation logic: task decomposition, expert assignment - Add ExpertTask, DelegationResult, butler_delegate() to Director - Add butler_delegate_task Tauri command bridging Director to frontend - 13 Director tests passing (6 original + 7 new butler tests) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
370 lines
17 KiB
Rust
370 lines
17 KiB
Rust
// ZCLAW Kernel integration for ZClaw desktop app
|
|
// Supports ZCLAW Kernel (successor to OpenClaw Gateway)
|
|
// - Port: 4200 (was 18789)
|
|
// - 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;
|
|
mod llm;
|
|
|
|
// Browser automation module (Fantoccini-based Browser Hand)
|
|
mod browser;
|
|
|
|
// Secure storage module for OS keyring/keychain
|
|
mod secure_storage;
|
|
|
|
// Memory commands for persistent storage
|
|
mod memory_commands;
|
|
|
|
// Intelligence Layer (migrated from frontend lib/)
|
|
mod intelligence;
|
|
|
|
// 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)
|
|
mod pipeline_commands;
|
|
|
|
// Classroom generation and interaction commands
|
|
mod classroom_commands;
|
|
|
|
// Gateway sub-modules (runtime, config, io, commands)
|
|
mod gateway;
|
|
|
|
// Health check commands (top-level module)
|
|
mod health_check;
|
|
|
|
// Development server (optional, for web debugging)
|
|
#[cfg(feature = "dev-server")]
|
|
mod dev_server;
|
|
|
|
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
|
pub fn run() {
|
|
// Start development server when dev-server feature is enabled
|
|
#[cfg(feature = "dev-server")]
|
|
{
|
|
std::thread::spawn(|| {
|
|
let rt = tokio::runtime::Runtime::new().expect("Failed to create tokio runtime for dev server");
|
|
rt.block_on(async {
|
|
match dev_server::start_dev_server().await {
|
|
Ok((_state, _handle)) => {
|
|
tracing::info!("[DevServer] Development server started on port {}", dev_server::DEV_SERVER_PORT);
|
|
}
|
|
Err(e) => {
|
|
tracing::error!("[DevServer] Failed to start: {}", e);
|
|
}
|
|
}
|
|
std::future::pending::<()>().await;
|
|
});
|
|
});
|
|
}
|
|
|
|
// Initialize Viking storage (async, in background)
|
|
let runtime = match tokio::runtime::Runtime::new() {
|
|
Ok(rt) => rt,
|
|
Err(e) => {
|
|
tracing::error!("[VikingCommands] Failed to create tokio runtime: {}", e);
|
|
return;
|
|
}
|
|
};
|
|
runtime.block_on(async {
|
|
if let Err(e) = crate::viking_commands::init_storage().await {
|
|
tracing::error!("[VikingCommands] Failed to initialize storage: {}", e);
|
|
}
|
|
});
|
|
|
|
// Initialize browser state
|
|
let browser_state = browser::commands::BrowserState::new();
|
|
|
|
// Initialize memory store state
|
|
let memory_state: memory_commands::MemoryStoreState = std::sync::Arc::new(tokio::sync::Mutex::new(None));
|
|
|
|
// Initialize intelligence layer state
|
|
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()));
|
|
|
|
// Initialize internal ZCLAW Kernel state
|
|
let kernel_state = kernel_commands::create_kernel_state();
|
|
|
|
// Initialize Scheduler state (for automatic trigger execution)
|
|
let scheduler_state = kernel_commands::create_scheduler_state();
|
|
|
|
// Initialize Pipeline state (DSL-based workflows)
|
|
let pipeline_state = pipeline_commands::create_pipeline_state();
|
|
|
|
// Initialize Classroom state (generation + chat)
|
|
let classroom_state = classroom_commands::create_classroom_state();
|
|
let classroom_chat_state = classroom_commands::chat::create_chat_state();
|
|
let classroom_gen_tasks = classroom_commands::create_generation_tasks();
|
|
|
|
tauri::Builder::default()
|
|
.plugin(tauri_plugin_opener::init())
|
|
.manage(browser_state)
|
|
.manage(memory_state)
|
|
.manage(heartbeat_state)
|
|
.manage(reflection_state)
|
|
.manage(identity_state)
|
|
.manage(kernel_state)
|
|
.manage(scheduler_state)
|
|
.manage(kernel_commands::SessionStreamGuard::default())
|
|
.manage(kernel_commands::StreamCancelFlags::default())
|
|
.manage(pipeline_state)
|
|
.manage(classroom_state)
|
|
.manage(classroom_chat_state)
|
|
.manage(classroom_gen_tasks)
|
|
.manage(kernel_commands::mcp::McpManagerState::default())
|
|
.setup(|app| {
|
|
// Initialize classroom persistence (async SQLite + data loading).
|
|
// Must complete before the event loop starts so that classroom
|
|
// commands have a valid persistence layer available.
|
|
use tauri::Manager;
|
|
let classroom_store = app.state::<classroom_commands::ClassroomStore>().inner().clone();
|
|
let chat_store = app.state::<classroom_commands::ChatStore>().inner().clone();
|
|
let handle = app.handle().clone();
|
|
|
|
let rt = tokio::runtime::Runtime::new()
|
|
.expect("Failed to create runtime for classroom persistence init");
|
|
|
|
let persistence = rt.block_on(
|
|
classroom_commands::init_persistence(&handle, &classroom_store, &chat_store)
|
|
).unwrap_or_else(|e| {
|
|
tracing::error!("[Classroom] Persistence init failed: {}, using in-memory fallback", e);
|
|
rt.block_on(classroom_commands::persist::ClassroomPersistence::open_in_memory())
|
|
.expect("In-memory SQLite should never fail")
|
|
});
|
|
app.manage(persistence);
|
|
Ok(())
|
|
})
|
|
.invoke_handler(tauri::generate_handler![
|
|
// Internal ZCLAW Kernel commands (preferred)
|
|
kernel_commands::lifecycle::kernel_init,
|
|
kernel_commands::lifecycle::kernel_status,
|
|
kernel_commands::lifecycle::kernel_shutdown,
|
|
kernel_commands::lifecycle::kernel_apply_saas_config,
|
|
kernel_commands::agent::agent_create,
|
|
kernel_commands::agent::agent_list,
|
|
kernel_commands::agent::agent_get,
|
|
kernel_commands::agent::agent_delete,
|
|
kernel_commands::agent::agent_update,
|
|
kernel_commands::agent::agent_export,
|
|
kernel_commands::agent::agent_import,
|
|
kernel_commands::chat::agent_chat,
|
|
kernel_commands::chat::agent_chat_stream,
|
|
kernel_commands::chat::cancel_stream,
|
|
// Skills commands (dynamic discovery)
|
|
kernel_commands::skill::skill_list,
|
|
kernel_commands::skill::skill_refresh,
|
|
kernel_commands::skill::skill_execute,
|
|
kernel_commands::skill::skill_create,
|
|
kernel_commands::skill::skill_update,
|
|
kernel_commands::skill::skill_delete,
|
|
// Orchestration commands (multi-skill graphs)
|
|
kernel_commands::orchestration::orchestration_execute,
|
|
kernel_commands::orchestration::orchestration_validate,
|
|
// Hands commands (autonomous capabilities)
|
|
kernel_commands::hand::hand_list,
|
|
kernel_commands::hand::hand_execute,
|
|
kernel_commands::hand::hand_approve,
|
|
kernel_commands::hand::hand_cancel,
|
|
kernel_commands::hand::hand_get,
|
|
kernel_commands::hand::hand_run_status,
|
|
kernel_commands::hand::hand_run_list,
|
|
kernel_commands::hand::hand_run_cancel,
|
|
// Scheduled task commands
|
|
kernel_commands::scheduled_task::scheduled_task_create,
|
|
kernel_commands::scheduled_task::scheduled_task_list,
|
|
|
|
// A2A commands gated behind multi-agent feature
|
|
#[cfg(feature = "multi-agent")]
|
|
kernel_commands::a2a::agent_a2a_send,
|
|
#[cfg(feature = "multi-agent")]
|
|
kernel_commands::a2a::agent_a2a_broadcast,
|
|
#[cfg(feature = "multi-agent")]
|
|
kernel_commands::a2a::agent_a2a_discover,
|
|
#[cfg(feature = "multi-agent")]
|
|
kernel_commands::a2a::agent_a2a_delegate_task,
|
|
#[cfg(feature = "multi-agent")]
|
|
kernel_commands::a2a::butler_delegate_task,
|
|
|
|
// Pipeline commands (DSL-based workflows)
|
|
pipeline_commands::discovery::pipeline_list,
|
|
pipeline_commands::discovery::pipeline_get,
|
|
pipeline_commands::discovery::pipeline_run,
|
|
pipeline_commands::discovery::pipeline_progress,
|
|
pipeline_commands::discovery::pipeline_cancel,
|
|
pipeline_commands::discovery::pipeline_result,
|
|
pipeline_commands::discovery::pipeline_runs,
|
|
pipeline_commands::discovery::pipeline_refresh,
|
|
pipeline_commands::crud::pipeline_create,
|
|
pipeline_commands::crud::pipeline_update,
|
|
pipeline_commands::crud::pipeline_delete,
|
|
pipeline_commands::intent_router::route_intent,
|
|
pipeline_commands::presentation::analyze_presentation,
|
|
pipeline_commands::presentation::pipeline_templates,
|
|
// ZCLAW gateway commands
|
|
gateway::commands::zclaw_status,
|
|
gateway::commands::zclaw_start,
|
|
gateway::commands::zclaw_stop,
|
|
gateway::commands::zclaw_restart,
|
|
gateway::commands::zclaw_local_auth,
|
|
gateway::commands::zclaw_prepare_for_tauri,
|
|
gateway::commands::zclaw_approve_device_pairing,
|
|
gateway::commands::zclaw_doctor,
|
|
// Health check commands
|
|
health_check::zclaw_health_check,
|
|
// Process monitoring commands
|
|
gateway::commands::zclaw_process_list,
|
|
gateway::commands::zclaw_process_logs,
|
|
gateway::commands::zclaw_version,
|
|
// Health check commands
|
|
health_check::zclaw_ping,
|
|
// OpenViking CLI sidecar commands
|
|
viking_commands::viking_status,
|
|
viking_commands::viking_add,
|
|
viking_commands::viking_add_with_metadata,
|
|
viking_commands::viking_find,
|
|
viking_commands::viking_grep,
|
|
viking_commands::viking_ls,
|
|
viking_commands::viking_read,
|
|
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,
|
|
memory::context_builder::estimate_content_tokens,
|
|
// LLM commands (for extraction)
|
|
llm::llm_complete,
|
|
llm::embedding_create,
|
|
llm::embedding_providers,
|
|
// Browser automation commands (Fantoccini-based Browser Hand)
|
|
browser::commands::browser_create_session,
|
|
browser::commands::browser_close_session,
|
|
browser::commands::browser_list_sessions,
|
|
browser::commands::browser_get_session,
|
|
browser::commands::browser_navigate,
|
|
browser::commands::browser_back,
|
|
browser::commands::browser_forward,
|
|
browser::commands::browser_refresh,
|
|
browser::commands::browser_get_url,
|
|
browser::commands::browser_get_title,
|
|
browser::commands::browser_find_element,
|
|
browser::commands::browser_find_elements,
|
|
browser::commands::browser_click,
|
|
browser::commands::browser_type,
|
|
browser::commands::browser_get_text,
|
|
browser::commands::browser_get_attribute,
|
|
browser::commands::browser_wait_for_element,
|
|
browser::commands::browser_execute_script,
|
|
browser::commands::browser_screenshot,
|
|
browser::commands::browser_element_screenshot,
|
|
browser::commands::browser_get_source,
|
|
browser::commands::browser_scrape_page,
|
|
browser::commands::browser_fill_form,
|
|
// Secure storage commands (OS keyring/keychain)
|
|
secure_storage::secure_store_set,
|
|
secure_storage::secure_store_get,
|
|
secure_storage::secure_store_delete,
|
|
secure_storage::secure_store_is_available,
|
|
// Memory persistence commands (Phase 1 Intelligence Layer Migration)
|
|
memory_commands::memory_init,
|
|
memory_commands::memory_store,
|
|
memory_commands::memory_get,
|
|
memory_commands::memory_search,
|
|
memory_commands::memory_delete,
|
|
// Trigger management commands
|
|
kernel_commands::trigger::trigger_list,
|
|
kernel_commands::trigger::trigger_get,
|
|
kernel_commands::trigger::trigger_create,
|
|
kernel_commands::trigger::trigger_update,
|
|
kernel_commands::trigger::trigger_delete,
|
|
kernel_commands::trigger::trigger_execute,
|
|
// Approval management commands
|
|
kernel_commands::approval::approval_list,
|
|
kernel_commands::approval::approval_respond,
|
|
memory_commands::memory_delete_all,
|
|
memory_commands::memory_stats,
|
|
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,
|
|
intelligence::heartbeat::heartbeat_start,
|
|
intelligence::heartbeat::heartbeat_stop,
|
|
intelligence::heartbeat::heartbeat_tick,
|
|
intelligence::heartbeat::heartbeat_get_config,
|
|
intelligence::heartbeat::heartbeat_update_config,
|
|
intelligence::heartbeat::heartbeat_get_history,
|
|
intelligence::heartbeat::heartbeat_update_memory_stats,
|
|
intelligence::heartbeat::heartbeat_record_correction,
|
|
intelligence::heartbeat::heartbeat_record_interaction,
|
|
// Context Compactor
|
|
intelligence::compactor::compactor_estimate_tokens,
|
|
intelligence::compactor::compactor_estimate_messages_tokens,
|
|
intelligence::compactor::compactor_check_threshold,
|
|
intelligence::compactor::compactor_compact,
|
|
// compactor_compact_llm removed: redundant with runtime maybe_compact_with_config()
|
|
// Reflection Engine
|
|
intelligence::reflection::reflection_init,
|
|
intelligence::reflection::reflection_record_conversation,
|
|
intelligence::reflection::reflection_should_reflect,
|
|
intelligence::reflection::reflection_reflect,
|
|
intelligence::reflection::reflection_get_history,
|
|
intelligence::reflection::reflection_get_state,
|
|
// Agent Identity Manager
|
|
intelligence::identity::identity_get,
|
|
intelligence::identity::identity_get_file,
|
|
intelligence::identity::identity_build_prompt,
|
|
intelligence::identity::identity_update_user_profile,
|
|
intelligence::identity::identity_append_user_profile,
|
|
intelligence::identity::identity_propose_change,
|
|
intelligence::identity::identity_approve_proposal,
|
|
intelligence::identity::identity_reject_proposal,
|
|
intelligence::identity::identity_get_pending_proposals,
|
|
intelligence::identity::identity_update_file,
|
|
intelligence::identity::identity_get_snapshots,
|
|
intelligence::identity::identity_restore_snapshot,
|
|
intelligence::identity::identity_list_agents,
|
|
intelligence::identity::identity_delete_agent,
|
|
// Classroom generation and interaction commands
|
|
classroom_commands::generate::classroom_generate,
|
|
classroom_commands::generate::classroom_generation_progress,
|
|
classroom_commands::generate::classroom_cancel_generation,
|
|
classroom_commands::generate::classroom_get,
|
|
classroom_commands::generate::classroom_list,
|
|
classroom_commands::chat::classroom_chat,
|
|
classroom_commands::chat::classroom_chat_history,
|
|
classroom_commands::export::classroom_export,
|
|
// MCP (Model Context Protocol) lifecycle commands
|
|
kernel_commands::mcp::mcp_start_service,
|
|
kernel_commands::mcp::mcp_stop_service,
|
|
kernel_commands::mcp::mcp_list_services,
|
|
kernel_commands::mcp::mcp_call_tool,
|
|
// Butler commands
|
|
intelligence::pain_aggregator::butler_list_pain_points,
|
|
intelligence::pain_aggregator::butler_record_pain_point,
|
|
intelligence::pain_aggregator::butler_generate_solution,
|
|
intelligence::pain_aggregator::butler_list_proposals,
|
|
intelligence::pain_aggregator::butler_update_proposal_status,
|
|
])
|
|
.run(tauri::generate_context!())
|
|
.expect("error while running tauri application");
|
|
}
|