关于 metacognitive-self-mod
用于分析过往 Skill 改进成效并优化改进流程的 Skill。它依据改进记忆和性能趋势归纳模式,并向 skill-improver 提出策略调整建议。
主要功能
- 01将结果分类为有效、中性或退步
- 02分析改进记忆与性能趋势
- 03记录因果假设和元洞见
- 04提出需用户批准的策略调整
适用场景
- 01调查 Skill 改进导致的退步
- 02在多轮改进后评估成效
- 03依据观察结果调整 skill-improver 策略
安装
复制下面的命令,在终端中运行。
npx skills add https:/ / github.com/ athola/ claude-night-market --skill metacognitive-self-mod安装后在 Claude Code 中输入/metacognitive-self-mod确认已加载。
附带文件modules/trace-capture.md
详细介绍
元认知式自我改进
概述
分析以往技能改进的成效,并完善改进流程本身。这是 Hyperagents 论文中的核心创新:不仅改进技能,还改进技能的改进方式。
上下文触发条件(自动调用)
在以下情况下应自动调用此技能:
-
检测到回归:稳态监控器发现某个技能的评估窗口以
pending_rollback_review状态结束。改进导致情况变差,我们需要弄清原因。 -
成效率低:当
ImprovementMemory.get_effective_strategies()与get_failed_strategies()的对比显示成效低于 50% 时,改进流程本身需要完善。 -
改进后仍然退化:当
PerformanceTracker.get_improvement_trend()对某个近期改进过的技能返回负值时。 -
定期检查:每完成 10 个改进周期后(通过 ImprovementMemory 中的结果计数跟踪)。
Hook 集成
当某个技能超过标记阈值时,稳态监控器会发出 "improvement_triggered": true。此时,在分派 skill-improver 之前,检查是否需要进行元认知分析:
from abstract.improvement_memory import ImprovementMemory
from pathlib import Path
memory = ImprovementMemory(Path.home() / ".claude/skills/improvement_memory.json")
# Check if metacognitive analysis is warranted
effective = memory.get_effective_strategies()
failed = memory.get_failed_strategies()
total = len(effective) + len(failed)
needs_metacognition = False
# Trigger 1: Low effectiveness rate
if total >= 5 and len(effective) / total < 0.5:
needs_metacognition = True
# Trigger 2: Periodic check (every 10 outcomes)
if total > 0 and total % 10 == 0:
needs_metacognition = True
# Trigger 3: Recent regression
if failed and failed[-1].get("outcome_type") == "failure":
needs_metacognition = True
if needs_metacognition:
# Run metacognitive analysis before next improvement
pass # Skill(abstract:metacognitive-self-mod)
适用场景(手动)
- 完成一批技能改进后,评估哪些做法有效
- 改进结果出现回归时
- 定期(每月)完善改进策略
- skill-improver Agent 似乎不起作用时
不适用场景
- 常规技能改进(直接使用 skill-improver)
- 首次创建技能(使用 skill-authoring)
工作流
步骤 1:加载改进数据
读取改进记忆和性能跟踪器数据:
# Check for improvement memory
MEMORY_FILE=~/.claude/skills/improvement_memory.json
TRACKER_FILE=~/.claude/skills/performance_history.json
if [ ! -f "$MEMORY_FILE" ]; then
echo "No improvement memory found."
echo "Run skill-improver first to generate improvement data."
exit 0
fi
使用 Python 加载 JSON 文件:
from abstract.improvement_memory import ImprovementMemory
from abstract.performance_tracker import PerformanceTracker
from pathlib import Path
memory = ImprovementMemory(Path.home() / ".claude/skills/improvement_memory.json")
tracker = PerformanceTracker(Path.home() / ".claude/skills/performance_history.json")
步骤 2:对改进结果分类
对记忆中的每项改进结果进行分类:
- 有效:
after_score - before_score >= 0.1 - 中性:
-0.1 < improvement < 0.1 - 回归:
after_score < before_score
effective = memory.get_effective_strategies()
failed = memory.get_failed_strategies()
# Calculate effectiveness rate
total = len(effective) + len(failed)
if total > 0:
effectiveness_rate = len(effective) / total
步骤 3:提取元模式
分析哪些类型的改进成功,哪些失败:
值得关注的成功模式:
- 添加错误处理(降低失败率)
- 添加示例(提升用户评分)
- 添加安静/详细模式(减少阻碍)
- 简化工作流步骤(缩短耗时)
值得关注的失败模式:
- 过度设计(添加选项过多)
- 破坏现有工作流(导致回归)
- 增加复杂性却不进行验证
- 因添加过多详细内容导致 token 预算超限
对于发现的每种模式,将其记录为因果假设:
memory.record_insight(
skill_ref="_meta", # Special ref for meta-insights
category="causal_hypothesis",
insight="Error handling improvements have 85% success rate",
evidence=["skill-A v1.1.0: +0.3", "skill-B v2.1.0: +0.15"],
)
步骤 4:分析改进趋势
使用 PerformanceTracker 识别:
- 持续改进的技能(正向趋势)
- 尽管尝试改进仍在退化的技能
- 改进最有效的领域
for skill_ref in tracker.get_all_skill_refs():
trend = tracker.get_improvement_trend(skill_ref)
if trend is not None:
if trend > 0.05:
# Sustained improvement - what's working?
pass
elif trend < -0.05:
# Degrading despite improvements - investigate
pass
步骤 5:生成策略建议
根据元分析,为 skill-improver 生成建议:
-
调整优先级公式:如果某些问题类型的改进成功率较高,应提高其权重。
-
选择改进方法:如果“添加错误处理”的成功率为 85%,而“重构工作流”仅为 30%,则应优先采用错误处理。
-
调整阈值:如果优先级低于 3.0 的改进总是失败,应提高最低阈值。
-
规避规则:记录未来改进中应避免的反模式。
步骤 6:存储元洞见
将所有发现记录回 ImprovementMemory 中的特殊 _meta 技能引用:
# Record strategy recommendation
memory.record_insight(
skill_ref="_meta",
category="strategy_success",
insight="Recommendation: Prioritize error handling and examples over restructuring",
evidence=[f"Success rate: error_handling={eh_rate:.0%}, restructure={rs_rate:.0%}"],
)
第 7 步:更新 skill-improver 策略
如果发现了重要的元洞察,请针对 skill-improver Agent 提出具体修改建议:
- 更新优先级公式中的权重
- 为已知反模式添加规避规则
- 根据实证数据调整阈值
- 添加经验证有效的新改进模式
重要:只提出修改建议,不要自动应用。用户必须批准对改进流程的修改。
输出
Metacognitive Self-Modification Report
Improvement Data:
Total outcomes analyzed: 15
Effective improvements: 11 (73%)
Regressions: 2 (13%)
Neutral: 2 (13%)
Success Patterns:
1. Error handling additions: 5/6 success (83%)
2. Example additions: 3/3 success (100%)
3. Quiet mode additions: 2/2 success (100%)
Failure Patterns:
1. Workflow restructuring: 1/3 success (33%)
2. Token-heavy additions: 0/1 success (0%)
Performance Trends:
Improving: 8 skills (positive trend)
Stable: 4 skills (no trend)
Degrading: 1 skill (negative trend despite attempts)
Recommendations:
1. Weight error handling improvements 2x in priority
2. Avoid workflow restructuring below priority 8.0
3. Cap additions at 200 tokens to prevent budget overflow
4. Focus next improvement cycle on degrading skill X
Meta-insights stored: 5 new entries in improvement memory
相关内容
abstract:skill-improver- 此技能分析并为其提出修改建议的 Agentabstract:skills-eval- 可根据元洞察细化其评估标准的评估框架abstract:aggregate-logs- 改进指标的数据来源
退出标准
- 元认知报告列出分析的结果总数(有效/回退/中性),数据来源为
~/.claude/skills/improvement_memory.json。 - 在
improvement_memory.json的skill_ref: "_meta"下记录至少一个因果假设,并引用证据(技能引用和分数变化)。 - 任何 Tier 3 策略建议(修改 skill-improver 优先级权重、添加规避规则、调整阈值)都必须作为提案呈现,并且在应用任何更改前需要获得用户明确批准。
- 如果在 5 个或更多结果中,有效率低于 50%,则应在报告输出中将此情况列为主要触发原因。