continuous-learning

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Continuous Learning

持续学习

Pattern Extraction Framework

模式提取框架

After every significant coding session, extract and categorize learnings into three buckets:
  1. Corrections - Mistakes caught during review or by the user
  2. Successful Approaches - Patterns that worked well and should be repeated
  3. Anti-Patterns - Approaches that caused problems and should be avoided
每次重要编码会话结束后,将所学内容提取并归类到三个类别中:
  1. 修正内容 - 评审过程中或用户发现的错误
  2. 成功实践方案 - 效果良好、值得重复使用的模式
  3. 反模式 - 引发问题、应避免使用的方案

Learning Entry Format

学习条目格式

yaml
pattern:
  id: "LEARN-2025-0042"
  category: "error-handling"
  type: "correction"         # correction | success | anti-pattern
  confidence: 0.85           # 0.0 to 1.0
  language: "typescript"
  context: "API error responses"
  observation: "Returning raw error messages from database exceptions exposes internals"
  lesson: "Always map database errors to application-level error codes before returning"
  example:
    before: "catch (e) { res.status(500).json({ error: e.message }) }"
    after: "catch (e) { logger.error(e); res.status(500).json({ error: 'INTERNAL_ERROR' }) }"
  frequency: 3               # times this pattern has been observed
  last_seen: "2025-06-15"
yaml
pattern:
  id: "LEARN-2025-0042"
  category: "error-handling"
  type: "correction"         # correction | success | anti-pattern
  confidence: 0.85           # 0.0 to 1.0
  language: "typescript"
  context: "API error responses"
  observation: "Returning raw error messages from database exceptions exposes internals"
  lesson: "Always map database errors to application-level error codes before returning"
  example:
    before: "catch (e) { res.status(500).json({ error: e.message }) }"
    after: "catch (e) { logger.error(e); res.status(500).json({ error: 'INTERNAL_ERROR' }) }"
  frequency: 3               # times this pattern has been observed
  last_seen: "2025-06-15"

Confidence Scoring

置信度评分

ScoreMeaningAction
0.95+Verified across multiple projectsApply automatically
0.80-0.94Confirmed in this codebaseApply and mention
0.60-0.79Observed but not fully validatedSuggest with caveat
0.40-0.59Hypothesis based on limited dataAsk before applying
<0.40Speculative, needs validationDocument but do not apply
Update confidence based on:
  • +0.10 when pattern is confirmed correct by user
  • +0.05 when pattern is observed again in a different context
  • -0.15 when pattern leads to a correction
  • -0.20 when pattern is explicitly rejected by user
评分含义操作建议
0.95+已在多个项目中验证自动应用
0.80-0.94已在当前代码库中确认应用并标注
0.60-0.79已观察到但未完全验证建议使用并附加说明
0.40-0.59基于有限数据的假设应用前需询问
<0.40推测性内容,需验证仅记录暂不应用
根据以下规则更新置信度:
  • 用户确认模式正确时,+0.10
  • 在不同场景下再次观察到该模式时,+0.05
  • 模式引发修正时,-0.15
  • 用户明确拒绝该模式时,-0.20

Session Wrap-Up Protocol

会话收尾流程

At the end of each session or before context compaction:
  1. Review changes made - Scan diffs for patterns
  2. Identify corrections - What was changed after initial implementation?
  3. Note successful first-attempts - What worked without revision?
  4. Record environment details - Framework versions, config specifics
  5. Update confidence scores - Adjust based on session outcomes
  6. Write to knowledge base - Append new entries to CLAUDE.md or LEARNED.md
markdown
undefined
在每次会话结束时或上下文压缩前:
  1. 回顾所做更改 - 扫描差异内容寻找模式
  2. 识别修正内容 - 初始实现后有哪些修改?
  3. 记录首次尝试成功的方案 - 哪些内容无需修改就生效?
  4. 记录环境细节 - 框架版本、配置详情
  5. 更新置信度评分 - 根据会话结果调整评分
  6. 写入知识库 - 将新条目追加到CLAUDE.md或LEARNED.md中
markdown
undefined

Session Learnings (2025-06-15)

会话学习记录(2025-06-15)

Corrections Applied

已应用的修正内容

  • [0.85] TypeScript: Use
    satisfies
    instead of
    as
    for type narrowing with object literals
  • [0.90] Next.js: Server Actions must be async functions, even for synchronous operations
  • [0.85] TypeScript:在对象字面量的类型收窄中使用
    satisfies
    而非
    as
  • [0.90] Next.js:Server Actions必须是异步函数,即使是同步操作也需如此

Successful Patterns

成功模式

  • [0.80] PostgreSQL: Partial indexes on status columns reduced query time by 60%
  • [0.75] React: Extracting data fetching into Server Components eliminated 3 useEffect hooks
  • [0.80] PostgreSQL:对状态列创建部分索引后,查询时间缩短60%
  • [0.75] React:将数据提取逻辑移至Server Components,消除了3个useEffect钩子

