refactor(crates): kernel/generation module split + DeerFlow optimizations + middleware + dead code cleanup
- Split zclaw-kernel/kernel.rs (1486 lines) into 9 domain modules - Split zclaw-kernel/generation.rs (1080 lines) into 3 modules - Add DeerFlow-inspired middleware: DanglingTool, SubagentLimit, ToolError, ToolOutputGuard - Add PromptBuilder for structured system prompt assembly - Add FactStore (zclaw-memory) for persistent fact extraction - Add task builtin tool for agent task management - Driver improvements: Anthropic/OpenAI extended thinking, Gemini safety settings - Replace let _ = with proper log::warn! across SaaS handlers - Remove unused dependency (url) from zclaw-hands
This commit is contained in:
@@ -20,6 +20,9 @@ pub struct AgentConfig {
|
||||
/// System prompt
|
||||
#[serde(default)]
|
||||
pub system_prompt: Option<String>,
|
||||
/// Custom agent personality (SOUL.md equivalent from DeerFlow)
|
||||
#[serde(default)]
|
||||
pub soul: Option<String>,
|
||||
/// Capabilities granted to this agent
|
||||
#[serde(default)]
|
||||
pub capabilities: Vec<Capability>,
|
||||
@@ -56,6 +59,7 @@ impl Default for AgentConfig {
|
||||
description: None,
|
||||
model: ModelConfig::default(),
|
||||
system_prompt: None,
|
||||
soul: None,
|
||||
capabilities: Vec::new(),
|
||||
tools: Vec::new(),
|
||||
max_tokens: None,
|
||||
@@ -91,6 +95,11 @@ impl AgentConfig {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_soul(mut self, soul: impl Into<String>) -> Self {
|
||||
self.soul = Some(soul.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_model(mut self, model: ModelConfig) -> Self {
|
||||
self.model = model;
|
||||
self
|
||||
|
||||
@@ -24,6 +24,8 @@ pub enum Capability {
|
||||
AgentMessage { pattern: String },
|
||||
/// Kill agents matching pattern
|
||||
AgentKill { pattern: String },
|
||||
/// OpenFang Protocol capabilities (reserved for future A2A mesh networking).
|
||||
/// Currently defined but not consumed - no implementation or grant path exists.
|
||||
/// Discover remote peers via OFP
|
||||
OfpDiscover,
|
||||
/// Connect to specific OFP peers
|
||||
@@ -58,7 +60,16 @@ impl Capability {
|
||||
match self {
|
||||
Capability::ToolAll => true,
|
||||
Capability::ToolInvoke { name } => name == tool_name,
|
||||
_ => false,
|
||||
Capability::MemoryRead { .. }
|
||||
| Capability::MemoryWrite { .. }
|
||||
| Capability::NetConnect { .. }
|
||||
| Capability::ShellExec { .. }
|
||||
| Capability::AgentSpawn
|
||||
| Capability::AgentMessage { .. }
|
||||
| Capability::AgentKill { .. }
|
||||
| Capability::OfpDiscover
|
||||
| Capability::OfpConnect { .. }
|
||||
| Capability::OfpAdvertise => false,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,7 +79,17 @@ impl Capability {
|
||||
Capability::MemoryRead { scope: s } => {
|
||||
s == "*" || s == scope || scope.starts_with(&format!("{}.", s))
|
||||
}
|
||||
_ => false,
|
||||
Capability::ToolAll
|
||||
| Capability::ToolInvoke { .. }
|
||||
| Capability::MemoryWrite { .. }
|
||||
| Capability::NetConnect { .. }
|
||||
| Capability::ShellExec { .. }
|
||||
| Capability::AgentSpawn
|
||||
| Capability::AgentMessage { .. }
|
||||
| Capability::AgentKill { .. }
|
||||
| Capability::OfpDiscover
|
||||
| Capability::OfpConnect { .. }
|
||||
| Capability::OfpAdvertise => false,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,7 +99,17 @@ impl Capability {
|
||||
Capability::MemoryWrite { scope: s } => {
|
||||
s == "*" || s == scope || scope.starts_with(&format!("{}.", s))
|
||||
}
|
||||
_ => false,
|
||||
Capability::ToolAll
|
||||
| Capability::ToolInvoke { .. }
|
||||
| Capability::MemoryRead { .. }
|
||||
| Capability::NetConnect { .. }
|
||||
| Capability::ShellExec { .. }
|
||||
| Capability::AgentSpawn
|
||||
| Capability::AgentMessage { .. }
|
||||
| Capability::AgentKill { .. }
|
||||
| Capability::OfpDiscover
|
||||
| Capability::OfpConnect { .. }
|
||||
| Capability::OfpAdvertise => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -152,6 +183,10 @@ impl Capability {
|
||||
(Capability::NetConnect { host: a }, Capability::NetConnect { host: b }) => {
|
||||
a == "*" || a == b
|
||||
}
|
||||
// Exhaustive fallback: all remaining (self, other) combinations
|
||||
// return false. Kept as wildcard because enumerating 12×12
|
||||
// combinations is impractical; new variants should add explicit
|
||||
// arms above when they introduce new grant rules.
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,7 +114,10 @@ impl Message {
|
||||
}
|
||||
}
|
||||
|
||||
/// Content block for structured responses
|
||||
/// Canonical LLM message content block. Used for agent conversation messages.
|
||||
/// See also: zclaw_runtime::driver::ContentBlock (LLM driver response subset),
|
||||
/// zclaw_hands::slideshow::ContentBlock (presentation rendering),
|
||||
/// zclaw_protocols::mcp_types::ContentBlock (MCP protocol wire format).
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[serde(tag = "type", rename_all = "snake_case")]
|
||||
pub enum ContentBlock {
|
||||
|
||||
Reference in New Issue
Block a user