Learning

From xiaobei930/cc-best · View interactive version

Learning is an AI agent skill from the GitHub repository xiaobei930/cc-best. Extracts reusable patterns from sessions. Use at session end to capture debugging insights and project-specific knowledge.

How to use this skill

Skill file

持续学习技能

本技能用于从开发会话中提取可复用的模式和知识,实现持续学习和改进。

快速参考

<!-- 详细内容 -->

目录

子文件

触发条件

学习模式类型

1. 错误解决模式

当解决了一个错误,记录:

## 错误: Cannot read property 'xxx' of undefined

### 场景

访问嵌套对象属性时

### 根本原因

异步数据未加载完成就访问

### 解决方案

// 使用可选链

const value = obj?.nested?.property;

// 或提供默认值

const value = obj?.nested?.property ?? defaultValue;

预防


### 2. 调试技巧

技巧: 调试 Next.js API 路由

场景

API 路由返回意外结果

技巧

  1. 在 route.ts 开头添加日志
export async function GET(request: NextRequest) {
  console.log('[API] GET /api/xxx', {
    url: request.url,
    headers: Object.fromEntries(request.headers)
  })
  // ...
}
  1. 使用 Postman/curl 直接测试
  2. 检查中间件是否拦截

### 3. 变通方案

变通: Prisma 不支持的复杂查询

场景

需要执行 Prisma 不原生支持的 SQL

变通方案

// 使用 $queryRaw 执行原生 SQL
const result = await prisma.$queryRaw`
  SELECT * FROM users
  WHERE LOWER(name) LIKE ${`%${search.toLowerCase()}%`}
`

// 或使用 $executeRaw 执行命令
await prisma.$executeRaw`
  UPDATE users SET updated_at = NOW()
  WHERE id = ${userId}
`

注意


### 4. 项目特定知识

项目: 用户认证流程

流程

  1. 用户提交凭证 → POST /api/auth/login
  2. 验证凭证 → 检查数据库
  3. 生成 JWT → 设置 httpOnly cookie
  4. 返回用户信息

关键文件

注意事项


## 评估清单

会话结束时,检查以下内容:

### 值得记录的模式

### 不值得记录的模式

## 知识库结构

.claude/

└── learned/

├── errors/

│ ├── prisma-connection-issues.md

│ └── react-hydration-mismatch.md

├── debugging/

│ ├── next-api-routes.md

│ └── database-query-slow.md

├── workarounds/

│ ├── prisma-raw-queries.md

│ └── nextauth-custom-session.md

├── patterns/

│ ├── error-handling.md

│ └── api-response-format.md

└── project/

├── auth-flow.md

└── data-models.md


## 知识文档模板

title: [标题]

category: [errors|debugging|workarounds|patterns|project]

tags: [tag1, tag2]

created: YYYY-MM-DD

updated: YYYY-MM-DD


[标题]

场景

[描述遇到这个问题/使用这个模式的场景]

问题/需求

[具体的问题描述或需求说明]

解决方案

[详细的解决方案,包括代码示例]

相关文件

参考

注意事项

[使用时需要注意的点]


## 自动化集成

### 会话评估 Hook

会话评估已通过 Node.js Hook 自动化,无需手动触发:

- **脚本**: `scripts/node/hooks/evaluate-session.js`(运行 `--help` 查看详情)
- **触发时机**: Stop 事件(会话结束时)
- **功能**: 自动评估会话长度,提示提取可复用模式

### 配置文件

{

"min_session_length": 10,

"extraction_threshold": "medium",

"auto_approve": false,

"learned_skills_path": "~/.claude/learned/",

"patterns_to_detect": [

"error_resolution",

"debugging_techniques",

"workarounds",

"project_specific"

],

"ignore_patterns": ["simple_typos", "one_time_fixes", "external_api_issues"]

}


## 本能系统(进阶)

本能是介于"观察"和"正式技能"之间的中间状态,用于捕捉重复出现的模式。

### 本能的生命周期

观察 ──→ 记录 ──→ 本能 ──→ 演化

│ │ │ │

│ │ │ └─→ 技能/命令/智能体

│ │ └─→ 置信度评估

│ └─→ observations.jsonl

└─→ Hook 自动捕获


### 置信度评分

| 置信度 | 含义     | 动作                |
| ------ | -------- | ------------------- |
| 0.3    | 首次观察 | 记录但不采取行动    |
| 0.5    | 重复出现 | 形成初步本能        |
| 0.7    | 多次验证 | 考虑演化为技能      |
| 0.9    | 高度可靠 | 正式演化为技能/命令 |

### 本能记录格式

本能: [名称]

触发模式

[什么情况下触发]

推荐行为

[应该如何响应]

置信度: 0.X

[基于多少次观察]

观察记录

演化候选

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.