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。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 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
评论
- …
同一仓库的更多技能
advisor
15k如果你开启该功能,让你的智能体在关键节点咨询一个更强的第二模型,例如在重大决定之前,或在错误上卡住时。
check-agent-compatibility
15k全面检查 AI 编程智能体能否启动、验证和记录某个代码仓库,并返回一个兼容性评分以及主要问题。
cli-for-agents
15k教你的智能体设计或审查命令行工具,使 AI 智能体无需提示即可运行,并提供清晰的帮助文字和示例。
continual-learning
15k通过把回顾过往对话的工作交给专门的记忆更新程序,使你的 AGENTS.md 笔记保持最新。