lessons
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseLessons Learned
编码经验教训记录
Capture insights and learn from past experiences.
留存编码见解,从过往经验中学习提升。
Capture Patterns
经验记录模式
Quick Lesson Capture
快速记录经验
When you learn something valuable during a session:
bash
undefined当你在编码过程中学到有价值的内容时:
bash
undefinedWrite to lessons file
Write to lessons file
cat >> ~/.claude/lessons.md << 'EOF'
cat >> ~/.claude/lessons.md << 'EOF'
[Date] - [Topic]
[Date] - [Topic]
Context: What were you doing?
Lesson: What did you learn?
Application: When to apply this?
EOF
undefinedContext: What were you doing?
Lesson: What did you learn?
Application: When to apply this?
EOF
undefinedStructured Lesson
结构化经验记录
markdown
undefinedmarkdown
undefined2024-01-15 - TypeScript Generic Constraints
2024-01-15 - TypeScript Generic Constraints
Context:
Building a type-safe form library, struggled with generic types.
Problem:
Generic function wasn't narrowing types correctly.
Solution:
Use constraints to narrow:
extendstypescript
function getValue<T extends { value: unknown }>(obj: T): T['value'] {
return obj.value;
}Lesson:
TypeScript generics need explicit constraints for type narrowing.
Tags: #typescript #generics #types
undefined场景:
构建类型安全的表单库时,在泛型类型使用上遇到困难。
问题:
泛型函数无法正确地缩小类型范围。
解决方案:
使用 约束来缩小类型范围:
extendstypescript
function getValue<T extends { value: unknown }>(obj: T): T['value'] {
return obj.value;
}经验总结:
TypeScript 泛型需要显式约束才能实现类型缩小。
标签: #typescript #generics #types
undefinedLesson Categories
经验分类记录
Bug Lessons
Bug经验记录
markdown
undefinedmarkdown
undefinedBug: [Brief description]
Bug: [简要描述]
Symptom: What happened
Root Cause: Why it happened
Fix: How to fix
Prevention: How to avoid in future
Time Cost: How long to debug (motivation to remember!)
undefined症状: 发生了什么问题
根本原因: 问题产生的原因
修复方案: 如何修复
预防措施: 未来如何避免
时间成本: 调试耗时(提醒自己牢记的动力!)
undefinedPattern Lessons
模式经验记录
markdown
undefinedmarkdown
undefinedPattern: [Name]
模式:[名称]
When to use: Situations where this applies
How to implement: Basic structure
Gotchas: Common mistakes
Example: Working code
undefined适用场景: 该模式的适用情况
实现方式: 基础结构
注意事项: 常见误区
示例: 可运行代码
undefinedTool Lessons
工具经验记录
markdown
undefinedmarkdown
undefinedTool: [Name]
工具:[名称]
What it does: Brief description
Key commands: Most useful commands
Gotchas: Things that trip people up
Alternatives: Other options
undefined功能介绍: 简要描述
核心命令: 最实用的命令
注意事项: 容易踩坑的点
替代方案: 其他可选工具
undefinedReview Practices
回顾实践
Daily Review
每日回顾
bash
undefinedbash
undefinedReview recent lessons
Review recent lessons
tail -100 ~/.claude/lessons.md
tail -100 ~/.claude/lessons.md
Search for topic
Search for topic
grep -A 10 "typescript" ~/.claude/lessons.md
undefinedgrep -A 10 "typescript" ~/.claude/lessons.md
undefinedWeekly Audit
每周审计
bash
gemini -m pro -o text -e "" "Review these lessons from the past week:
$(tail -500 ~/.claude/lessons.md)
1. What patterns emerge?
2. What mistakes keep recurring?
3. What should be turned into automation?
4. What needs deeper study?"bash
gemini -m pro -o text -e "" "Review these lessons from the past week:
$(tail -500 ~/.claude/lessons.md)
1. What patterns emerge?
2. What mistakes keep recurring?
3. What should be turned into automation?
4. What needs deeper study?"Before Starting Work
工作前置回顾
bash
undefinedbash
undefinedGet relevant lessons
Get relevant lessons
TOPIC="authentication"
grep -B 2 -A 10 -i "$TOPIC" ~/.claude/lessons.md
undefinedTOPIC="authentication"
grep -B 2 -A 10 -i "$TOPIC" ~/.claude/lessons.md
undefinedAutomation from Lessons
经验转化为自动化
When a lesson appears multiple times, automate it:
当某条经验多次出现时,将其转化为自动化工具:
Create Git Hook
创建Git钩子
bash
undefinedbash
undefinedLesson: Always run tests before commit
Lesson: Always run tests before commit
→ Create pre-commit hook
→ Create pre-commit hook
cat > .git/hooks/pre-commit << 'EOF'
#!/bin/bash
npm test || exit 1
EOF
chmod +x .git/hooks/pre-commit
undefinedcat > .git/hooks/pre-commit << 'EOF'
#!/bin/bash
npm test || exit 1
EOF
chmod +x .git/hooks/pre-commit
undefinedCreate Snippet
创建代码片段
bash
undefinedbash
undefinedLesson: This pattern is useful
Lesson: This pattern is useful
→ Save as snippet
→ Save as snippet
cat > ~/.claude/snippets/async-error-handling.ts << 'EOF'
async function safeAsync<T>(promise: Promise<T>): Promise<[T, null] | [null, Error]> {
try {
const result = await promise;
return [result, null];
} catch (error) {
return [null, error as Error];
}
}
EOF
undefinedcat > ~/.claude/snippets/async-error-handling.ts << 'EOF'
async function safeAsync<T>(promise: Promise<T>): Promise<[T, null] | [null, Error]> {
try {
const result = await promise;
return [result, null];
} catch (error) {
return [null, error as Error];
}
}
EOF
undefinedCreate Checklist
创建检查清单
bash
undefinedbash
undefinedLesson: Keep forgetting these steps
Lesson: Keep forgetting these steps
→ Create checklist
→ Create checklist
cat > ~/.claude/checklists/pr-review.md << 'EOF'
cat > ~/.claude/checklists/pr-review.md << 'EOF'
PR Review Checklist
PR Review Checklist
- Tests pass
- No console.logs
- Types are explicit
- Error handling present
- Documentation updated EOF
undefined- Tests pass
- No console.logs
- Types are explicit
- Error handling present
- Documentation updated EOF
undefinedAI-Assisted Learning
AI辅助学习
Extract Lessons from Session
从会话中提取经验
bash
gemini -m pro -o text -e "" "Extract lessons learned from this coding session:
[Paste conversation or summary]
For each lesson:
1. What was learned
2. When it applies
3. How to remember it"bash
gemini -m pro -o text -e "" "Extract lessons learned from this coding session:
[Paste conversation or summary]
For each lesson:
1. What was learned
2. When it applies
3. How to remember it"Connect Lessons
关联经验
bash
gemini -m pro -o text -e "" "Find connections between these lessons:
$(cat ~/.claude/lessons.md)
1. What themes emerge?
2. What knowledge gaps exist?
3. What should be studied next?"bash
gemini -m pro -o text -e "" "Find connections between these lessons:
$(cat ~/.claude/lessons.md)
1. What themes emerge?
2. What knowledge gaps exist?
3. What should be studied next?"Generate Quiz
生成测试题
bash
gemini -m pro -o text -e "" "Create a quiz from these lessons:
$(tail -1000 ~/.claude/lessons.md)
Generate 5 questions that test understanding of key concepts."bash
gemini -m pro -o text -e "" "Create a quiz from these lessons:
$(tail -1000 ~/.claude/lessons.md)
Generate 5 questions that test understanding of key concepts."Storage Options
存储方案
File-based
文件存储
bash
undefinedbash
undefinedSingle file
Single file
~/.claude/lessons.md
~/.claude/lessons.md
By date
By date
~/.claude/lessons/2024-01.md
~/.claude/lessons/2024-01.md
By topic
By topic
~/.claude/lessons/typescript.md
~/.claude/lessons/git.md
undefined~/.claude/lessons/typescript.md
~/.claude/lessons/git.md
undefinedMemory Integration
记忆库集成
bash
undefinedbash
undefinedSave to basic-memory
Save to basic-memory
basic-memory tool write-note
--title "Lesson: TypeScript Generics"
--folder "lessons"
--content "$(cat lesson.md)"
--tags "lesson,typescript"
--title "Lesson: TypeScript Generics"
--folder "lessons"
--content "$(cat lesson.md)"
--tags "lesson,typescript"
undefinedbasic-memory tool write-note
--title "Lesson: TypeScript Generics"
--folder "lessons"
--content "$(cat lesson.md)"
--tags "lesson,typescript"
--title "Lesson: TypeScript Generics"
--folder "lessons"
--content "$(cat lesson.md)"
--tags "lesson,typescript"
undefinedBest Practices
最佳实践
- Capture immediately - Don't wait, you'll forget
- Be specific - Include code examples
- Note the cost - Time spent motivates remembering
- Review regularly - Lessons fade without review
- Automate repeated - Turn lessons into tools
- Tag consistently - Makes searching easier
- Connect to context - When does this apply?
- 即时记录 - 不要拖延,否则会遗忘
- 内容具体 - 附上代码示例
- 记录成本 - 耗时记录能提醒自己牢记
- 定期回顾 - 不回顾的经验会被遗忘
- 自动化重复经验 - 将经验转化为工具
- 统一标签 - 便于搜索
- 关联场景 - 明确适用时机