Claude学习协议服务器

一个帮助Claude Code从错误中学习的模型上下文协议服务器,通过观察工作模式并提供更新规则、钩子和技能的建议。

  • by Vvkmnn
  • JavaScript
  • 本地部署
  • 更新于
在 GitHub 查看 Vvkmnn/claude-gladiator-mcp

使用说明

克劳德角斗士

一 模型上下文协议(MCP) 有帮助的服务器 克劳德代码 从自己的错误中吸取教训。在工作中观察模式,然后反思以获得更新规则、钩子和技能的建议。



受Claude Code持续学习实验的启发: 一切克劳德代码 通过 原谅我, 欺骗 通过 刀片,以及 人造人 通过 载人飞机研究基础: 旅行者 (王等人,2023)和 反思 (Shinn等人,2023)。

安装

要求:

来自shell:

claude mcp add claude-gladiator-mcp -- npx claude-gladiator-mcp

从内部克劳德 (需要重新启动):

Add this to our global mcp config: npx claude-gladiator-mcp

Install this mcp: https://github.com/Vvkmnn/claude-gladiator-mcp

从任何手动配置 mcp.json:(光标、风帆等)

{
  "mcpServers": {
    "claude-gladiator-mcp": {
      "command": "npx",
      "args": ["claude-gladiator-mcp"],
      "env": {}
    }
  }
}

有 不 npm install 必需的 --没有外部依赖或本地数据库,只有聚类算法。

然而,如果 npx 解决错误的包,您可以使用以下命令强制解决:

npm install -g claude-gladiator-mcp

技能

可选地,安装技能来教克劳德何时主动观察和反思:

npx skills add Vvkmnn/claude-gladiator-mcp --skill claude-gladiator --global
# Optional: add --yes to skip interactive prompt and install to all agents

这使得Claude能够自动观察工具故障、用户更正和代码库模式。MCP在没有技能的情况下工作,但技能提高了可发现性。

插件

对于自动观察挂钩和会话结束反射提示,请从安装 克劳德商场 市场:

/plugin marketplace add Vvkmnn/claude-emporium
/plugin install claude-gladiator@claude-emporium

这 克劳德角斗士 插件提供:

钩子 (目标明确,成功后零开销):

  • Bash/编辑/写入错误后→ 通过以下方式观察故障模式 gladiator_observe
  • 会话结束前→ 通过以下方式反思未经处理的观察结果 gladiator_reflect

需要先安装MCP服务器。请参阅商场了解其他Claude Code插件和MCP。

特性

MCP服务器 这给了克劳德一个学习循环。观察模式,对它们进行聚类,改进配置。

gladiator_observe

记录一个值得学习的模式——工具故障、纠正、惯例、决策。通过摘要的SHA-256哈希进行重复数据消除。

gladiator_observe summary=<summary> tags=<tags> context=<context>
  > "Edit failed on config.ts -- 3 identical import blocks, fixed by including surrounding context"
  > "User wanted tests in __tests__/ not next to source -- project convention"
  > "All API routes use zod validation middleware -- schema in routes/schemas/"
┌─ ⚔ ───────────────────────────────────────────────────── Recorded ─┐
│ Edit failed on config.ts -- 3 identical import blocks              │
│ Recommend (rule): Next time: included 3 lines above                │
│ Tags: edit, disambiguation                                         │
│ Backlog: 3 unprocessed of 12 total                                 │
└────────────────────────────────────────────────────────────────────┘
{
  "id": "obs_1738012345_a7f3",
  "ts": "2025-01-27T18:32:25.000Z",
  "summary": "Edit failed on config.ts -- 3 identical import blocks",
  "recommendation": "Next time: included 3 lines above",
  "artifact_type": "rule",
  "context": {
    "tool": "Edit",
    "error": "old_string not unique",
    "before": "used import line only",
    "after": "included 3 lines above"
  },
  "tags": ["edit", "disambiguation"],
  "processed": false
}

gladiator_reflect

对未处理的观测值进行聚类,扫描现有观测值 ~/.claude/rules/, ~/.claude/hooks/,以及 ~/.claude/skills/,并建议是否 更新现有工件 或 创建一个新的.

gladiator_reflect
  > "I've accumulated 5 observations about edit failures -- what patterns emerge?"
  > "Review what I've learned this session before it's lost"

gladiator_reflect query="testing"
  > "Search past observations about testing conventions"

集群模式 (存在未经处理的观察结果):

