Skip to content

everythingfornothing/skill_evolution_plugin

Repository files navigation

Skill Evolution Plugin

让 ClawHub Skill 自动进化为个性化专属技能

npm version License: MIT OpenClaw Plugin


🎯 简介

Skill Evolution Plugin 是一个 OpenClaw 插件,能够自动捕获 Skill 使用过程中的修正行为,通过模式识别生成优化建议,最终实现 Skill 的自进化。

核心价值:让从 ClawHub 下载的通用 Skill,通过你的使用习惯,自动进化为个性化专属技能。


✨ 特性

  • 🔍 隐式学习 - 无需手动反馈,自动捕获 AI 的修正行为
  • 📝 补丁生成 - 直接生成可应用的 unified diff 补丁
  • 🔒 本地优先 - 数据存储在本地,隐私安全
  • 🚀 轻量级 - 独立插件,npm install 即可使用
  • 🎯 OpenClaw 原生 - 深度集成 OpenClaw 生态

📦 安装

前置要求

  • Node.js >= 16.0.0
  • OpenClaw >= 1.0.0
  • npm >= 7.0.0

安装插件

# 克隆项目
git clone https://github.com/YOUR_USERNAME/skill-evolution-plugin.git
cd skill-evolution-plugin

# 安装依赖
npm install

# (可选)全局安装 CLI
npm install -g

🚀 快速开始

1. 运行演示

# 使用快速启动脚本
./QUICKSTART.sh

# 或手动运行
node bin/cli.js demo

输出示例

═══════════════════════════════════════════════════════════
  Skill Evolution Plugin - MVP 演示
═══════════════════════════════════════════════════════════

--- 第 1 次执行 ---
[SkillEvolution] 开始监控会话 exec_1774620809179_ws4q9w (skill: agent-browser)
[SkillEvolution] 会话 exec_1774620809179_ws4q9w 结束,已保存到 ...
  ✓ 会话 exec_1774620809179_ws4q9w 已保存

...

═══════════════════════════════════════════════════════════
  生成进化报告
═══════════════════════════════════════════════════════════

╔══════════════════════════════════════════════════════════╗
║  📊 Skill 进化报告 - agent-browser                  ║
╚══════════════════════════════════════════════════════════╝

📈 执行统计:
   - 总执行次数:5
   - 成功率:100.0%

🔍 发现 2 个优化机会:
   1. 优化 agent-browser.snapshot 的重试策略
      频率:60.0% (3/5)
   2. 为 agent-browser.click 添加容错逻辑
      频率:60.0% (3/5)

2. 查看报告

# 生成人类可读报告
node bin/cli.js report agent-browser

# 查看状态
node bin/cli.js status agent-browser

# JSON 格式分析
node bin/cli.js analyze agent-browser

3. 列出补丁

node bin/cli.js list-patches agent-browser

💡 使用示例

基础用法

const { SkillEvolutionPlugin } = require('skill-evolution-plugin');

// 创建插件实例
const plugin = new SkillEvolutionPlugin();

// 开始监控
const sessionId = plugin.startMonitoring('agent-browser', '帮我登录网站');

// 记录工具调用
plugin.recordToolCall(sessionId, 'agent-browser.open', 
  { url: 'https://example.com' }, 
  { success: true }
);

// 记录修正(AI 自动调整参数)
plugin.recordToolCall(sessionId, 'agent-browser.click', 
  { ref: '@e5' }, 
  { success: true },
  { correctedFrom: { ref: '@e3' }, correctionReason: 'Element not found' }
);

// 结束监控
plugin.stopMonitoring(sessionId, 'success');

// 生成报告
const report = plugin.generateReport('agent-browser');
console.log(report);

进阶用法

// 自定义配置
const plugin = new SkillEvolutionPlugin({
  threshold: 3,  // 3 次相似修正后建议
  logPath: '~/.openclaw/skills'
});

// 分析模式
const analysis = plugin.analyze('agent-browser');
console.log(JSON.stringify(analysis, null, 2));

// 创建补丁
const patchInfo = plugin.createPatch(
  'agent-browser',
  originalContent,
  modifiedContent,
  'Add retry logic'
);

OpenClaw 集成

详见 integration/README.md

const { evolutionPlugin } = require('skill-evolution-plugin');

// 在 OpenClaw SkillExecutor 中
async executeTool(skillName, toolName, params) {
  const sessionId = evolutionPlugin.startMonitoring(skillName, userRequest);
  
  try {
    const result = await originalExecute(toolName, params);
    evolutionPlugin.recordToolCall(sessionId, toolName, params, result);
    return result;
  } catch (error) {
    evolutionPlugin.recordToolCall(sessionId, toolName, params, { error });
    throw error;
  } finally {
    evolutionPlugin.stopMonitoring(sessionId, 'success');
  }
}

更多示例


📚 CLI 命令

skill-evolution demo              # 运行演示
skill-evolution analyze <skill>   # 分析模式(JSON 输出)
skill-evolution report <skill>    # 生成人类可读报告
skill-evolution status <skill>    # 查看状态
skill-evolution list-patches <skill>  # 列出补丁
skill-evolution help              # 显示帮助

选项

-t, --threshold <number>  建议阈值(默认:3)
-l, --limit <number>      日志数量限制(默认:100)
-h, --help                显示帮助

