Communitygithub.com

持续学习 v2.1 - 基于本能的架构

一种基于本能的系统,通过钩子观察会话,创建带置信度评分的原子化本能,并将其演化为技能/命令/智能体。v2.1 新增项目作用域本能,防止跨项目污染。

持续学习 v2.1 - 基于本能的架构 是什么?

此技能将 Claude Code 会话转化为可重用的知识,通过“本能”(带有置信度评分的小型学习行为)实现。它通过 PreToolUse/PostToolUse 钩子以确定性方式观察每次工具调用,提取模式,并将它们组织为原子化的 yaml 文件。v2.1 的关键创新是项目作用域本能:React 模式保留在 React 项目中,Python 约定保留在 Python 项目中,而像“始终验证输入”这样的通用模式则全局共享。这消除了跨项目污染,无需手动隔离。该系统同时支持 CLI 命令(如 `/instinct-status`、`/evolve`)和一个可选的背景观察代理,用于自动分析。它与 Claude Code 和 Cursor 等平台兼容,其观察代理需要 WSL2、Linux 或 macOS。该技能支持导出/导入本能,促进协作,并允许将项目级本能提升为全局级。

兼容平台✓Claude Code~Codex CLI~Cursor
npx skills add https://github.com/affaan-m/ECC/tree/main/skills/continuous-learning-v2

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

持续学习 v2.1 - 基于本能的架构 是做什么的?

一个先进的学习系统,通过原子化的“本能”(带有置信度评分的小型学习行为)将你的 Claude Code 会话转化为可重用的知识。

v2.1 新增了项目作用域本能——React 模式保留在你的 React 项目中,Python 约定保留在你的 Python 项目中,而通用模式(如“始终验证输入”)则全局共享。

何时激活

  • 设置从 Claude Code 会话自动学习
  • 通过钩子配置基于本能的行为提取
  • 调整学习行为的置信度阈值
  • 审查、导出或导入本能库
  • 将本能演化为完整的技能、命令或智能体
  • 管理项目作用域与全局本能
  • 将本能从项目作用域提升到全局作用域

v2.1 更新内容

特性v2.0v2.1
存储全局 (~/.claude/homunculus/)项目作用域 (${XDG_DATA_HOME:-~/.local/share}/ecc-homunculus/projects/<hash>/)
作用域所有本能适用于所有地方项目作用域 + 全局
检测无git 远程 URL / 仓库路径
提升不适用当在 2 个以上项目中出现时,项目 → 全局
命令4 (status/evolve/export/import)6 (+promote/projects)
跨项目存在污染风险默认隔离

v2 (对比 v1) 更新内容

特性v1v2
观察停止钩子(会话结束)PreToolUse/PostToolUse(100% 可靠)
分析主上下文后台智能体 (Haiku)
粒度完整技能原子化“本能”
置信度无0.3-0.9 加权
演化直接到技能本能 -> 聚类 -> 技能/命令/智能体
共享无导出/导入本能

本能模型

本能是一种小型学习行为:

---
id: prefer-functional-style
trigger: "when writing new functions"
confidence: 0.7
domain: "code-style"
source: "session-observation"
scope: project
project_id: "a1b2c3d4e5f6"
project_name: "my-react-app"
---

# 偏好函数式风格

## 动作

在适当时使用函数式模式而非类模式。

## 证据

- 观察到 5 个函数式模式偏好实例
- 用户于 2025-01-15 将基于类的方法纠正为函数式

属性:

  • 原子化——一个触发条件,一个动作
  • 置信度加权——0.3 = 试探性,0.9 = 近乎确定
  • 领域标记——code-style, testing, git, debugging, workflow 等。
  • 有据可查——追踪哪些观察产生了它
  • 作用域感知——project(默认)或 global

工作原理

会话活动 (在 git 仓库中)
      |
      | 钩子捕获提示 + 工具使用(100% 可靠)
      | + 检测项目上下文 (git 远程 / 仓库路径)
      v
+---------------------------------------------+
|  projects/<project-hash>/observations.jsonl  |
|   (提示词, 工具调用, 结果, 项目)           |
+---------------------------------------------+
      |
      | 观察者智能体读取 (后台, Haiku)
      v
+---------------------------------------------+
|          模式检测                            |
|   * 用户纠正 -> 本能                         |
|   * 错误解决 -> 本能                         |
|   * 重复工作流 -> 本能                       |
|   * 作用域决定: 项目还是全局?               |
+---------------------------------------------+
      |
      | 创建/更新
      v
+---------------------------------------------+
|  projects/<project-hash>/instincts/personal/ |
|   * prefer-functional.yaml (0.7) [项目]       |
|   * use-react-hooks.yaml (0.9) [项目]         |
+---------------------------------------------+
|  instincts/personal/  (全局)                 |
|   * always-validate-input.yaml (0.85) [全局] |
|   * grep-before-edit.yaml (0.6) [全局]       |
+---------------------------------------------+
      |
      | /evolve 聚类 + /promote
      v
