principle-model-the-domain
它能做什么
为智能体提供一条规则,用与业务领域相符的结构对有状态的逻辑进行建模。适合代码中充斥着标志位和嵌套条件的工程师。
适用场景
- ✓当你编写带有生命周期或阶段的有状态逻辑的时候。
- ✓当代码分支很多,或在多个文件中重复相同的形状假设的时候。
- ✓当无效状态不断进入系统的时候。
技能链接
https://github.com/cursor/plugins/blob/main/harness/pstack/claude-code/skills/principle-model-the-domain/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“我们的订单流程用一堆布尔值来追踪状态。请把它正确地建模,让不可能的状态无法出现。”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会找出真实的状态和规则,然后用合适的结构对它们进行编码,例如状态机、带类型的模型或查找表。这样可以去掉许多分支,并让无效状态更难被写入。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Model the Domain
Encode the real domain in a data structure instead of scattering it across conditionals. A structure that matches the domain makes invalid states unrepresentable and deletes branches. Choosing it at write time is cheap. Recovering it later reads as a refactor and gets deferred.
Reach for:
- A state machine instead of scattered booleans, phases, or lifecycle checks.
- A typed model instead of loose parameters or repeated shape assumptions.
- A map, registry, lookup table, or discriminated union instead of branching spread across files.
- A reducer or command/event model instead of ad hoc state mutations.
- A module organized around one body of domain knowledge instead of a sequence such as load, validate, transform, and save. Execution order is not ownership.
- A small module boundary that gathers repeated behavior, ownership, or invariants.
- A queue, cache, index, graph, tree, or normalized collection where the access pattern calls for it.
- Any other structure that fits. When none fits, work out what the code must never allow and how the data gets read, then find the structure that encodes exactly that.
Do not force an abstraction. Prefer boring code if the current shape is already clear, local, and unlikely to grow. Be skeptical of an abstraction that adds indirection without removing branches, duplicated rules, invalid states, or lifecycle risk.
The sign that you skipped this is a new feature that grows an existing if/else chain by one more branch, or a second boolean that must stay in sync with the first. Temporal decomposition is another sign. Phase-named modules repeat the same domain rules across steps.
常见问题
每个问题都需要新的结构吗?
不需要。当前的形状清晰且不太可能增长时,该技能更倾向于使用普通代码。
一个常见的例子是什么?
用只允许有效转换的状态机,替换分散的布尔值。
为什么要尽早选择结构?
在编写时它的成本很低,而之后再补上正确的结构往往会被推迟,成本也更高。
详情
作者的原始描述
Apply when writing stateful logic, or when code branches a lot or repeats a shape assumption across files.
repo: cursor/plugins
热度
- GitHub 星标
- 15k
- 排名
- #10982
- 许可证
- —
- 更新时间
- 2026/10/31
评论
- …
同一仓库的更多技能
advisor
15k如果你开启该功能,让你的智能体在关键节点咨询一个更强的第二模型,例如在重大决定之前,或在错误上卡住时。
check-agent-compatibility
15k全面检查 AI 编程智能体能否启动、验证和记录某个代码仓库,并返回一个兼容性评分以及主要问题。
cli-for-agents
15k教你的智能体设计或审查命令行工具,使 AI 智能体无需提示即可运行,并提供清晰的帮助文字和示例。
continual-learning
15k通过把回顾过往对话的工作交给专门的记忆更新程序,使你的 AGENTS.md 笔记保持最新。