🏗️ 架构设计

┌─────────────────────────────────────────────────────────┐
│                        用户                              │
└─────────────────────────────────────────────────────────┘
                        ↓
┌─────────────────────────────────────────────────────────┐
│              Skill Evolution Plugin                     │
│  ┌─────────────┐  ┌──────────────┐  ┌─────────────────┐│
│  │ Interceptor │→ │  Analyzer    │→ │ Patch Manager   ││
│  │ (拦截器)    │  │  (分析器)    │  │ (补丁管理)      ││
│  └─────────────┘  └──────────────┘  └─────────────────┘│
└─────────────────────────────────────────────────────────┘
                        ↓
┌─────────────────────────────────────────────────────────┐
│              ~/.openclaw/skills/<skill>/.evolution/     │
│  ├── execution-log.jsonl    (执行日志)                  │
│  ├── patches/               (补丁文件)                  │
│  └── manifest.json          (版本管理)                  │
└─────────────────────────────────────────────────────────┘

核心模块

  • Interceptor:拦截工具调用,记录修正行为
  • Analyzer:分析日志,识别模式,生成建议
  • PatchManager:管理补丁的生成和应用

详见 docs/ARCHITECTURE.md


📊 数据格式

执行日志(execution-log.jsonl)

{
  "session_id": "exec_1774620809181_jf3oj0",
  "skill": "agent-browser",
  "timestamp": "2026-03-27T14:13:29.181Z",
  "user_request": "帮我登录 example.com",
  "actual_execution": [...],
  "modifications": [
    {
      "type": "correction",
      "tool": "agent-browser.click",
      "original": "@e3",
      "corrected": "@e5",
      "reason": "Re-snapshot"
    }
  ],
  "outcome": "success"
}

🔧 配置

环境变量

# 启用/禁用插件
export SKILL_EVOLUTION_ENABLED=true

# 自定义日志路径
export SKILL_EVOLUTION_LOG_PATH=~/.openclaw/skills

# 设置阈值
export SKILL_EVOLUTION_THRESHOLD=3

配置文件(计划中)

# ~/.openclaw/config.yaml
plugins:
  skill-evolution:
    enabled: true
    threshold: 3
    logPath: ~/.openclaw/skills
    autoReport: weekly

🧪 测试

# 运行演示
npm run demo

# 运行测试(计划中)
npm test

# 查看测试覆盖率
npm run coverage

📁 项目结构

skill-evolution-plugin/
├── src/
│   ├── index.js              # 主入口
│   ├── interceptor.js        # 拦截器
│   ├── analyzer.js           # 分析器
│   └── patch-manager.js      # 补丁管理
├── bin/
│   └── cli.js                # CLI 工具
├── examples/
│   ├── basic-usage.js        # 基础用法
│   ├── advanced-usage.js     # 进阶用法
│   └── openclaw-integration.js # OpenClaw 集成
├── test/
│   └── demo.js               # 演示脚本
├── docs/
│   ├── ARCHITECTURE.md       # 架构设计
│   ├── API.md                # API 参考
│   └── INTEGRATION.md        # 集成指南
├── integration/
│   ├── README.md             # 集成指南
│   └── openclaw-hook-example.js # 示例代码
├── package.json
├── README.md
├── CHANGELOG.md
├── CONTRIBUTING.md
└── LICENSE

🤝 贡献

欢迎贡献!详见 CONTRIBUTING.md

可以贡献的内容

  • 🐛 报告 Bug
  • 💡 提出新功能建议
  • 📝 改进文档
  • 🔧 提交代码
  • 🌍 翻译文档

快速开始

# 1. Fork 项目
# 2. 克隆到本地
git clone https://github.com/YOUR_USERNAME/skill-evolution-plugin.git

# 3. 创建分支
git checkout -b feature/your-feature-name

# 4. 开发并提交
npm install
# ... 开发 ...
git commit -m "feat: add new feature"

# 5. 创建 Pull Request

📈 路线图

Phase 1: MVP ✅ (已完成)

  • 拦截器
  • 分析器
  • 补丁管理
  • CLI 工具
  • 基础文档

Phase 2: 功能完善 (进行中)

  • 补丁自动生成
  • 补丁应用功能
  • 回滚功能
  • 单元测试
  • OpenClaw 深度集成

Phase 3: 智能化 (计划中)

  • 改进模式识别算法
  • 跨 Skill 学习
  • 改进建议共享池
  • 企业版功能

📊 性能指标

  • 内存开销:~5MB(存储执行记录)
  • CPU 开销:<1%(异步记录,不阻塞执行)
  • 磁盘开销:~1KB/次执行(JSONL 格式)

🔒 安全与隐私

  • 本地存储:所有数据存储在 ~/.openclaw/skills/<skill>/.evolution/
  • 不上传云端:无网络请求,完全离线
  • 用户控制:用户可随时删除 .evolution/ 目录
  • 不记录敏感信息:仅记录工具调用,不记录用户数据

📚 相关资源


📄 许可证

MIT License - 详见 LICENSE


🙏 致谢

感谢 OpenClaw 社区和所有贡献者!


📞 联系方式


Made with ❤️ for OpenClaw Community

About

让clawhub上的skills进入自进化时代

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors