principle-encode-lessons-in-structure
把教训写进结构
Encode recurring fixes in mechanisms (tools, code, metadata, automation) instead of textual instructions. Every error, human correction, and unexpected outcome is a learning signal. Capture it, route it, and close the loop.
把反复出现的修复编码进机制(工具、代码、元数据、自动化),别靠文字指示。每次错误、人的纠正、意外结果都是学习信号。抓住它、路由它、闭环它。
Why: Textual instructions are easy to miss. They require the reader to notice, remember, and comply. Structural mechanisms (lint rules, metadata flags, runtime checks, automation scripts) enforce the rule without cooperation.
为什么: 文字指示容易漏。读者得注意到、记住、配合。结构机制(lint、元数据标志、运行时检查、自动化脚本)不用配合也能强制规则。
Pattern: When you catch yourself writing the same instruction a second time:
模式: 发现自己第二次写同一条指示时:
-
Ask: can this be a lint rule, a metadata flag, a runtime check, or a script?
-
If yes, encode it. Delete the instruction
-
If no (requires judgment), make the instruction more prominent and add an example of the failure mode
-
问:能做成 lint、元数据标志、运行时检查或脚本吗?
-
能,就编码。删掉指示。
-
不能(需要判断),就把指示放更显眼,并加失败模式例子。
Pick the strongest mechanism. When more than one mechanism would work, choose the strongest the situation allows (an unrepresentable state that cannot compile, then a lint or banned API that fails CI, then a canonical helper, then a runtime check), because agents copy whatever the surrounding code already does and a weaker guard becomes the next template.
选最强机制。 多种都能用时,选情境允许的最强(不可表示因而编不过 → 让 CI 失败的 lint/禁用 API → 规范 helper → 运行时检查),因为 agent 会抄周边已有做法,弱守卫会变成下一个模板。
Corollary: If the fix is structural, only use the structural fix. The instruction is the symptom.
推论: 若修复是结构性的,只用结构修复。文字指示是症状。
Feedback loop:
反馈环:
-
Capture every correction. When the human intervenes or tests fail, decide if it’s a one-off or a pattern.
-
Route to the right layer. One-off -> brain note. Recurring fix -> skill or lint rule. Systemic issue -> principle.
-
Close the loop. Don’t just record. Apply now or create a concrete todo.
-
抓住每次纠正。 人介入或测试失败时,判断是一次性还是模式。
-
路由到正确层。 一次性 → brain note。反复修复 → skill 或 lint。系统性问题 → principle。
-
闭环。 别只记。现在就应用,或建具体 todo。
Anti-patterns:
反模式:
-
Acknowledging without recording (“I’ll keep that in mind” does not persist)
-
Recording without routing (a brain note about a lint rule that should exist is wasted unless the lint rule gets implemented)
-
Fixing without generalizing (fixing one instance while leaving the recurring pattern intact)
-
只承认不记录(「我会记住」留不住)
-
只记录不路由(brain note 写着「该有个 lint」却不实现,白费)
-
只修不推广(修一例,反复模式原样留下)