aboutyao/cognitive-brain/SKILL.md
# 🧠 Cognitive Brain > **跨会话记忆与认知系统 v5.0** | Cross-Session Memory & Cognition System > > 让 AI 拥有像人类一样的记忆、思考和预测能力 **Version: 7.0.1** | **License: MIT** --- ## ✨ 功能特性 | Features | 功能 | Feature | 描述 | |------|---------|------| | 🔄 实时共享 | Real-time Sharing | 跨会话毫秒级记忆同步 | | 🧠 四层记忆 | Four-Layer Memory | 感官/工作/情景/语义记忆架构 | | 💭 自由思考 | Free Thinking | 非任务驱动的意识流思考 | | 🔮 智能预测 | Prediction | 预测用户需求,预加载记忆 | | 📊 可视化 | Visualization | 知识图谱、时间线、摘要 | | 🔗 联想网络 | Association Network | 概念关联,激活扩散算法 | | 🏗
npx skillsauth add openclaw/skills aboutyao/cognitive-brainInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
跨会话记忆与认知系统 v5.0 | Cross-Session Memory & Cognition System
让 AI 拥有像人类一样的记忆、思考和预测能力
Version: 7.0.1 | License: MIT
| 功能 | Feature | 描述 | |------|---------|------| | 🔄 实时共享 | Real-time Sharing | 跨会话毫秒级记忆同步 | | 🧠 四层记忆 | Four-Layer Memory | 感官/工作/情景/语义记忆架构 | | 💭 自由思考 | Free Thinking | 非任务驱动的意识流思考 | | 🔮 智能预测 | Prediction | 预测用户需求,预加载记忆 | | 📊 可视化 | Visualization | 知识图谱、时间线、摘要 | | 🔗 联想网络 | Association Network | 概念关联,激活扩散算法 | | 🏗️ 分层架构 | Layered Architecture | Domain/Repository/Service 分层设计 | | 🔒 事务安全 | Transaction Safety | UnitOfWork 确保数据一致性 | | 📚 完整文档 | Documentation | API 文档 + 架构文档 | | ✅ 测试覆盖 | Test Coverage | 自动化测试套件 |
# 方式1: ClawHub 安装(推荐)
clawhub install cognitive-brain
cd ~/.openclaw/workspace/skills/cognitive-brain
npm run setup:auto # 非交互模式,自动安装所有依赖
# 方式2: 手动安装
cd ~/.openclaw/workspace/skills/cognitive-brain
npm install
npm run setup # 交互式配置
| 命令 | 说明 |
|------|------|
| npm run check | 检查系统依赖(PostgreSQL, Redis, pgvector) |
| npm run setup | 交互式安装,会提示输入数据库配置 |
| npm run setup:auto | 自动安装,使用默认配置,自动安装缺失依赖 |
| npm run setup:resume | 从断点恢复安装(安装失败后使用) |
| npm run health | 健康检查 |
| npm run reset | 重置数据库(清空记忆,保留表结构) |
| npm run uninstall | 卸载(清理数据库、hooks、配置文件) |
| 特性 | 说明 |
|------|------|
| 🔄 断点恢复 | 安装失败后运行 npm run setup:resume 继续 |
| 📋 安装日志 | 记录到 install.log,便于排查问题 |
| 🔍 已安装检测 | 自动检测是否已安装,避免重复 |
| ⚡ 一键安装 | installCommand 自动执行完整安装流程 |
| 依赖 | 版本 | 安装命令 (Ubuntu) |
|------|------|-------------------|
| Node.js | >= 18 | apt install nodejs npm |
| PostgreSQL | >= 14 | apt install postgresql |
| Redis | >= 6 | apt install redis-server |
| pgvector | - | apt install postgresql-16-pgvector |
💡
npm run setup:auto会自动安装这些依赖(需要 root 权限)
const { CognitiveBrain } = require('./src/index.js');
const brain = new CognitiveBrain();
// 存储记忆
const memory = await brain.encode('用户的项目叫 Alpha', {
type: 'conversation',
importance: 0.8
});
// 检索记忆
const memories = await brain.recall('项目');
// 获取统计
const stats = await brain.stats();
# 编码记忆
node scripts/core/encode.cjs "内容" -t conversation -i 0.8
# 检索记忆
node scripts/core/recall.cjs --query "关键词" --limit 5
# 健康检查
node scripts/tools/health_check.cjs
# 运行测试
./tests/run.sh
┌─────────────────────────────────────────────────────────────┐
│ API / CLI 层 │
│ ┌────────────┐ ┌────────────┐ ┌────────────┐ │
│ │ REST API │ │ CLI │ │ Hook │ │
│ └────────────┘ └────────────┘ └────────────┘ │
└─────────────────────────┬───────────────────────────────────┘
│
┌─────────────────────────▼───────────────────────────────────┐
│ Service 层 │
│ ┌────────────┐ ┌────────────┐ ┌────────────┐ │
│ │ Memory │ │ Concept │ │ Association│ │
│ │ Service │ │ Service │ │ Service │ │
│ └────────────┘ └────────────┘ └────────────┘ │
└─────────────────────────┬───────────────────────────────────┘
│
┌─────────────────────────▼───────────────────────────────────┐
│ Repository 层 │
│ ┌────────────┐ ┌────────────┐ ┌────────────┐ │
│ │ Memory │ │ Concept │ │ Association│ │
│ │ Repository │ │ Repository │ │ Repository │ │
│ └────────────┘ └────────────┘ └────────────┘ │
│ UnitOfWork (事务) │
└─────────────────────────┬───────────────────────────────────┘
│
┌─────────────────────────▼───────────────────────────────────┐
│ Domain 层 │
│ ┌────────────┐ ┌────────────┐ ┌────────────┐ │
│ │ Memory │ │ Concept │ │ Association│ │
│ │ Entity │ │ Entity │ │ Entity │ │
│ └────────────┘ └────────────┘ └────────────┘ │
└─────────────────────────┬───────────────────────────────────┘
│
┌─────────────────────────▼───────────────────────────────────┐
│ 持久层 | Persistence │
│ ┌────────────┐ ┌────────────┐ ┌────────────┐ │
│ │ PostgreSQL│ │ Redis │ │ Files │ │
│ │ (主存储) │ │ (缓存) │ │ (配置/日志)│ │
│ └────────────┘ └────────────┘ └────────────┘ │
└─────────────────────────────────────────────────────────────┘
| 层级 | Layer | Duration | Purpose | Description | |------|-------|---------|---------|-------------| | 感官记忆 | Sensory | Milliseconds | Buffer | Transient sensory buffer for immediate perception | | 工作记忆 | Working | Minutes~Hours | Active Processing | Active processing workspace for current tasks | | 情景记忆 | Episodic | Long-term | Experiences | Personal experiences and events with context | | 语义记忆 | Semantic | Long-term | Knowledge | Facts, concepts, and structured knowledge |
主入口类,提供统一的操作接口。
const { CognitiveBrain } = require('./src/index.js');
const brain = new CognitiveBrain();
// 编码记忆
const memory = await brain.encode(content, {
type: 'conversation',
importance: 0.8,
sourceChannel: 'qq'
});
// 检索记忆
const memories = await brain.recall('关键词', { limit: 10 });
// 事务操作
await brain.transaction(async (uow) => {
// 多表原子操作
});
// 获取统计
const stats = await brain.stats();
{
id: 'uuid',
content: '记忆内容',
type: 'episodic',
importance: 0.5,
sourceChannel: 'qq',
role: 'user',
entities: ['关键词'],
emotions: { valence: 0, arousal: 0 },
createdAt: Date,
updatedAt: Date
}
{
id: 'uuid',
name: '概念名称',
type: 'general',
importance: 0.5,
activation: 0.0,
accessCount: 0
}
{
id: 'uuid',
fromId: '概念A-ID',
toId: '概念B-ID',
type: 'related',
weight: 0.5
}
使用 UnitOfWork 模式确保数据一致性:
const { UnitOfWork } = require('./src/repositories/UnitOfWork.js');
const { MemoryRepository } = require('./src/repositories/MemoryRepository.js');
// 自动事务
await UnitOfWork.withTransaction(pool, async (uow) => {
const memRepo = new MemoryRepository(uow.getQueryClient());
const conceptRepo = new ConceptRepository(uow.getQueryClient());
await memRepo.create(memory);
await conceptRepo.create(concept);
// 自动 commit 或 rollback
});
# 运行所有测试
./tests/run.sh
# 运行特定测试
node tests/v5.test.cjs
node tests/db.test.cjs
node tests/memory.test.cjs
# 健康检查
node scripts/tools/health_check.cjs
| 表名 | 用途 | 说明 |
|------|------|------|
| episodes | 情景记忆 | 存储对话和事件 |
| concepts | 概念节点 | 提取的实体和关键词 |
| associations | 概念关联 | 概念间的关系 |
| system_memory | 系统配置 | 全局设置和状态 |
自动集成到 OpenClaw 消息流程:
用户消息 → Hook(cognitive-recall) → 检索记忆 → 注入上下文 → AI回复 → 编码记忆
{
"version": "5.3.25",
"storage": {
"primary": {
"type": "postgresql",
"host": "localhost",
"port": 5432,
"database": "cognitive_brain"
},
"cache": {
"type": "redis",
"host": "localhost",
"port": 6379
}
}
}
agent:bootstrap Hook 即时注入记忆type: 'conversation' 改为有效类型 'episodic'npm run uninstall 清理所有组件npm run reset 清空记忆数据git checkout -b feature/xxx)git commit -m 'Add feature')git push origin feature/xxx)MIT License
让 AI 拥有记忆,让对话更有温度 ❤️
tools
Use when the user wants to connect to, test, or use the McDonalds service at mcp.mcd.cn, including checking authentication, probing MCP endpoints, listing tools, or calling McDonalds MCP tools through a reusable local CLI.
development
Web scraping platform — Twitter/X data, Vinted marketplace, and general web scraping API
development
SlowMist AI Agent Security Review — comprehensive security framework for skills, repositories, URLs, on-chain addresses, and products (Claude Code version)
data-ai
去除中文文本中的 AI 写作痕迹,使其读起来自然。基于维基百科 AI 写作特征指南,检测 24 种 AI 模式。触发词:humanizer-cn、去除 AI 痕迹、去除 AI 写作痕迹、中文文本人性化。