┌─ ⚔ ──────────────────────────────────────────────────── Reflected ─┐
│ 5 observations → 2 groups                                          │
│ 8 existing artifacts scanned (IDF-weighted)                        │
│                                                                    │
│ UPDATE avoid: edit-disambiguation (3 obs)                          │
│   - Next time: included 3 lines above                              │
│   - Include surrounding function context for disambiguation        │
│   - Check for duplicate imports before editing                     │
│ NEW rule: testing-convention (2 obs)                               │
│   - Next time: moved to __tests__/utils.test.ts                    │
│   - Use __tests__/ directory for all test files                    │
└────────────────────────────────────────────────────────────────────┘
{
  "observations_analyzed": 5,
  "groups_found": 2,
  "existing_artifacts_scanned": 8,
  "groups": [
    {
      "suggested_name": "edit-disambiguation",
      "artifact_type": "rule",
      "tags": ["edit", "disambiguation", "old_string"],
      "action": "update",
      "update_targets": [{ "type": "rule", "name": "avoid", "path": "~/.claude/rules/avoid.md" }],
      "observations": ["..."]
    },
    {
      "suggested_name": "testing-convention",
      "artifact_type": "rule",
      "tags": ["convention", "testing"],
      "action": "create",
      "update_targets": [],
      "observations": ["..."]
    }
  ],
  "actions": [
    "PREFER updating existing artifacts over creating new ones",
    "Consolidate related observations into a single change when possible",
    "Only create new artifacts when no existing one covers the topic"
  ]
}

统计模式 (没有未处理的内容):

┌─ ⚔ ──────────────────────────────────────────────────────── Stats ─┐
│ Observations: 12 total, 0 unprocessed                              │
│   rule: 8                                                          │
│   skill: 3                                                         │
│   hook: 1                                                          │
└────────────────────────────────────────────────────────────────────┘

查询模式 (gladiator_reflect query="edit"):

┌─ ⚔ ──────────────────────────────────────────────────────── Found ─┐
│ "edit" -- 4 observations                                           │
│   Edit failed on config.ts -- 3 identical import (2h ago)          │
│   Edit old_string matched wrong function in uti (1d ago)           │
│   Edit succeeded after adding file_path context (3d ago)           │
│   Edit conflict on package.json -- concurrent wr (5d ago)          │
└────────────────────────────────────────────────────────────────────┘

方法论

如何 克劳德角斗士 作品:

gladiator_observe(summary, tags, context)
      │
      ├─ dedup ─── SHA-256(summary) vs last 100 ─── duplicate? → skip
      ├─ classify ─ tags + context → rule | skill | hook | agent
      ├─ recommend  context.after → "Next time: ..."
      └─ append ─── → observations.jsonl


gladiator_reflect(query?, limit?)
      │
      ├─ query? ──────── search all by summary/tags/error → return matches
      │
      ├─ 0 unprocessed ─ return stats: total, by_type, recent 5
      │
      └─ N unprocessed ─┐
          │              │
          ├─ cluster ─── Jaccard(tags) > 0.3 → merge into groups
          │              majority-vote artifact_type per group
          │
          ├─ scan ────── rules/*.md + hooks/* + skills/*/SKILL.md
          │              extract keywords (>3 chars) per artifact
          │
          ├─ score ───── IDF: 1/docFreq(word) per shared keyword
          │              filter words in >40% of artifacts
          │              name match bonus: +5
          │              threshold: >= 3.0 → "update"
          │
          ├─ mark ────── processed = true
          │
          └─ return ──── per cluster: action, targets, observations

核心算法:

设计原则:

  • 两阶段学习 --先观察,后反思;永远不要实时修改工件
  • 更新超过创建 --更喜欢更新现有的规则/钩子/技能,而不是创建新的规则/挂钩/技能
  • 仅附加存储 --JSONL格式,每个观察都是自包含的,从未发生过突变
  • 零依赖 --只有 @modelcontextprotocol/sdk, zod
  • 离线 --永远不要离开你的机器,没有网络呼叫

文件访问:

  • 读/写: ~/.claude/gladiator/observations.jsonl (JSONL,每一行都是一个自包含的JSON对象,包含时间戳、摘要、标签、上下文和处理状态)
  • 扫描(只读): ~/.claude/rules/, ~/.claude/hooks/, ~/.claude/skills/

发展

git clone https://github.com/Vvkmnn/claude-gladiator-mcp && cd claude-gladiator-mcp
npm install && npm run build
npm test

包装要求:

  • Node.js:>=20.0.0(ES模块)
  • 运行时: @modelcontextprotocol/sdk, zod
  • 零外部数据库 --与合作 npx

开发工作流程:

npm run build          # TypeScript compilation with executable permissions
npm run dev            # Watch mode with tsc --watch
npm run start          # Run the MCP server directly
npm run lint           # ESLint code quality checks
npm run lint:fix       # Auto-fix linting issues
npm run format         # Prettier formatting (src/)
npm run format:check   # Check formatting without changes
npm run typecheck      # TypeScript validation without emit
npm run test           # Lint + type check
npm run prepublishOnly # Pre-publish validation (build + lint + format:check)

Git钩子(通过赫斯基):

  • 预承诺:自动格式化已暂存 .ts 使用Prettier和ESLint的文件

贡献:

  • 分叉存储库并创建功能分支
  • 遵循TypeScript严格模式 MCP协议 标准

从示例中学习:

许可证

麻省理工学院


英寸 Verso 通过 让-莱昂·格罗姆 (1872).“Ave Imperator,欢迎你死。” 克劳狄乌斯 回答“不”(或不)。