+---------------------------------------------+
|  projects/<hash>/evolved/ (项目作用域)       |
|  evolved/ (全局)                             |
|   * commands/new-feature.md                  |
|   * skills/testing-workflow.md               |
|   * agents/refactor-specialist.md            |
+---------------------------------------------+

项目检测

系统自动检测你的当前项目:

  1. CLAUDE_PROJECT_DIR 环境变量(最高优先级)—— 即使该目录不是 git 仓库(通过其绝对路径进行哈希),也会被作为显式覆盖尊重。
  2. git remote get-url origin —— 哈希以创建可移植的项目 ID(同一仓库在不同机器上获得相同 ID)
  3. git rev-parse --show-toplevel —— 使用仓库路径作为备选方案(特定于机器)
  4. 全局备选方案 —— 如果未检测到项目,本能归入全局作用域

每个项目获得一个 12 字符的哈希 ID(例如,a1b2c3d4e5f6)。注册表文件位于 ${XDG_DATA_HOME:-~/.local/share}/ecc-homunculus/projects.json,将 ID 映射到人类可读的名称。

数据目录

Continuous-learning-v2 将观察者数据存储在 ~/.claude 之外,这样 Claude Code 的敏感路径防护就不会阻止后台本能的写入:

  1. 设置 CLV2_HOMUNCULUS_DIR 为绝对路径
  2. $XDG_DATA_HOME/ecc-homunculus
  3. $HOME/.local/share/ecc-homunculus

数据仍在 ~/.claude/homunculus 的现有用户可以一次性迁移:

bash skills/continuous-learning-v2/scripts/migrate-homunculus.sh

快速入门

1. 启用观察钩子

如果作为插件安装(推荐):

无需额外的 settings.json 钩子块。Claude Code v2.1+ 会自动加载插件的 hooks/hooks.json,并且 observe.sh 已在那里注册。

如果你先前将 observe.sh 复制到了 ~/.claude/settings.json,请删除那个重复的 PreToolUse / PostToolUse 块。重复的插件钩子会导致双重执行以及 ${CLAUDE_PLUGIN_ROOT} 解析错误,因为该变量仅在插件管理的 hooks/hooks.json 条目中可用。

如果手动安装到 ~/.claude/skills,请将此添加到你的 ~/.claude/settings.json:

{
  "hooks": {
    "PreToolUse": [{
      "matcher": "*",
      "hooks": [{
        "type": "command",
        "command": "~/.claude/skills/continuous-learning-v2/hooks/observe.sh"
      }]
    }],
    "PostToolUse": [{
      "matcher": "*",
      "hooks": [{
        "type": "command",
        "command": "~/.claude/skills/continuous-learning-v2/hooks/observe.sh"
      }]
    }]
  }
}

2. 初始化目录结构

系统会在首次使用时自动创建目录,但你也可以手动创建它们:

# 全局目录
mkdir -p "${XDG_DATA_HOME:-$HOME/.local/share}/ecc-homunculus"/{instincts/{personal,inherited},evolved/{agents,skills,commands},projects}

# 项目目录会在钩子首次在 git 仓库中运行时自动创建

3. 使用本能命令

/instinct-status     # 显示已学习的本能(项目 + 全局)
/evolve              # 将相关的本能聚类为技能/命令
/instinct-export     # 导出本能到文件
/instinct-import     # 从他人处导入本能
/promote             # 将项目本能提升到全局作用域
/projects            # 列出所有已知项目及其本能数量

命令

命令描述
/instinct-status显示所有本能(项目作用域 + 全局),带置信度
/evolve将相关本能聚类为技能/命令,建议提升
/instinct-export导出本能(可按作用域/领域过滤)
/instinct-import <file>导入本能,带作用域控制
/promote [id]将项目本能提升到全局作用域
/projects列出所有已知项目及其本能数量

配置

编辑 config.json 以控制后台观察者:

{
  "version": "2.1",
  "observer": {
    "enabled": false,
    "run_interval_minutes": 5,
    "min_observations_to_analyze": 20
  }
}
键默认值描述
observer.enabledfalse启用后台观察者智能体
observer.run_interval_minutes5观察者分析观察数据的频率
observer.min_observations_to_analyze20分析运行前所需的最小观察数

其他行为(观察捕获、本能阈值、项目作用域、提升标准)通过 instinct-cli.py 和 observe.sh 中的代码默认值进行配置。

观察者平台支持

