feat(kernel): add internal ZCLAW kernel integration with Tauri

Phase 1-3 of independence architecture:
- zclaw-types: Add ToolDefinition, ToolResult, KernelConfig, ModelConfig
- zclaw-kernel: Fix AgentInfo provider field, export config module
- desktop: Add kernel_commands for internal kernel access
- Add AgentId FromStr implementation for parsing

New Tauri commands:
- kernel_init, kernel_status, kernel_shutdown
- agent_create, agent_list, agent_get, agent_delete
- agent_chat

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
iven
2026-03-22 08:37:20 +08:00
parent 185763868a
commit 7abfca9d5c
6 changed files with 618 additions and 0 deletions

View File

@@ -0,0 +1,15 @@
//! ZCLAW Kernel
//!
//! Central coordinator for all ZCLAW subsystems.
mod kernel;
mod registry;
mod capabilities;
mod events;
pub mod config;
pub use kernel::*;
pub use registry::*;
pub use capabilities::*;
pub use events::*;
pub use config::*;

View File

@@ -0,0 +1,92 @@
//! Agent registry
use dashmap::DashMap;
use zclaw_types::{AgentConfig, AgentId, AgentInfo, AgentState};
use chrono::Utc;
/// In-memory registry of active agents
pub struct AgentRegistry {
agents: DashMap<AgentId, AgentConfig>,
states: DashMap<AgentId, AgentState>,
created_at: DashMap<AgentId, chrono::DateTime<Utc>>,
}
impl AgentRegistry {
pub fn new() -> Self {
Self {
agents: DashMap::new(),
states: DashMap::new(),
created_at: DashMap::new(),
}
}
/// Register an agent
pub fn register(&self, config: AgentConfig) {
let id = config.id;
self.agents.insert(id, config);
self.states.insert(id, AgentState::Running);
self.created_at.insert(id, Utc::now());
}
/// Unregister an agent
pub fn unregister(&self, id: &AgentId) {
self.agents.remove(id);
self.states.remove(id);
self.created_at.remove(id);
}
/// Get an agent by ID
pub fn get(&self, id: &AgentId) -> Option<AgentConfig> {
self.agents.get(id).map(|r| r.clone())
}
/// Get agent info
pub fn get_info(&self, id: &AgentId) -> Option<AgentInfo> {
let config = self.agents.get(id)?;
let state = self.states.get(id).map(|s| *s).unwrap_or(AgentState::Terminated);
let created_at = self.created_at.get(id).map(|t| *t).unwrap_or_else(Utc::now);
Some(AgentInfo {
id: *id,
name: config.name.clone(),
description: config.description.clone(),
model: config.model.model.clone(),
provider: config.model.provider.clone(),
state,
message_count: 0, // TODO: Track this
created_at,
updated_at: Utc::now(),
})
}
/// List all agents
pub fn list(&self) -> Vec<AgentInfo> {
self.agents.iter()
.filter_map(|entry| {
let id = entry.key();
self.get_info(id)
})
.collect()
}
/// Update agent state
pub fn set_state(&self, id: &AgentId, state: AgentState) {
self.states.insert(*id, state);
}
/// Get agent state
pub fn get_state(&self, id: &AgentId) -> AgentState {
self.states.get(id).map(|s| *s).unwrap_or(AgentState::Terminated)
}
/// Count active agents
pub fn count(&self) -> usize {
self.agents.len()
}
}
impl Default for AgentRegistry {
fn default() -> Self {
Self::new()
}
}