ai-coding-memory 是一个 AI Coding 项目记忆系统,用于:
使用场景
- 开始新任务前 :使用 search 查找相关的历史经验和决策
- 完成重要功能后 :使用 record 记录关键决策和设计思路
- 修复复杂Bug后 :使用 record 记录问题根因和解决方案
- 任务结束后 :使用 summarize 自动汇总所有变更
核心价值
跨会话记忆 :新会话能快速同步项目进展
避免重复造轮子 :发现已有的工具类和模式
防错复现 :记录Bug根因,避免重复犯错
决策追溯 :记录"为什么"这么写,而不只是代码本身
调用方式
记录知识 (record)
基本语法 :
ai-coding-memory record [类型] [标题] [内容]
参数说明 :
- 类型 (可选): decision (架构决策)、 pattern (设计模式)、 incident (Bug修复)、 convention (规范约定)
- 标题 :简短描述性标题
- 内容 :详细内容描述
可选参数 : - –auto-tags :自动生成标签
- –auto-files :自动关联文件
示例 :
记录架构决策
ai-coding-memory record decision “使用Zustand作为状态管理” “选择Zustand的原因是…”
记录Bug修复
ai-coding-memory record incident “修复登录表单验证问题” “问题描述:… 修复方案:…”
记录设计模式
ai-coding-memory record pattern “错误处理统一模式” “所有API调用都应使用try-catch包装…”
记录规范约定
ai-coding-memory record convention “组件命名规范” “所有组件使用PascalCase命名…”
自动生成标签和关联文件
ai-coding-memory record decision “使用React Query管理服务器状态” “原因:…”
–auto-tags --auto-files
检索知识 (search)
基本语法 :
ai-coding-memory search [查询关键词]
参数说明 :
- 查询关键词 :支持空格或逗号分隔多个关键词
可选参数 : - –type :过滤特定类型(decision、pattern、incident、convention)
示例 :
搜索所有相关内容
ai-coding-memory search 登录 验证
搜索特定类型
ai-coding-memory search 状态管理 --type decision
搜索Bug记录
ai-coding-memory search 性能 --type incident
搜索设计模式
ai-coding-memory search 错误处理 --type pattern
自动总结 (summarize)
基本语法 :
ai-coding-memory summarize
功能说明 :
- 自动读取 git 变更统计
- 生成结构化总结内容
- 自动推断知识类型
- 自动补全标签与关联文件
- 写入对应知识目录并更新索引
示例 :
自动总结当前git变更
ai-coding-memory summarize
知识存储结构
知识存储在项目的 knowledge/ 目录下:
knowledge/
├── decisions/ # 架构决策记录 (ADR)
│ ├── 2024-03-13-使用Zustand作为状态管理.md
│ └── 2024-03-10-选择React-Query.md
├── patterns/ # 设计模式、最佳实践
│ ├── 2024-03-12-错误处理统一模式.md
│ └── 2024-03-08-组件复用模式.md
├── incidents/ # Bug修复记录 (Post-mortem)
│ ├── 2024-03-15-登录表单验证问题.md
│ └── 2024-03-05-内存泄漏修复.md
├── conventions/ # 命名、目录结构、技术栈约定
│ ├── 2024-03-01-组件命名规范.md
│ └── 2024-02-28-目录结构约定.md
└── _index.md # 全局索引
知识文件格式
每个 .md 文件必须包含标准 Frontmatter:
type: decision | pattern | incident | convention
title: 简短描述性标题
date: YYYY-MM-DD
tags: [标签1, 标签2]
related_files: [相关文件路径]
status: accepted | resolved | active
标题
背景/问题
描述为什么需要这个决策/模式/修复
决策/方案
详细说明选择的方案或模式
理由
解释为什么选择这个方案
影响
说明这个决策对项目的影响
相关文件
- 文件路径1
- 文件路径2
自动调用流程
在任务开始阶段:
- 执行 search 检索既有知识
↓ - 将检索到的知识融入当前任务规划
↓ - 避免重复造轮子,利用已有经验
在任务结束阶段: - 执行 record 或 summarize
↓ - 自动生成知识条目
↓ - 更新 knowledge/_index.md
↓ - 形成可追溯的知识索引
使用场景示例
场景1:开始新功能开发
1. 先检索相关决策和模式
ai-coding-memory search 用户认证 状态管理
2. 根据检索结果规划开发
AI会告诉你:项目已选择Zustand作为状态管理,已存在用户认证模式…
3. 开发完成后,记录新的决策或模式
ai-coding-memory record decision “使用JWT进行用户认证” “原因:…” --auto-tags
–auto-files
场景2:修复Bug
1. 检索是否有类似的历史Bug
ai-coding-memory search 登录 失败 --type incident
2. 修复Bug后,记录修复过程
ai-coding-memory record incident “修复登录接口超时问题” "
问题描述:登录接口在弱网环境下超时
根因分析:未设置合理的超时时间
修复方案:增加超时配置和重试机制
" --auto-files
场景3:任务完成后自动总结
完成一系列开发后
ai-coding-memory summarize
AI会自动:
- 读取git变更
- 生成结构化总结
- 自动推断知识类型
- 写入对应目录
- 更新索引
最佳实践
推荐做法
- 任务开始前先search
ai-coding-memory search [关键词] - 重要决策及时record
ai-coding-memory record decision [标题] [内容] --auto-tags --auto-files - 任务结束后summarize
ai-coding-memory summarize - Bug修复后记录incident
ai-coding-memory record incident [标题] [内容] --auto-files
避免做法 - 不要记录琐碎的代码变更
- 不要记录没有参考价值的内容
- 不要忘记更新索引(使用–auto-tags和–auto-files)
- 不要在Frontmatter中遗漏关键字段
知识类型对比
ai-coding-memory Skill下载:https://hanhoo.feishu.cn/wiki/DrF2wYFG5i22qOkcZfKcMxfrnbg

