跳到正文
Skillpedia
通用编程15k · #10982

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。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/cursor/plugins/blob/main/harness/pstack/claude-code/skills/principle-model-the-domain/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 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

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能