mcpField
S
self-correction-loop

self-correction-loop

github.com/codewithmukeshAgent 工作流79145 次安装12 周前更新
代码仓库

关于 self-correction-loop

一项帮助 Claude 将用户纠正内容整理为 MEMORY.md 可复用项目规则的技能。它强调将具体修正概括成通用规则,并进行分类、去重和定期回顾,以供后续会话使用。

主要功能

  1. 01识别值得保存的纠正
  2. 02将具体修正概括为通用规则
  3. 03按类别组织规则
  4. 04合并重复或相近的记忆条目
  5. 05定期回顾和审查记忆

适用场景

  1. 01保存项目专属编码规范
  2. 02在新会话中应用以往的修正
  3. 03清理相互矛盾或重复的规则

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/codewithmukesh/dotnet-claude-kit --skill self-correction-loop

安装后在 Claude Code 中输入/self-correction-loop确认已加载。

详细介绍

自我纠正循环

核心原则

  1. 每次纠正都是复利投资 — 今天的一次纠正会花费用户 30 秒,却能在未来所有会话中节省数小时。应将每次纠正视为优先级很高的知识记录,而非一次性修复。

  2. 先归纳,再存储 — “在 Orders 模块中使用 TimeProvider,而不是 DateTime.Now”应归纳为“所有模块中始终使用 TimeProvider,而不是 DateTime.Now/UtcNow。”具体的纠正应转化为类别级规则。

  3. 分类以便检索 — 按类别组织规则(代码风格、架构、命名、测试、数据访问、API 设计、配置、性能),才能方便查找。未分类的规则会被遗忘。

  4. 积极去重 — 添加规则前,先检查现有规则是否有重叠。应更新现有规则,而不是添加近似重复项。记忆膨胀会适得其反。

  5. 在会话开始时查看记忆 — Claude 在新会话中首先应检查 MEMORY.md 中的项目专属规则。记录了知识却从不查看,只会白费功夫。

模式

纠正检测与记录流程

当用户纠正 Claude 的输出时,严格按照以下顺序执行:

1. DETECT — User says something like:
   - "No, use X instead of Y"
   - "We don't do it that way here"
   - "That's wrong, it should be..."
   - "Always/Never do X in this project"
   - "Remember this for next time"

2. ACKNOWLEDGE — Confirm understanding of the correction
   "Got it — using HybridCache instead of IMemoryCache."

3. GENERALIZE — Extract the class-level rule
   Specific: "Don't use IMemoryCache in the Orders endpoint"
   General:  "Always use HybridCache instead of IMemoryCache — it provides
              stampede protection and L1+L2 caching out of the box."

4. CHECK — Scan MEMORY.md for existing related rules
   - If a related rule exists, UPDATE it (broader scope, better wording)
   - If no related rule exists, ADD a new one under the right category

5. STORE — Write to MEMORY.md under the appropriate category

6. CONFIRM — Tell the user what was captured
   "Added to Memory > Data Access: Always use HybridCache over IMemoryCache."
MEMORY.md 组织格式

按类别组织记忆,并采用一致的规则格式:

# Project Memory

## Code Style
- Always use file-scoped namespaces — never block-scoped
- Use primary constructors for DI injection in services and handlers

## Architecture
- This project uses Vertical Slice Architecture — one file per feature operation

## Data Access
- Always use HybridCache over IMemoryCache — stampede protection + L1/L2
- Never use repository pattern over EF Core — use DbContext directly

## Testing
- Integration tests use ApiFixture base class — never raw WebApplicationFactory

使用以下类别:代码风格、架构、命名、数据访问、API 设计、测试、配置、性能。每条规则应占一行,具有可操作性,并在破折号后说明理由。

规则归纳:从具体到类别级

将具体的纠正转化为广泛适用的规则:

SPECIFIC CORRECTION:
"Don't use DateTime.Now in the CreateOrder handler"

GENERALIZATION STEPS:
1. Is this specific to CreateOrder? → No, it's a .NET-wide concern
2. Is this specific to handlers? → No, applies everywhere
3. What's the underlying principle? → TimeProvider is testable, DateTime is not
4. What's the broadest correct statement?

GENERALIZED RULE:
"Always use TimeProvider instead of DateTime.Now/UtcNow — TimeProvider is
injectable and testable. This applies to all production code."
定期审查记忆

每隔 5-10 次会话(或记忆超过 50 条规则时),审查规则质量:

AUDIT CHECKLIST:
1. Remove rules that contradict each other — keep the most recent
2. Merge rules that overlap — combine into a single, clearer rule
3. Remove rules that are now obvious (e.g., captured early but now second nature)
4. Verify rules are still accurate — .NET evolves, patterns change
5. Check that categories are balanced — a category with 20+ rules needs subcategories
会话开始时查看记忆

在会话开始时,阅读 MEMORY.md 并主动应用相关规则。对于已经记录的规则,不要等到别人提醒才遵循。

反模式

忽略纠正
// BAD — user corrects, Claude fixes but doesn't capture
User: "No, we use HybridCache here, not IMemoryCache"
Claude: "Fixed. Here's the updated code with HybridCache..."
*Next session: makes the same mistake*

// GOOD — fix AND capture
User: "No, we use HybridCache here, not IMemoryCache"
Claude: "Fixed. Here's the updated code with HybridCache.
         Added to Memory > Data Access: Always use HybridCache over IMemoryCache."
*Next session: checks memory, uses HybridCache from the start*
规则过于具体
// BAD — rule is too narrow to be useful
"In the CreateOrder handler on line 47, use TimeProvider"

// GOOD — generalized to apply broadly
"Always use TimeProvider instead of DateTime.Now/UtcNow in all production code"
从不查看记忆
// BAD — 50 rules captured, none ever reviewed
MEMORY.md grows to 200 lines, contains duplicates and contradictions,
Claude doesn't read it because it's too long to be useful

// GOOD — periodic audit keeps memory lean and accurate
MEMORY.md stays under 80 rules, well-categorized, no duplicates,
Claude reads it at session start and applies rules proactively
存储仅适用于当前会话的上下文
// BAD — temporary state saved as permanent memory
"Currently working on the Orders module refactor, file is at src/Orders/Handler.cs"

// GOOD — only permanent, reusable knowledge
"The Orders module uses VSA with one file per feature under Features/"

决策指南

情况操作
用户明确纠正 Claude 的代码在 MEMORY.md 中记录归纳后的规则
用户说“记住这一点”或“始终/绝不”按原话记录,如有可能则进一步归纳
同一项纠正出现两次优先级高 — 该规则尚未记录或尚未查看
纠正与项目相关在 MEMORY.md 中结合项目上下文存储
纠正适用于所有 .NET 项目存储在 MEMORY.md 中 — 它也适用于当前项目
MEMORY.md 超过 50 条规则启动审查 — 去重、合并、删减
开始新会话编写任何代码前先查看 MEMORY.md
规则与现有规则矛盾保留最新的纠正,删除旧规则
纠正只针对一次性任务不要存储 — 只记录可复用的模式
用户要求忘记某条规则立即从 MEMORY.md 中删除
观察到某种模式,但尚未确认使用 instinct-system skill 创建一个直觉(置信度 0.3),而不是添加 MEMORY.md 规则
直觉达到 0.9 置信度将其提升为 MEMORY.md 中的永久规则(参见 instinct-system skill)

评论

支持 Markdown