后台观察者需要 WSL2、Linux 或 macOS。在原生 Windows(Git Bash / MSYS2)上,它会启动并报告成功,但当生成它的钩子退出且其作业对象关闭时,进程会被终止,因此不会运行任何分析——在那里设置 observer.enabled: true 实际上是空操作(见 issue #2489)。

observe.sh 会在后续钩子调用时检测到这一点,并在观察者连续多次未能存活后,将一条解释性警告写入 observer-start.log。

环境变量默认值描述
ECC_OBSERVER_NOSURVIVE_WARN_AFTER3记录警告前的连续非存活次数

文件结构

${XDG_DATA_HOME:-~/.local/share}/ecc-homunculus/
+-- identity.json           # 你的个人资料、技术等级
+-- projects.json           # 注册表: 项目哈希 -> 名称/路径/远程
+-- observations.jsonl      # 全局观察(备选方案)
+-- instincts/
|   +-- personal/           # 全局自动学习的本能
|   +-- inherited/          # 全局导入的本能
+-- evolved/
|   +-- agents/             # 全局生成的智能体
|   +-- skills/             # 全局生成的技能
|   +-- commands/           # 全局生成的命令
+-- projects/
    +-- a1b2c3d4e5f6/       # 项目哈希(来自 git 远程 URL)
    |   +-- project.json    # 每个项目的元数据镜像 (id/name/root/remote)
    |   +-- observations.jsonl
    |   +-- observations.archive/
    |   +-- instincts/
    |   |   +-- personal/   # 项目特定的自动学习
    |   |   +-- inherited/  # 项目特定的导入
    |   +-- evolved/
    |       +-- skills/
    |       +-- commands/
    |       +-- agents/
    +-- f6e5d4c3b2a1/       # 另一个项目
        +-- ...

作用域决策指南

模式类型作用域示例
语言/框架约定项目"使用 React 钩子", "遵循 Django REST 模式"
文件结构偏好项目"测试放在 __tests__/ 中", "组件放在 src/components/"
代码风格项目"使用函数式风格", "偏好 dataclasses"
错误处理策略项目"对错误使用 Result 类型"
安全实践全局"验证用户输入", "清理 SQL"
通用最佳实践全局"先写测试", "始终处理错误"
工具工作流偏好全局"编辑前先 grep", "写入前先读取"
Git 实践全局"约定式提交", "小而专注的提交"

本能提升(项目 -> 全局)

当同一本能以高置信度出现在多个项目中时,它就有资格提升到全局作用域。

自动提升标准:

  • 在 2 个或更多项目中存在相同的本能 ID
  • 平均置信度 >= 0.8

如何提升:

# 提升特定本能
python3 instinct-cli.py promote prefer-explicit-errors

# 自动提升所有符合条件的本能
python3 instinct-cli.py promote

# 预览更改而不执行
python3 instinct-cli.py promote --dry-run

/evolve 命令也会建议提升候选。

置信度评分

置信度随时间演变:

分数含义行为
0.3试探性建议但非强制
0.5适中在相关时应用
0.7强自动批准应用
0.9近乎确定核心行为

置信度增加当:

  • 模式被重复观察
  • 用户未纠正建议的行为
  • 来自其他来源的类似本能一致

置信度减少当:

  • 用户明确纠正了该行为
  • 长时间未观察到该模式
  • 出现矛盾证据

为什么使用钩子而非技能进行观察?

“v1 依赖技能进行观察。技能是概率性的——它们根据 Claude 的判断,约 50-80% 的时间触发。”

钩子100% 的时间确定性触发。这意味着:

  • 每次工具调用都被观察到
  • 没有模式被遗漏
  • 学习是全面的

向后兼容性

v2.1 完全兼容 v2.0 和 v1:

  • 现有的全局本能可以使用 scripts/migrate-homunculus.sh 从 ~/.claude/homunculus/instincts/ 迁移
  • 来自 v1 的现有 ~/.claude/skills/learned/ 技能仍然可用
  • 停止钩子仍然运行(但现在也会输入到 v2)
  • 逐步迁移:两者并行运行

隐私

  • 观察数据本地存储在你的机器上
  • 项目作用域的本能按项目隔离
  • 仅本能(模式)可以导出——而不是原始观察数据
  • 不会共享任何实际代码或对话内容
  • 你控制哪些内容被导出和提升

相关资源

  • ECC-Tools GitHub App - 从仓库历史生成本能
  • Homunculus - 启发了 v2 本能驱动架构(原子观察、置信度评分、本能演化管道)的社区项目
  • 长篇指南 - 持续学习部分

基于本能的学习:教 Claude 你的模式,一个项目接一个项目。

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

accessibility

Design, implement, and audit inclusive digital products using WCAG 2.2 Level AA. Use when building or auditing UI that must meet WCAG 2.2 Level AA, or when reviewing a change for keyboard, contrast, or screen-reader support.

affaan-m/content-engine

Create platform-native content systems for X, LinkedIn, TikTok, YouTube, newsletters, and repurposed multi-platform campaigns. Use when the user wants social posts, threads, scripts, content calendars, or one source asset adapted cleanly across platforms.

affaan-m/ECC

Multi-platform content distribution across X, LinkedIn, Threads, and Bluesky. Adapts content per platform using content-engine patterns. Never posts identical content cross-platform. Use when the user wants to distribute content across social platforms.

affaan-m/fal-ai-media

Unified media generation via fal.ai MCP — image, video, and audio. Covers text-to-image (Nano Banana), text/image-to-video (Seedance, Kling, Veo 3), text-to-speech (CSM-1B), and video-to-audio (ThinkSound). Use when the user wants to generate images, videos, or audio with AI.

affaan-m/manim-video

日本語翻訳:このファイルは manim-video 用の日本語翻訳が必要です

affaan-m/remotion-video-creation

Remotion のベストプラクティス - React で動画を作成する。3D、アニメーション、音声、字幕、チャート、トランジションなどをカバーするドメイン固有の29のルール。

affaan-m/video-editing

AI-assisted video editing workflows for cutting, structuring, and augmenting real footage. Covers the full pipeline from raw capture through FFmpeg, Remotion, ElevenLabs, fal.ai, and final polish in Descript or CapCut. Use when the user wants to edit video, cut footage, create vlogs, or build video content.

agent-architecture-audit

Full-stack diagnostic for agent and LLM applications. Audits the 12-layer agent stack for wrapper regression, memory pollution, tool discipline failures, hidden repair loops, and rendering corruption. Produces severity-ranked findings with code-first fixes. Essential for developers building agent applications, autonomous loops, or any LLM-powered feature. Use when an agent or LLM feature misbehaves and the failing layer is unknown, or before shipping an agent stack.

agent-eval

Head-to-head comparison of coding agents (Claude Code, Aider, Codex, etc.) on custom tasks with pass rate, cost, time, and consistency metrics. Use when choosing between coding agents, or when a change to an agent setup needs measured pass rate, cost, and time rather than an impression.

agent-harness-construction

Design and optimize AI agent action spaces, tool definitions, and observation formatting for higher completion rates. Use when defining or revising an agent

agentic-engineering

Operate as an agentic engineer using eval-first execution, decomposition, and cost-aware model routing. Use when planning or executing engineering work that agents will carry out end to end.

agentic-os

Build persistent multi-agent operating systems on Claude Code. Covers kernel architecture, specialist agents, slash commands, file-based memory, scheduled automation, and state management without external databases. Use when building a persistent multi-agent system on Claude Code with its own memory, commands, and scheduling.

agent-introspection-debugging

Structured self-debugging workflow for AI agent failures using capture, diagnosis, contained recovery, and introspection reports. Use when an agent run fails and you need a reproducible diagnosis instead of a retry.

agent-payment-x402

Add x402 payment execution to AI agents with per-task budgets, spending controls, and non-custodial wallets. Supports Base through agentwallet-sdk and X Layer through OKX Payments / OKX Agent Payments Protocol. Use when an agent must pay for something itself and needs per-task budgets, spending controls, and a non-custodial wallet.

agent-self-evaluation

Use after completing any non-trivial task. The agent self-rates its output on 5 axes — accuracy, completeness, clarity, actionability, conciseness — with concrete evidence per criterion. Produces a structured 1-5 scorecard with specific improvement suggestions.

agent-sort

Build an evidence-backed ECC install plan for a specific repo by sorting skills, commands, rules, hooks, and extras into DAILY vs LIBRARY buckets using parallel repo-aware review passes. Use when ECC should be trimmed to what a project actually needs instead of loading the full bundle.

ai-first-engineering

Engineering operating model for teams where AI agents generate a large share of implementation output. Use when setting team process, review gates, or ownership rules for a codebase largely written by agents.

ai-regression-testing

Regression testing strategies for AI-assisted development. Sandbox-mode API testing without database dependencies, automated bug-check workflows, and patterns to catch AI blind spots where the same model writes and reviews code. Use when adding regression coverage to AI-assisted code, or when the same model both wrote and reviewed a change.

android-clean-architecture

Clean Architecture patterns for Android and Kotlin Multiplatform projects — module structure, dependency rules, UseCases, Repositories, and data layer patterns. Use when structuring modules, layers, or data flow in an Android or KMP project.

angular-developer

Generates Angular code and provides architectural guidance. Trigger when creating projects, components, or services, or for best practices on reactivity (signals, linkedSignal, resource), forms, dependency injection, routing, SSR, accessibility (ARIA), animations, styling (component styles, Tailwind CSS), testing, or CLI tooling.

相关技能