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

principle-boundary-discipline

它能做什么

为智能体提供一条关于检查和错误处理应放在代码何处的规则。适合希望减少冗余守卫、让代码更易测试的开发者。

适用场景

  • ✓当你正在为一个程序接入验证或错误处理的时候。
  • ✓当同样的检查在许多内部函数中重复出现的时候。
  • ✓当你希望业务逻辑保存在易于测试的纯函数中的时候。

技能链接

https://github.com/cursor/plugins/blob/main/harness/pstack/claude-code/skills/principle-boundary-discipline/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

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

可以这样问 AI

“在这个服务中,我应该在哪里验证配置和 API 响应,才能让其余代码保持简单?”

每周 5 个新技能,1 分钟读完。

工作原理

智能体会把验证放在边界处,例如命令行参数、配置文件和外部调用,然后信任内部已经带类型的数据。它会把业务逻辑保存在不依赖框架即可运行的纯函数中。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Boundary Discipline

Place validation, type narrowing, and error handling at system boundaries. Trust internal code unconditionally. Business logic lives in pure functions. The shell is thin and mechanical.

Why: Scattered validation is noisy, redundant, and gives a false sense of safety. Keep logic out of framework wiring so it can be tested without the framework.

The pattern:

  • At boundaries (CLI args, config files, external APIs, network protocols): validate, return errors, handle defensively.
  • Inside the system: typed data, error propagation, no re-validation. Trust the types.
  • Across the boundary. Expose domain concepts, not the boundary's private representation. Keep general-purpose mechanism inside and special-purpose policy at the edge.

Applications:

Validation and error handling:

  • Validate config at parse time (the boundary), not inside business logic
  • Parse raw data into domain types at the boundary
  • Do not re-export transport, storage, framework, or wire types through the public surface
  • No redundant nil checks deep in call chains if the boundary already validated

Code organization:

  • Business logic in pure functions with no framework dependencies
  • Parse functions: pure transforms from raw bytes to typed state
  • Prompt construction: structured state in, string out
  • Scoring and assessment: pure transforms from state to results

The tests:

  • "Is this data crossing a system boundary right now?" If not, validation is redundant.
  • "Can this be a pure function that the shell just calls?" If yes, extract it.
常见问题

为什么不在每个地方都做验证?

分散的检查既嘈杂又重复,还会造成一种虚假的安全感。

系统内部应该包含什么?

带类型的数据和错误传递,不再对边界已经验证过的值重复检查。

为什么要把逻辑放在框架之外?

这样无需启动框架就能进行测试。

详情

作者的原始描述

Apply when wiring validation, error handling, or framework adapters. Concentrate guards at system boundaries (CLI, config, network, external APIs); trust internal types and keep business logic in pure functions.

repo: cursor/plugins

热度

GitHub 星标
15k
排名
#10974
许可证
—
更新时间
2026/10/31

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能