Anti-Patterns Identified

已识别的反模式

  • [0.70] Avoid: Nesting more than 2 levels of Suspense boundaries (causes waterfall)
  • [0.65] Avoid: Using
    any
    to suppress TypeScript errors in catch blocks (use
    unknown
    )
undefined
  • [0.70] 避免:嵌套超过2层的Suspense边界(会导致请求瀑布)
  • [0.65] 避免:在catch块中使用
    any
    来抑制TypeScript错误(应使用
    unknown
undefined

Knowledge Base Organization

知识库组织结构

Structure the knowledge base by domain:
knowledge/
  error-handling.md      # Error patterns across languages
  testing.md             # Test patterns and anti-patterns
  performance.md         # Optimization learnings
  api-design.md          # API design decisions
  deployment.md          # Infrastructure learnings
  project-specific.md    # Current project conventions
Each file follows the same entry format. Deduplicate entries with matching
observation
fields by incrementing
frequency
and updating
confidence
.
按领域划分知识库结构:
knowledge/
  error-handling.md      # 跨语言错误模式
  testing.md             # 测试模式与反模式
  performance.md         # 优化经验
  api-design.md          # API设计决策
  deployment.md          # 基础设施经验
  project-specific.md    # 当前项目约定
每个文件遵循相同的条目格式。对于
observation
字段匹配的重复条目,增加
frequency
并更新
confidence
以实现去重。

Correction Tracking

修正跟踪

When a user corrects code or approach:
  1. Record what was originally produced
  2. Record what the correction was
  3. Identify the root cause (wrong assumption, missing context, outdated pattern)
  4. Create or update a learning entry
  5. Search for similar patterns that might need the same correction
markdown
undefined
当用户修正代码或方案时:
  1. 记录最初的实现内容
  2. 记录修正后的内容
  3. 识别根本原因(错误假设、缺失上下文、过时模式)
  4. 创建或更新学习条目
  5. 搜索可能需要相同修正的类似模式
markdown
undefined

Correction Log

修正日志

  • Original: Used
    useEffect
    to fetch data on mount
  • Correction: Moved data fetching to Server Component
  • Root cause: Applied client-side SPA pattern in Server Component context
  • Generalization: In Next.js App Router, prefer server-side data fetching for initial page data
  • Confidence: 0.90 (confirmed across 4 components)
undefined
  • 初始实现:使用
    useEffect
    在组件挂载时获取数据
  • 修正内容:将数据获取逻辑移至Server Component
  • 根本原因:在Server Component环境中应用了客户端SPA模式
  • 通用结论:在Next.js App Router中,初始页面数据优先使用服务端数据获取
  • 置信度:0.90(已在4个组件中确认)
undefined

Pattern Reinforcement

模式强化

Track how often patterns are applied and whether they hold:
Pattern: "Use zod for API input validation"
  Applied: 12 times
  Confirmed: 11 times
  Corrected: 1 time (edge case with file uploads)
  Confidence: 0.92
  Status: ESTABLISHED
Statuses:
  • EMERGING (frequency < 3) - New pattern, needs validation
  • GROWING (frequency 3-7) - Building evidence, apply with mention
  • ESTABLISHED (frequency 8+, confidence > 0.85) - Apply automatically
  • DEPRECATED - Once valid, now superseded by a better approach
跟踪模式的应用次数及有效性:
Pattern: "Use zod for API input validation"
  Applied: 12 times
  Confirmed: 11 times
  Corrected: 1 time (edge case with file uploads)
  Confidence: 0.92
  Status: ESTABLISHED
状态说明:
  • EMERGING(应用次数<3)- 新模式,需验证
  • GROWING(应用次数3-7)- 证据积累中,应用时需标注
  • ESTABLISHED(应用次数≥8,置信度>0.85)- 自动应用
  • DEPRECATED - 曾有效,但已被更优方案取代

Integration with Memory Files

与记忆文件的集成

Store learnings in the project's memory file (CLAUDE.md or equivalent):
  • High-confidence learnings (>0.85) go in the main instructions section
  • Medium-confidence (0.60-0.84) go in a dedicated "Learnings" section
  • Low-confidence (<0.60) stay in session notes until validated
  • Deprecated patterns move to an archive section with reason for deprecation
Review and prune the knowledge base monthly. Remove entries that have not been referenced in 90 days and have confidence below 0.70.
将学习内容存储在项目的记忆文件(CLAUDE.md或同类文件)中:
  • 高置信度学习内容(>0.85)放入主说明部分
  • 中等置信度内容(0.60-0.84)放入专门的“学习记录”部分
  • 低置信度内容(<0.60)保留在会话笔记中,直至验证通过
  • 已废弃的模式移至归档部分,并注明废弃原因
每月回顾并精简知识库。移除90天内未被引用且置信度低于0.70的条目。