# ZCLAW 项目深度分析与创新头脑风暴 ## 一、项目概览 ### 1.1 核心指标 | 维度 | 数据 | |------|------| | Rust Crates | 9 个 (L1-L5 分层) | | 前端 TypeScript | ~25,000 行 | | 后端 Rust | ~12,000 行 | | Zustand Store | 16+ | | Tauri 命令 | 100+ | | SKILL.md 技能 | 69 个 | | Hands 自主能力 | 9/11 (82%) | | Pipeline 模板 | 5 类 | | LLM Provider | 8 个 | ### 1.2 架构成熟度 **整体: L4 (生产级)** | 系统层 | 成熟度 | 说明 | |--------|--------|------| | 通信层 | L4 | Tauri IPC + WebSocket 双模式 | | 状态管理 | L4 | 16+ Zustand Store | | 智能层 | L4 | 6 个核心组件全部实现 | | Skills | L4 | 69 技能 + 注册执行 | | Hands | L4 | 9/11 实现 | | Pipeline | L4 | DSL 解析 + 执行引擎 | --- ## 二、分层架构 ``` ┌─────────────────────────────────────────────────────────────────┐ │ ZCLAW 桌面应用 (Tauri 2.x) │ ├─────────────────────────────────────────────────────────────────┤ │ 前端层 (React 18 + TypeScript + Zustand) │ │ ↓ KernelClient (Tauri invoke) │ ├─────────────────────────────────────────────────────────────────┤ │ 后端层 (Rust Workspace) │ │ zclaw-kernel (L4: 核心协调) │ │ ↓ │ │ ┌───────────┬───────────┬───────────┐ │ │ │zclaw- │zclaw- │zclaw- │ │ │ │runtime │skills │hands │ │ │ │(LLM驱动) │(69技能) │(9个Hand) │ │ │ └───────────┴───────────┴───────────┘ │ │ ↑ │ │ zclaw-memory (L2: SQLite存储) │ │ ↑ │ │ zclaw-types (L1: 基础类型) │ └─────────────────────────────────────────────────────────────────┘ ``` --- ## 三、核心系统能力 ### 3.1 Pipeline DSL 系统 **5 类工作流模板:** | 类别 | Pipeline | 功能 | |------|----------|------| | 教育 | 互动课堂生成器 | 输入课题→生成完整课件 | | 营销 | 营销方案生成器 | 输入产品→生成营销策略 | | 法律 | 合同智能审查 | 识别风险条款→修改建议 | | 研究 | 文献综述生成器 | 主题→结构化综述报告 | | 生产力 | 智能会议纪要 | 会议内容→结构化纪要 | **Action 类型:** `llm_generate`, `skill`, `hand`, `parallel`, `condition`, `file_export`, `http_request` ### 3.2 Skills 系统 **69 个技能分类:** | 分类 | 数量 | 代表技能 | |------|------|---------| | 开发工程 | 15+ | ai-engineer, backend-architect | | 协调管理 | 8+ | agents-orchestrator, project-shepherd | | 测试质量 | 6+ | code-reviewer, reality-checker | | 设计体验 | 8+ | ux-architect, ui-designer | | 社媒营销 | 12+ | twitter-engager, xiaohongshu-specialist | | 中文平台 | 5+ | chinese-writing, feishu-docs | ### 3.3 Hands 自主能力 | Hand | 状态 | 核心能力 | |------|------|---------| | Browser | ✅ | 15+ 浏览器操作 (Navigate, Click, Scrape...) | | Researcher | ✅ | 多源搜索、内容提取、自动综述 | | Collector | ✅ | 数据聚合、JSONPath 提取 | | Slideshow | ✅ | 课件控制、聚光灯、激光笔 | | Whiteboard | ✅ | 图表绘制、LaTeX 渲染 | | Quiz | ✅ | 自适应测验、成绩分析 | | Speech | ✅ | SSML 语音合成 | | Clip | ⚠️ | 视频处理 (需 FFmpeg) | | Twitter | ⚠️ | 自动化 (需 API Key) | ### 3.4 智能层组件 | 组件 | 功能 | 实现 | |------|------|------| | Agent Memory | 跨会话记忆 | Rust + SQLite | | Identity Evolution | 身份演化 | 提案审批机制 | | Reflection Engine | 自我反思 | 模式分析建议 | | Heartbeat Engine | 心跳巡检 | 自主行为触发 | | Autonomy Manager | 自主授权 | 权限控制 | | Context Compaction | 上下文压缩 | 长对话优化 | --- ## 四、高价值创新点子 (头脑风暴) ### P0 级 - 核心差异化 #### 1. 技能编排引擎 (Skill Orchestration Engine) **概念:** 自动组合多个 Skill 形成执行图,处理复杂任务 **示例流程:** ``` 用户: "帮我分析腾讯的财务状况并生成报告" │ ├──► Skill 1: finance-tracker (提取财务数据) │ │ │ └──► Skill 2: analytics-reporter (生成分析) │ │ │ └──► Skill 3: executive-summary-generator (格式化报告) ``` **可行性:** 技术难度高 | 商业价值极高 | 用户需求极高 #### 2. 可视化工作流构建器 (Visual Workflow Builder) **概念:** 拖拽式 Pipeline 编辑器,降低非技术用户门槛 **实现路径:** 1. 节点类型: Input, LLM, Skill, Hand, Condition, Parallel, Export 2. YAML 双向生成 3. 模板库 + 自定义 **可行性:** 技术难度中 | 商业价值极高 | 用户需求极高 --- ### P1 级 - 差异化功能 #### 3. 自适应智能网格 (Adaptive Intelligence Mesh) **概念:** Pipeline + Memory + Heartbeat 协同,基于用户模式主动推荐工作流 **核心机制:** - Heartbeat 分析 Memory 模式 - 识别任务类型、偏好时间、常用流程 - 主动推荐/触发 Pipeline #### 4. 上下文感知 Hand 触发 (Context-Aware Hand Triggers) **概念:** Hand 触发条件扩展为语义匹配 ```yaml triggers: condition: memory_contains: ["财报", "财务"] conversation_intent: "financial_analysis" ``` #### 5. 记忆驱动的身份演化 (Memory-Powered Persona Evolution) **概念:** 基于记忆模式主动调整 Persona **示例:** ``` 检测到模式: - 70% 对话涉及 Python 代码 - 偏好要点式总结 - 活跃时段: 10:00-12:00 提案: - 身份增加 "Python 专家" - 启用 "简洁输出" 模式 - 在 10:30 安排主动提醒 ``` #### 6. 技能市场 (Skill Marketplace) **概念:** 开发者发布/出售技能,平台分成 **实现:** - .zskill 打包格式 - 验证 + 安全扫描 - 评分、评论、订阅 --- ### P2 级 - 增强功能 | 创新点 | 描述 | 价值 | |--------|------|------| | Pipeline-Skill 双向桥接 | Skill 可触发 Pipeline | 工作流联动 | | 协作工作空间 | 多用户共享 Agent/Memory | B2B 收入 | | 智能LLM路由 | 按任务自动选择最优模型 | 成本优化 | | 预测性记忆助手 | 主动预加载相关记忆 | 体验提升 | --- ## 五、优先级矩阵 | 创新点 | 技术难度 | 商业价值 | 用户需求 | 优先级 | |--------|----------|----------|----------|--------| | 技能编排引擎 | 高 | 极高 | 极高 | **P0** | | 可视化工作流构建器 | 中 | 极高 | 极高 | **P0** | | 自适应智能网格 | 中 | 高 | 高 | P1 | | 上下文感知触发 | 中 | 高 | 高 | P1 | | 记忆驱动身份演化 | 中 | 极高 | 高 | P1 | | 技能市场 | 中 | 极高 | 高 | P1 | | Pipeline-Skill 桥接 | 高 | 高 | 中 | P2 | | 协作工作空间 | 中 | 极高 | 中 | P2 | | 智能LLM路由 | 高 | 高 | 中 | P2 | | 预测性记忆 | 中 | 高 | 高 | P2 | --- ## 六、实施路线图 ### Phase 1: 基础 (1-2 月) 1. **可视化工作流构建器** - 大众化入口 2. **技能编排引擎** - 核心差异化 3. **技能市场 MVP** - 生态基础 ### Phase 2: 智能 (2-3 月) 4. **自适应智能网格** - 个性化 5. **上下文感知触发** - 真正自动化 6. **记忆驱动身份演化** - 身份进化 ### Phase 3: 规模 (3-6 月) 7. **Pipeline-Skill 桥接** - 工作流集成 8. **协作工作空间** - 团队功能 9. **智能LLM路由** - 成本优化 10. **预测性记忆** - 体验增强 --- ## 七、架构瓶颈与改进 | 瓶颈 | 现状 | 改进方向 | |------|------|---------| | Pipeline-Skill 集成 | 单向调用 | 双向感知 | | Memory 索引 | 关键词匹配 | 语义嵌入 | | Hand 触发系统 | 手动/定时 | 语义条件 | | 状态同步 | 单用户 | CRDT 协作 | | LLM 抽象 | Provider 特定 | 统一路由层 | --- ## 八、商业化差异化 1. **本地优先隐私** - 数据不离本地 (vs ChatGPT/Claude) 2. **69+ 专业技能** - 超越通用助手 3. **Pipeline DSL** - 独特工作流自动化 4. **Memory + Identity** - 持续进化的 AI 伙伴 5. **Hands 系统** - 超越对话的自主行动 --- ## 九、关键文件索引 | 文件 | 用途 | |------|------| | [kernel.rs](crates/zclaw-kernel/src/kernel.rs) | 核心协调器 | | [executor.rs](crates/zclaw-pipeline/src/executor.rs) | Pipeline 执行引擎 | | [registry.rs](crates/zclaw-skills/src/registry.rs) | Skill 注册中心 | | [heartbeat.rs](desktop/src-tauri/src/intelligence/heartbeat.rs) | 心跳引擎 | | [hand.rs](crates/zclaw-hands/src/hand.rs) | Hand trait 定义 | --- ## 十、总结 ZCLAW 是一个架构清晰的 AI Agent 桌面应用,具备: ✅ **坚实的技术基础** - 9 个 Rust crates,分层设计 ✅ **丰富的能力生态** - 69 技能 + 9 Hands + 5 Pipeline ✅ **完整的智能层** - 6 个核心组件 ✅ **多模型支持** - 8 个 LLM Provider **下一步建议:** 1. 优先实现 **可视化工作流构建器** 和 **技能编排引擎** 2. 启动 **技能市场** MVP 建立生态 3. 逐步完善智能层协同效应 --- # 第二部分:详细实施计划 > 本部分包含 6 个创新点的详细技术设计和实施步骤 --- ## 创新点 1: 技能编排引擎 (Skill Orchestration Engine) ### 1.1 概述 自动组合多个 Skill 形成执行图 (DAG),支持数据传递、错误处理、依赖解析。 ### 1.2 核心数据结构 ```rust // crates/zclaw-skills/src/orchestration/types.rs /// 技能编排图 pub struct SkillGraph { pub id: String, pub name: String, pub nodes: Vec, // DAG 节点 pub edges: Vec, // 数据流边 pub input_schema: Option, pub output_mapping: HashMap, } /// 编排节点 pub struct SkillNode { pub id: String, pub skill_id: SkillId, pub input_mappings: HashMap, pub retry: Option, pub timeout_secs: Option, pub when: Option, // 条件表达式 } /// 数据表达式 pub enum DataExpression { InputRef(String), // ${inputs.field} NodeOutputRef { node_id: String, field: String }, // ${nodes.xxx.output} Literal(Value), Expression(String), } /// 执行计划 pub struct OrchestrationPlan { pub graph: SkillGraph, pub execution_order: Vec, // 拓扑排序 pub parallel_groups: Vec>, // 并行组 } ``` ### 1.3 关键 Trait ```rust /// 编排计划器 pub trait OrchestrationPlanner: Send + Sync { fn validate(&self, graph: &SkillGraph, registry: &SkillRegistry) -> Result>; fn plan(&self, graph: &SkillGraph) -> Result; fn auto_compose(&self, skill_ids: &[SkillId], registry: &SkillRegistry) -> Result; } /// 图执行器 pub trait SkillGraphExecutor: Send + Sync { async fn execute(&self, graph: &SkillGraph, inputs: HashMap, context: &SkillContext) -> Result; } ``` ### 1.4 实施步骤 | 阶段 | 任务 | 文件 | 工时 | |------|------|------|------| | Phase 1 | 核心类型和验证 | `orchestration/types.rs`, `validation.rs` | 4h | | Phase 2 | 计划器和执行器 | `planner.rs`, `executor.rs`, `context.rs` | 6h | | Phase 3 | 自动组合算法 | `auto_compose.rs` | 4h | | Phase 4 | Pipeline 集成 | `actions/skill_orchestration.rs` | 3h | **需要修改的文件:** - `crates/zclaw-skills/src/lib.rs` - 添加 `pub mod orchestration;` - `crates/zclaw-pipeline/src/types.rs` - 添加 `Action::SkillOrchestration` - `crates/zclaw-pipeline/src/executor.rs` - 处理新 Action 类型 **需要新增的文件:** - `crates/zclaw-skills/src/orchestration/mod.rs` - `crates/zclaw-skills/src/orchestration/types.rs` - `crates/zclaw-skills/src/orchestration/validation.rs` - `crates/zclaw-skills/src/orchestration/planner.rs` - `crates/zclaw-skills/src/orchestration/executor.rs` - `crates/zclaw-skills/src/orchestration/context.rs` - `crates/zclaw-skills/src/orchestration/auto_compose.rs` ### 1.5 验证方案 **单元测试:** - 图验证 (循环检测、缺失节点) - 拓扑排序正确性 - 数据表达式解析 - 并行组识别 **手动验证:** ```bash # 创建编排 YAML cat > test_orchestration.yaml << EOF apiVersion: zclaw/v1 kind: SkillOrchestration spec: nodes: - id: research skill_id: web-researcher input_mappings: query: ${inputs.topic} - id: summarize skill_id: text-summarizer input_mappings: text: ${nodes.research.output.content} edges: - from_node: research to_node: summarize EOF # 在 UI 中执行编排 ``` ### 1.6 工作量估算 - **总工时:** 17 小时 - **风险:** 中等 - DAG 执行复杂性、并发状态管理 - **可复用:** Pipeline 的 ExecutionContext、SkillRegistry --- ## 创新点 2: 可视化工作流构建器 (Visual Workflow Builder) ### 2.1 概述 拖拽式 Pipeline 编辑器,支持 YAML 双向转换,节点类型包括 Input, LLM, Skill, Hand, Condition, Parallel, Export。 ### 2.2 核心数据结构 ```typescript // desktop/src/lib/workflow-builder/types.ts export type NodeType = 'input' | 'llm' | 'skill' | 'hand' | 'condition' | 'parallel' | 'export' | 'loop'; export interface WorkflowNode { id: string; type: NodeType; position: { x: number; y: number }; data: NodeData; } export interface NodeData { label: string; config: Record; llmConfig?: { template: string; model?: string; temperature?: number }; skillConfig?: { skillId: string; inputMappings: Record }; handConfig?: { handId: string; action: string; params: Record }; conditionConfig?: { expression: string; branches: { condition: string; targetNodeId: string }[] }; parallelConfig?: { maxWorkers: number }; exportConfig?: { formats: ('pptx' | 'html' | 'pdf' | 'markdown')[] }; } export interface WorkflowCanvas { nodes: WorkflowNode[]; edges: WorkflowEdge[]; viewport: { x: number; y: number; zoom: number }; metadata: { name: string; description?: string; category?: string }; } ``` ### 2.3 关键组件 | 组件 | 文件 | 功能 | |------|------|------| | WorkflowCanvas | `WorkflowCanvas.tsx` | React Flow 画布 | | NodePalette | `NodePalette.tsx` | 可拖拽节点面板 | | PropertyPanel | `PropertyPanel.tsx` | 节点属性编辑器 | | YamlConverter | `yaml-converter.ts` | YAML 双向转换 | ### 2.4 实施步骤 | 阶段 | 任务 | 工时 | |------|------|------| | Phase 1 | 安装依赖 + 类型定义 | 2h | | Phase 2 | 核心组件 (Canvas, Palette, Panel) | 8h | | Phase 3 | YAML 转换器 | 4h | | Phase 4 | 集成现有 WorkflowEditor | 3h | **需要安装的依赖:** ```bash pnpm add @xyflow/react dagre @dagrejs/dagre ``` **需要新增的文件:** ``` desktop/src/ ├── components/WorkflowBuilder/ │ ├── WorkflowCanvas.tsx │ ├── NodePalette.tsx │ ├── PropertyPanel.tsx │ └── nodes/ │ ├── InputNode.tsx │ ├── LLMNode.tsx │ ├── SkillNode.tsx │ ├── HandNode.tsx │ ├── ConditionNode.tsx │ ├── ParallelNode.tsx │ └── ExportNode.tsx ├── store/workflowBuilderStore.ts └── lib/workflow-builder/ ├── types.ts ├── yaml-converter.ts └── validation.ts ``` ### 2.5 验证方案 **手动验证:** ```bash pnpm start:dev # 1. 拖拽 Input 节点,配置 topic 输入 # 2. 拖拽 LLM 节点,连接到 Input,配置模板 # 3. 拖拽 Skill 节点,连接到 LLM,选择技能 # 4. 拖拽 Export 节点,连接到 Skill,选择格式 # 5. 点击 "生成 YAML" - 验证输出 # 6. 点击 "执行" - 验证 Pipeline 运行 ``` ### 2.6 工作量估算 - **总工时:** 17 小时 - **风险:** 中等 - React Flow 学习曲线、复杂状态管理 - **可复用:** Pipeline YAML 解析器、pipeline-client.ts --- ## 创新点 3: 自适应智能网格 (Adaptive Intelligence Mesh) ### 3.1 概述 Pipeline + Memory + Heartbeat 协同,基于用户行为模式主动推荐工作流。 ### 3.2 核心数据结构 ```rust // desktop/src-tauri/src/intelligence/mesh.rs /// 用户行为模式 pub struct BehaviorPattern { pub id: String, pub pattern_type: PatternType, pub frequency: usize, pub last_occurrence: DateTime, pub confidence: f32, pub context: PatternContext, } pub enum PatternType { SkillCombination { skill_ids: Vec }, TemporalTrigger { hand_id: String, time_pattern: String }, TaskPipelineMapping { task_type: String, pipeline_id: String }, InputPattern { keywords: Vec, intent: String }, } /// 工作流推荐 pub struct WorkflowRecommendation { pub id: String, pub pipeline_id: String, pub confidence: f32, pub reason: String, pub suggested_inputs: HashMap, pub patterns_matched: Vec, } ``` ### 3.3 数据流 ``` Heartbeat Tick → MeshCoordinator.analyze() ↓ PatternDetector.detect_patterns() ↓ Memory (活动历史) + Pipeline Runs (执行历史) ↓ BehaviorPattern[] ↓ WorkflowRecommender.recommend() ↓ WorkflowRecommendation[] ↓ UI 通知 → 用户接受 → 执行 Pipeline ``` ### 3.4 实施步骤 | 阶段 | 任务 | 文件 | 工时 | |------|------|------|------| | Phase 1 | 核心类型 + 模式检测 | `mesh.rs`, `pattern_detector.rs` | 5h | | Phase 2 | Memory/Pipeline 集成 | `mesh.rs` | 4h | | Phase 3 | 推荐引擎 | `recommender.rs` | 4h | | Phase 4 | Heartbeat 集成 + UI | `heartbeat.rs`, `WorkflowRecommendations.tsx` | 4h | **需要新增的文件:** - `desktop/src-tauri/src/intelligence/mesh.rs` - `desktop/src-tauri/src/intelligence/pattern_detector.rs` - `desktop/src-tauri/src/intelligence/recommender.rs` - `desktop/src/components/WorkflowRecommendations.tsx` ### 3.5 验证方案 ```bash # 1. 重复使用特定技能组合 # 2. 等待心跳检查 (或强制触发) # 3. 检查 UI 中的推荐通知 # 4. 接受推荐并验证 Pipeline 执行 ``` ### 3.6 工作量估算 - **总工时:** 17 小时 - **风险:** 中高 - 模式检测准确性、推荐相关性 - **可复用:** HeartbeatEngine, PersistentMemoryStore, PipelineExecutor --- ## 创新点 4: 上下文感知 Hand 触发 (Context-Aware Hand Triggers) ### 4.1 概述 扩展触发条件为语义匹配: MemoryQuery, ContextCondition, IdentityState。 ### 4.2 核心数据结构 ```rust // crates/zclaw-hands/src/trigger.rs (扩展) pub enum TriggerType { // ... 现有类型 ... /// 记忆查询触发器 MemoryQuery { memory_type: Option, content_pattern: String, min_count: usize, min_importance: Option, }, /// 上下文条件触发器 ContextCondition { conditions: Vec, combination: ConditionCombination, // All | Any | None }, /// 身份状态触发器 IdentityState { file: IdentityFile, content_pattern: Option, any_change: bool, }, /// 复合触发器 Composite { triggers: Vec, combination: ConditionCombination, }, } pub enum ContextField { TimeOfDay, DayOfWeek, ActiveProject, RecentTopic, PendingTasks, MemoryCount, LastInteractionHours, } ``` ### 4.3 触发器评估器 ```rust // crates/zclaw-hands/src/trigger_evaluator.rs pub struct TriggerEvaluator { memory_store: Arc, identity_manager: Arc>, heartbeat_engine: Arc>, } impl TriggerEvaluator { pub async fn evaluate(&self, trigger: &TriggerType, agent_id: &str) -> Result { match trigger { TriggerType::MemoryQuery { content_pattern, min_count, .. } => { let results = self.memory_store.search(query).await?; Ok(results.len() >= *min_count) } TriggerType::ContextCondition { conditions, combination } => { // 评估条件组合 } // ... } } } ``` ### 4.4 实施步骤 | 阶段 | 任务 | 工时 | |------|------|------| | Phase 1 | 扩展 TriggerType | 3h | | Phase 2 | 实现评估器 | 5h | | Phase 3 | Heartbeat 集成 | 3h | | Phase 4 | UI 配置界面 | 3h | **需要修改的文件:** - `crates/zclaw-hands/src/trigger.rs` - 添加新触发类型 - `desktop/src-tauri/src/intelligence/heartbeat.rs` - 触发评估钩子 - `desktop/src/components/CreateTriggerModal.tsx` - 新触发类型配置 **需要新增的文件:** - `crates/zclaw-hands/src/trigger_evaluator.rs` ### 4.5 验证方案 ```bash # 创建语义触发器 # 类型: MemoryQuery # memory_type: "task" # content_pattern: "urgent" # min_count: 3 # 添加 3 条包含 "urgent" 的任务记忆 # 验证 Hand 被触发 ``` ### 4.6 工作量估算 - **总工时:** 14 小时 - **风险:** 中等 - 复杂条件评估、状态同步 - **可复用:** PersistentMemoryStore, AgentIdentityManager, HeartbeatEngine --- ## 创新点 5: 记忆驱动身份演化 (Memory-Powered Persona Evolution) ### 5.1 概述 基于 Memory 模式自动调整 Persona,提取用户偏好并更新 USER.md。 ### 5.2 核心数据结构 ```rust // desktop/src-tauri/src/intelligence/persona_evolution.rs /// 检测到的用户偏好 pub struct DetectedPreference { pub category: PreferenceCategory, pub value: String, pub confidence: f32, pub evidence: Vec, pub occurrence_count: usize, } pub enum PreferenceCategory { CommunicationStyle, // "concise", "detailed" Tone, // "formal", "casual" Language, // "zh-CN", "en-US" CodeStyle, // "typescript", "python" DetailLevel, // "summary", "step-by-step" WorkHours, // "9-18", "flexible" Expertise, // "frontend", "backend" } /// 身份变更提案 pub struct PersonaChangeProposal { pub id: String, pub agent_id: String, pub change_type: PersonaChangeType, pub proposed_value: String, pub confidence: f32, pub supporting_evidence: Vec, } pub enum PersonaChangeType { UserProfileAddition, UserProfileUpdate, InstructionAddition, SoulModification, } ``` ### 5.3 偏好检测流程 ``` Memory 分析 → 模式匹配 → 偏好聚合 → 提案生成 → 审批/自动应用 ``` **检测模式:** ```rust let patterns = [ (r"偏好(.+?)(?:风格|方式|模式)", PreferenceCategory::CommunicationStyle), (r"喜欢用(.+?)(?:语言|代码)", PreferenceCategory::CodeStyle), (r"(?:说|写)(.+?)(?:一点|一些)", PreferenceCategory::DetailLevel), ]; ``` ### 5.4 实施步骤 | 阶段 | 任务 | 工时 | |------|------|------| | Phase 1 | 核心类型 + 偏好检测 | 4h | | Phase 2 | Memory 分析集成 | 3h | | Phase 3 | Identity Manager 集成 | 4h | | Phase 4 | UI 组件 | 3h | **需要新增的文件:** - `desktop/src-tauri/src/intelligence/persona_evolution.rs` - `desktop/src/components/PersonaEvolutionPanel.tsx` **需要修改的文件:** - `desktop/src-tauri/src/intelligence/identity.rs` - 添加演化钩子 - `desktop/src/components/IdentityChangeProposal.tsx` - Persona 变更支持 ### 5.5 验证方案 ```bash # 在对话中表达偏好: # "我喜欢简洁的回答" # "用中文回复" # "先给代码再解释" # 等待演化周期或手动触发 # 检查 USER.md 是否更新 ``` ### 5.6 工作量估算 - **总工时:** 14 小时 - **风险:** 中等 - NLP 模式准确性、提案相关性 - **可复用:** PersistentMemoryStore, AgentIdentityManager, Heartbeat 修正模式 --- ## 创新点 6: 预测性记忆助手 (Predictive Memory Assistant) ### 6.1 概述 主动预加载相关记忆,基于对话轨迹预测用户需求。 ### 6.2 核心数据结构 ```rust // desktop/src-tauri/src/intelligence/predictive_memory.rs pub struct PredictiveConfig { pub enabled: bool, pub max_preload_count: usize, pub confidence_threshold: f32, pub context_window_size: usize, pub strategy: PreloadStrategy, } pub enum PreloadStrategy { KeywordMatching, SemanticSimilarity, TemporalPatterns, Hybrid, } /// 记忆预测结果 pub struct MemoryPrediction { pub memory_id: String, pub relevance_score: f32, pub prediction_reason: PredictionReason, pub matched_keywords: Vec, } pub enum PredictionReason { KeywordMatch, SemanticSimilarity, TemporalRelevance, UserPattern, ContextAssociation, } ``` ### 6.3 预测引擎 ```rust impl PredictiveMemoryEngine { pub async fn predict( &mut self, agent_id: &str, recent_messages: &[ChatMessage], ) -> Result> { // 1. 从最近消息提取上下文 let context = self.trajectory_analyzer.extract_context(recent_messages)?; // 2. 获取候选记忆 let candidates = self.memory_store.search(query).await?; // 3. 评分排序 let predictions: Vec = candidates .iter() .filter_map(|m| self.score_memory(m, &context)) .sorted_by(|a, b| b.relevance_score.partial_cmp(&a.relevance_score)) .take(self.config.max_preload_count) .collect(); // 4. 预加载到缓存 self.preload_cache.insert(agent_id.to_string(), memories); Ok(predictions) } } ``` ### 6.4 实施步骤 | 阶段 | 任务 | 工时 | |------|------|------| | Phase 1 | 核心类型 + 基础预测 | 4h | | Phase 2 | Memory Store 集成 | 3h | | Phase 3 | 聊天流程集成 | 3h | | Phase 4 | UI 指示器 | 2h | **需要新增的文件:** - `desktop/src-tauri/src/intelligence/predictive_memory.rs` **需要修改的文件:** - `desktop/src-tauri/src/kernel_commands.rs` - 聊天流程钩子 - `desktop/src/components/MemoryPanel.tsx` - 预测指示器 ### 6.5 验证方案 ```bash # 1. 添加关于 "React" 和 "TypeScript" 的记忆 # 2. 开始对话提到 "frontend development" # 3. 验证 React/TypeScript 记忆出现在预加载区域 # 4. 检查 LLM 响应是否使用预加载上下文 ``` ### 6.6 工作量估算 - **总工时:** 12 小时 - **风险:** 低中 - 预测准确性、性能影响 - **可复用:** PersistentMemoryStore, 聊天消息基础设施 --- ## 总结:工作量与优先级 | 创新点 | 总工时 | 风险 | 优先级 | 关键依赖 | |--------|--------|------|--------|----------| | 1. 技能编排引擎 | 17h | 中 | **P0** | SkillRegistry, PipelineExecutor | | 2. 可视化工作流构建器 | 17h | 中 | **P0** | Pipeline YAML, React Flow | | 3. 自适应智能网格 | 17h | 中高 | P1 | Heartbeat, Memory, Pipeline | | 4. 上下文感知触发 | 14h | 中 | P1 | Memory, IdentityManager | | 5. 记忆驱动身份演化 | 14h | 中 | P1 | Memory, IdentityManager | | 6. 预测性记忆助手 | 12h | 低中 | P2 | Memory, Chat flow | | **总计** | **91h** | | | | --- ## 建议实施顺序 1. **Week 1-2:** 技能编排引擎 (P0) + 可视化工作流构建器 (P0) 2. **Week 3-4:** 上下文感知触发 (P1) + 记忆驱动身份演化 (P1) 3. **Week 5-6:** 自适应智能网格 (P1) + 预测性记忆助手 (P2) --- ## 实施进度报告 (2025-03-25) ### 已完成: P0 优先级创新点 #### 1. 技能编排引擎 (Skill Orchestration Engine) ✅ **新增文件:** - `crates/zclaw-skills/src/orchestration/mod.rs` - 模块入口 - `crates/zclaw-skills/src/orchestration/types.rs` - 核心类型 (SkillGraph, SkillNode, SkillEdge, DataExpression) - `crates/zclaw-skills/src/orchestration/validation.rs` - 图验证、循环检测、拓扑排序 - `crates/zclaw-skills/src/orchestration/planner.rs` - OrchestrationPlanner trait + PlanBuilder fluent API - `crates/zclaw-skills/src/orchestration/executor.rs` - SkillGraphExecutor trait + DefaultExecutor - `crates/zclaw-skills/src/orchestration/context.rs` - OrchestrationContext 执行上下文 - `crates/zclaw-skills/src/orchestration/auto_compose.rs` - 自动组合算法 (Schema 匹配) - `crates/zclaw-pipeline/src/actions/orchestration.rs` - Pipeline 动作处理器 **修改文件:** - `crates/zclaw-skills/Cargo.toml` - 添加 regex, uuid 依赖 - `crates/zclaw-skills/src/lib.rs` - 导出 orchestration 模块 - `crates/zclaw-pipeline/src/types.rs` - 添加 SkillOrchestration Action 类型 - `crates/zclaw-pipeline/src/actions/mod.rs` - 添加 OrchestrationActionDriver trait - `crates/zclaw-pipeline/src/executor.rs` - 处理 SkillOrchestration action **核心功能:** - DAG (有向无环图) 执行模型 - 拓扑排序确定执行顺序 - 并行组识别优化性能 - 数据表达式解析 (\${inputs.xxx}, \${nodes.xxx.output}) - 条件评估 (==, !=, exists) - 基于 Schema 匹配的自动技能组合 #### 2. 可视化工作流构建器 (Visual Workflow Builder) ✅ **新增文件:** - `desktop/src/lib/workflow-builder/types.ts` - 完整类型定义 (12 种节点类型) - `desktop/src/lib/workflow-builder/yaml-converter.ts` - 双向 YAML 转换器 - `desktop/src/store/workflowBuilderStore.ts` - Zustand 状态管理 - `desktop/src/components/WorkflowBuilder/WorkflowBuilder.tsx` - 主画布组件 - `desktop/src/components/WorkflowBuilder/NodePalette.tsx` - 可拖拽节点面板 - `desktop/src/components/WorkflowBuilder/PropertyPanel.tsx` - 属性编辑面板 - `desktop/src/components/WorkflowBuilder/WorkflowToolbar.tsx` - 工具栏 - `desktop/src/components/WorkflowBuilder/nodes/InputNode.tsx` - 输入节点 - `desktop/src/components/WorkflowBuilder/nodes/LlmNode.tsx` - LLM 节点 - `desktop/src/components/WorkflowBuilder/nodes/SkillNode.tsx` - 技能节点 - `desktop/src/components/WorkflowBuilder/nodes/HandNode.tsx` - Hand 节点 - `desktop/src/components/WorkflowBuilder/nodes/ConditionNode.tsx` - 条件节点 - `desktop/src/components/WorkflowBuilder/nodes/ParallelNode.tsx` - 并行节点 - `desktop/src/components/WorkflowBuilder/nodes/ExportNode.tsx` - 导出节点 - `desktop/src/components/WorkflowBuilder/nodes/HttpNode.tsx` - HTTP 节点 - `desktop/src/components/WorkflowBuilder/nodes/OrchestrationNode.tsx` - 编排节点 **安装依赖:** - `@xyflow/react` - React Flow 画布库 - `dagre`, `@dagrejs/dagre` - 自动布局算法 - `js-yaml`, `@types/js-yaml` - YAML 解析 **核心功能:** - 拖拽式节点放置 - 可视化边连接 - 属性面板编辑 - YAML 双向转换 - 拓扑排序验证 - 循环检测 - Dagre 自动布局 ### 下一步工作 **P1 优先级:** - [ ] 自适应智能网格 (Adaptive Intelligence Mesh) - [ ] 上下文感知触发 (Context-Aware Hand Triggers) - [ ] 记忆驱动身份演化 (Memory-Powered Persona Evolution) **P2 优先级:** - [ ] 预测性记忆助手 (Predictive Memory Assistant)