From 39362cab7f9a30404ee94eb72ad9b2216c09dab8 Mon Sep 17 00:00:00 2001 From: cfdaily Date: Sat, 16 May 2026 23:25:31 +0800 Subject: [PATCH] auto-sync: 2026-05-16 23:25:31 --- docs/design/technical-design-v2.6.md | 146 +++++++++++++++++++++++++-- 1 file changed, 140 insertions(+), 6 deletions(-) diff --git a/docs/design/technical-design-v2.6.md b/docs/design/technical-design-v2.6.md index 51ebaad..48753c4 100644 --- a/docs/design/technical-design-v2.6.md +++ b/docs/design/technical-design-v2.6.md @@ -350,7 +350,141 @@ build_bootstrap() 按 tag 检索 experiences 表,格式化后注入 L2 上下 --- -## 7. API 设计 +## 7. Skill 体系 + +### 7.1 Skill 三层载体 + +| 载体 | 自由度 | 生命周期 | 产出者 | 存储 | +|------|--------|---------|--------|------| +| **Memory** | 高(自然语言) | 短期(30天过期) | Agent 自动沉淀 | experiences 表 | +| **Skill** | 中(模板+约束) | 中期(版本管理) | 二级蒸馏 / 人工编写 | skills/ 目录 | +| **Rule** | 低(脚本/断言) | 长期(代码级稳定) | 人工提炼 | guardrails.yaml | + +信息压缩方向:Memory → Skill → Rule(自由度递减,可靠性递增)。 + +### 7.2 Skill 目录结构 + +``` +sanguo_moziplus_v2/ +├── skills/ ← 全局 Skill 库 +│ ├── builtins/ ← 系统内置 Skill +│ │ ├── blackboard_operations/ ← 黑板操作规范 +│ │ ├── code_review/ ← 代码审查标准 +│ │ └── data_validation/ ← 数据验证 +│ └── custom/ ← 用户/蒸馏产出 Skill +│ └── {skill_id}/n │ ├── SKILL.md ← 四要素:description/triggers/actions/constraints + │ ├── template.md ← 可选:详细模板 + │ └── meta.yaml ← 版本、来源、tag + │ +├── projects/{pid}/ + │ └── skills/ ← per-project Skill 覆盖/扩展 + │ └── {skill_id}/ + │ └── project_override.md +``` + +### 7.3 Skill 四要素(SKILL.md 格式) + +```markdown +# {skill_name} + +## Description +一句话描述能力。 + +## Triggers +自动触发条件(任务类型/关键词/产出类型)。 + +## Actions +执行步骤和产出要求。 + +## Constraints +硬性约束(必须满足/禁止做)。 +``` + +### 7.4 Skill 生命周期 + +``` +draft(蒸馏产出/人工创建) + → active(验证通过,build_bootstrap 可引用) + → deprecated(30天无引用/被更好的替代) + → deleted(清理) +``` + +- **draft → active**:二级蒸馏自动标记,或人工在 Dashboard 审批 +- **active → deprecated**:`expire_days` 无引用自动降级 +- **active → deprecated → deleted**:有新版本替代时 + +### 7.5 Skill 在 Daemon 中的角色 + +```python +# daemon/bootstrap.py 中 Skill 加载逻辑 + +def load_skills(task, role, project_config) -> list[str]: + """L3 被动参考层:按需加载 Skill description""" + skills = [] + + # 1. 按 task_type 匹配 triggers + builtin_skills = scan_skills("skills/builtins/", task.task_type) + + # 2. per-project 覆盖 + project_skills = scan_skills(f"projects/{task.project_id}/skills/", task.task_type) + + # 3. 经验匹配(experiences 表按 tag 检索,注入 L2) + # → 这部分在 build_bootstrap() 的 L2 ⑦ 中处理 + + # 4. 只返回 description(四要素摘要),不加载完整 SKILL.md + return [s.description for s in builtin_skills + project_skills if s.status == 'active'] +``` + +**四层加载**(来源:课题4 D4-6): + +| 层 | 加载时机 | 内容 | 占用 | +|----|---------|------|------| +| Agent 固化 | OpenClaw agent 配置 | SOUL.md/IDENTITY.md/TOOLS.md | L1(Agent 自带) | +| OpenClaw 注册 | agent 启动时 | OpenClaw skills/ 目录 | L3(按需) | +| moziplus 注入 | build_bootstrap() | prompt_templates + guardrails + review_protocols | L2(精确注入) | +| 按需检索 | Agent 执行中主动查询 | Skill SKILL.md 全文 | L3(Agent 自己读) | + +### 7.6 template_components.yaml + +模板组件库,build_bootstrap() L2 拼装时引用: + +```yaml +components: + - id: executor_ops + file: prompt_templates/executor.md + inject_to: [executor] + + - id: reviewer_ops + file: prompt_templates/reviewer.md + inject_to: [reviewer] + + - id: planner_ops + file: prompt_templates/planner.md + inject_to: [planner] + + - id: guardrails + file: config/guardrails.yaml + inject_to: [executor] + condition: task_type in guardrails + + - id: review_protocol + file: config/review_protocols/{task_type}_review.yaml + inject_to: [reviewer, planner] + condition: review required + + - id: experience_injection + source: experiences_table + inject_to: [executor, reviewer] + condition: matching_tags > 0 + + - id: custom + file: null # per-project 自定义 + inject_to: [] +``` + +--- + +## 8. API 设计 ### 7.1 黑板 API @@ -395,7 +529,7 @@ GET /api/events?project={pid} --- -## 8. Hook 系统 +## 9. Hook 系统 双重 Hook 架构: @@ -409,7 +543,7 @@ GET /api/events?project={pid} --- -## 9. 前端架构 +## 10. 前端架构 ### 9.1 技术选型 @@ -441,7 +575,7 @@ cd src/frontend && npm run build --- -## 10. 测试策略 +## 11. 测试策略 ### 10.1 单元测试 @@ -468,7 +602,7 @@ per-project 测试用 `:memory:` SQLite。全局注册表测试用临时文件 --- -## 11. 实现顺序 +## 12. 实现顺序 | Phase | 内容 | 估计时间 | |-------|------|---------| @@ -479,7 +613,7 @@ per-project 测试用 `:memory:` SQLite。全局注册表测试用临时文件 --- -## 12. 风险 +## 13. 风险 | 风险 | 缓解 | |------|------|