firm-hebbian-memory
⚠️ Contenu généré par IA — validation humaine requise avant déploiement en production.
Purpose
Ce skill rend le Claude.md vivant et auto-évolutif via des mécanismes inspirés
de la plasticité synaptique hebbienne. Les patterns de travail qui se répètent sont
renforcés, ceux qui deviennent obsolètes s'atrophient naturellement.
Inspiration neurobiologique :
- - Plasticité hebbienne → renforcement des poids Layer 2 par co-activation
- Mémoire hippocampique → stockage épisodique en base vectorielle (pgvector)
- Consolidation néocorticale → job d'analyse transformant les épisodes en schémas
Architecture — 4 couches Claude.md (CDC §3.3)
| Couche | Nom | Modification |
|---|
| Layer 1 | CORE (immuable) | Humain uniquement |
| Layer 2 |
CONSOLIDATED PATTERNS | Auto-mise à jour (poids hebbiens) |
| Layer 3 | EPISODIC INDEX | Auto-mise à jour (pointeurs sessions) |
| Layer 4 | META INSTRUCTIONS | Lecture seule pour le système auto |
Tools activés (8 tools)
Runtime (2 tools)
CODEBLOCK0
Audit (6 tools)
CODEBLOCK1
Formule de mise à jour des poids (CDC §4.3)
CODEBLOCK2
Seuils de consolidation
| Transition | Condition |
|---|
| Épisodique → Émergent | Activé 5 sessions consécutives |
| Émergent → Fort |
poids > 0.8 sur 20 sessions |
| Fort → CORE |
Validation humaine obligatoire |
| Atrophie → Suppression | poids < 0.10 pendant 4 semaines + PR humaine |
Sécurité (CDC §5.2)
- - PII stripping obligatoire : regex sur emails, phones, IPs, API keys, SSN, JWT, AWS keys, chemins Unix home
- Secrets détectés : session rejetée + alerte immédiate
- Accès BDD : localhost/VPN uniquement
- Rotation embeddings : policy de ré-embedding si fuite suspectée
- Réversibilité : chaque modification = 1 commit Git atomique
- Path whitelist : configurable via
HEBBIAN_ALLOWED_DIRS (env) — protège containers/multi-user
Limitations connues (PII)
Le stripping regex couvre les catégories les plus courantes (10 patterns) mais ne
détecte pas les credentials embarqués dans des URLs de connexion (e.g.
postgres://user:password@host/db) ni les variables d'environnement loguées dans
des stack traces (DB_URL=...). Un scanner de secrets dédié (e.g. trufflehog,
detect-secrets) est recommandé en complément pour les environnements à haute
sensibilité.
Anti-dérive (CDC §5.1)
- - Aucune règle ne peut atteindre poids = 1.0 automatiquement (max 0.95)
- Détecteur de drift : alerte si cosine similarity vs baseline < 0.7
- 3 changements auto consécutifs → review forcée
- Snapshot mensuel archivé en Git tag
Pipeline global
CODEBLOCK3
Hook post-session (MVP)
Sans hook automatique, l'ingestion reste manuelle — adoption = zéro.
Voici le minimum pour boucler le pipeline dès le MVP.
Option A — Script shell (le plus simple)
Créer ~/.openclaw/hooks/post-session.sh :
CODEBLOCK4
Option B — Entrée cron (automatisation passive)
CODEBLOCK5
Option C — Intégration pi-coding-agent
Si le projet utilise pi-coding-agent, ajouter dans sa config :
CODEBLOCK6
Note : Le hook ne déclenche que le harvest (lecture). La mise à jour
des poids (weight_update) reste toujours manuelle avec dry_run=True par
défaut — conformément à la règle absolue n°1 du CDC.
Adaptation OpenClaw
| Composant CDC | Adaptation OpenClaw |
|---|
| Hook post-session | Lecture fichiers .jsonl de INLINECODE11 |
| Claude.md Layer 2 |
Skills OpenClaw (
.md ou
.json) |
| Claude.md Layer 4 | Extension
pi-coding-agent dédiée |
| GitHub PR for review | PR sur repo privé skills |
| Secrets stripping |
Renforcé — 9 patterns regex + détection runtime |
Configuration requise
CODEBLOCK7
Référence
- - CDC :
cahier_des_charges_memoire_hebbienne.md v1.0.0 - Module : INLINECODE16
- Modèles : 8 classes Pydantic dans INLINECODE17
💎 Support
Si ce skill vous est utile, vous pouvez soutenir le développement :
Dogecoin : INLINECODE18
firm-hebbian-memory
⚠️ AI生成内容 — 部署到生产环境前需要人工验证。
目的
该技能通过受赫布突触可塑性启发的机制,使Claude.md保持活跃并自我进化。重复的工作模式会得到强化,而过时的模式则会自然萎缩。
神经生物学灵感:
- - 赫布可塑性 → 通过共激活强化第2层权重
- 海马体记忆 → 在向量数据库(pgvector)中存储情景记忆
- 新皮层巩固 → 分析任务将情景转化为模式
架构 — Claude.md 4层结构(CDC §3.3)
| 层 | 名称 | 修改方式 |
|---|
| 第1层 | 核心层(不可变) | 仅由人类修改 |
| 第2层 |
已巩固模式 | 自动更新(赫布权重) |
| 第3层 | 情景索引 | 自动更新(会话指针) |
| 第4层 | 元指令 | 对自动系统为只读 |
已启用的工具(8个工具)
运行时(2个工具)
openclawhebbianharvest — 摄取JSONL会话日志 → SQLite(已脱敏)
openclawhebbianweight_update — 计算/应用赫布权重(默认试运行)
审计(6个工具)
openclawhebbiananalyze — 分析共激活模式(Jaccard系数)
openclawhebbianstatus — 权重、萎缩、晋升仪表盘
openclawhebbianlayer_validate — 验证4层结构
openclawhebbianpii_check — 审计PII脱敏配置
openclawhebbiandecayconfigcheck — 验证赫布参数
openclawhebbiandrift_check — 检测语义漂移与基线的差异
权重更新公式(CDC §4.3)
python
新权重 = 旧权重 + (学习率 × 激活值) - (衰减 × (1 - 激活值))
默认参数
学习率 = 0.05 # 激活时强化
衰减 = 0.02 # 未激活时萎缩
最小权重 = 0.0 # 下限 — 低于0.10则删除
最大权重 = 0.95 # 上限 — 高于0.95则晋升至核心层
巩固阈值
| 转换 | 条件 |
|---|
| 情景 → 新兴 | 连续5个会话激活 |
| 新兴 → 强 |
20个会话中权重 > 0.8 |
| 强 → 核心 |
必须人工验证 |
| 萎缩 → 删除 | 权重 < 0.10持续4周 + 人工PR |
安全性(CDC §5.2)
- - 强制PII脱敏:对邮箱、电话、IP、API密钥、SSN、JWT、AWS密钥、Unix home路径进行正则脱敏
- 检测到机密:拒绝会话 + 立即告警
- 数据库访问:仅限localhost/VPN
- 嵌入轮换:怀疑泄露时重新嵌入的策略
- 可逆性:每次修改 = 1个原子Git提交
- 路径白名单:可通过HEBBIANALLOWEDDIRS(环境变量)配置 — 保护容器/多用户环境
已知限制(PII)
正则脱敏覆盖最常见的类别(10种模式),但无法检测嵌入在连接URL中的凭据(例如postgres://user:password@host/db),也无法检测在堆栈跟踪中记录的环境变量(DB_URL=...)。对于高敏感度环境,建议额外使用专用机密扫描器(例如trufflehog、detect-secrets)。
防漂移(CDC §5.1)
- - 任何规则都无法自动达到权重 = 1.0(最高0.95)
- 漂移检测器:如果余弦相似度与基线相比 < 0.7则告警
- 连续3次自动更改 → 强制审查
- 每月快照以Git标签存档
全局流程
[ Claude Code会话 ]
↓ 会话结束
[ openclawhebbianharvest ] → 提取摘要 + 标签 + 规则(已脱敏)
↓
[ 本地SQLite ] → 结构化情景存储
↓
[ openclawhebbiananalyze ] → Jaccard聚类 + 共激活分析
↓
[ openclawhebbianweight_update ] → 更新第2层(试运行=True)
↓
[ 人工审查 ] → 应用前验证(试运行=False)
会话后钩子(MVP)
如果没有自动钩子,摄取仍需手动操作 — 采用率为零。
以下是最小MVP所需的完整流程。
选项A — Shell脚本(最简单)
创建~/.openclaw/hooks/post-session.sh:
bash
#!/usr/bin/env bash
会话后钩子:自动摄取最新的JSONL
set -euo pipefail
SESSION_LOG=${1:-$(ls -t ~/.openclaw/sessions/*.jsonl 2>/dev/null | head -1)}
[ -z $SESSION_LOG ] && exit 0
通过curl调用MCP(服务器必须在:8012上运行)
curl -s -X POST http://localhost:8012/mcp \
-H Content-Type: application/json \
-d {
\method\: \tools/call\,
\params\: {
\name\: \openclaw
hebbianharvest\,
\arguments\: {\session
jsonlpath\: \$SESSION_LOG\}
}
} | jq .result.ingested // .error
选项B — Cron条目(被动自动化)
bash
每30分钟,摄取新的JSONL
/30 * /bin/bash ~/.openclaw/hooks/post-session.sh >> ~/.openclaw/hebbian-harvest.log 2>&1
选项C — pi-coding-agent集成
如果项目使用pi-coding-agent,在其配置中添加:
json
{
hooks: {
post_session: {
command: ~/.openclaw/hooks/post-session.sh,
trigger: onsessionend
}
}
}
注意: 钩子仅触发摄取(读取)。权重更新(weightupdate)始终保持手动操作,默认dryrun=True — 符合CDC的绝对规则第1条。
OpenClaw适配
| CDC组件 | OpenClaw适配 |
|---|
| 会话后钩子 | 读取pi-coding-agent的.jsonl文件 |
| Claude.md第2层 |
OpenClaw技能(.md或.json) |
| Claude.md第4层 | 专用pi-coding-agent扩展 |
| 用于审查的GitHub PR | 私有技能仓库的PR |
| 机密脱敏 |
强化 — 9种正则模式 + 运行时检测 |
所需配置
json
{
hebbian: {
parameters: {
learning_rate: 0.05,
decay: 0.02,
poids_min: 0.0,
poids_max: 0.95
},
thresholds: {
episodictoemergent: 5,
emergenttostrong: 0.8
},
pii_stripping: {
enabled: true,
patterns: [email, phone, ip, api_key, ssn]
},
security: {
secret_detection: true,
access_restriction: localhost,
embeddingrotation: onbreach
},
anti_drift: {
maxconsecutiveauto_changes: 3
}
}
}
参考
- - CDC:cahierdeschargesmemoirehebbienne.md v1.0.0
- 模块:src/hebbian_memory.py
- 模型:src/models.py中的8个Pydantic类
💎 支持
如果此技能对您有帮助,您可以支持开发:
狗狗币:DQBggqFNWsRNTPb6kkiwppnMo1Hm8edfWq