# 约束驱动开发 (constraint-driven-development)

> 把项目质量标准写成 CONSTRAINTS.md 契约，并在 diff 中发现被悄悄降低的标准。

- 分类: [代码规范](https://www.myskills.tools/zh/categories/code-standards/)
- 来源: 社区 · Addy Osmani
- 代码仓库: https://github.com/addyosmani/agent-skills/tree/main/skills/constraint-driven-development (commit ba3d99e)
- SKILL.md: https://github.com/addyosmani/agent-skills/blob/main/skills/constraint-driven-development/SKILL.md
- 安装命令: `npx skills add addyosmani/agent-skills --skill constraint-driven-development`
- 许可证: MIT
- 兼容工具: Claude Code, Codex, Cursor, Copilot, Gemini CLI
- 权限: read-repo ✓, write-files ✓, shell ✓, network ✓
- 状态: 扫描通过
- 规则扫描无法覆盖所有风险，安装前请阅读此技能的 SKILL.md，确认权限后再使用。
- ⚠ 访谈需要用户在场，CI 或无人值守运行时只应用基础规则；gitleaks 必须加 --redact。

## 核心规则

不得为了让改动通过而削弱 CONSTRAINTS.md 中的标准。

## 执行阶段

1. **先探测再提问** — 先读取项目已有的测试、lint 和 CI 配置，能读到的就不问。
2. **四个带默认值的问题** — 逐一询问要约束的维度、失败时阻断还是警告、目标数值等，每题都给出默认值。
3. **写入并安装工具** — 写入 CONSTRAINTS.md，在 AGENTS.md 和 CLAUDE.md 中加一行提示，并为每个维度接入相应的检查工具。
4. **守住标准本身** — 在 diff 中检查阈值被调低、测试被跳过或删除、新增 @ts-ignore/eslint-disable 和未完成的桩代码。

## 权限说明（据 SKILL.md 整理）

| 能力 | 是否需要 | 说明 |
|---|---|---|
| 文件写入 | 需要 | 写入 CONSTRAINTS.md、检查脚本和工具配置，并在 AGENTS.md、CLAUDE.md 中各加一行。 |
| 命令执行 | 部分需要 | 安装并运行所选维度的检查工具（如 gitleaks、osv-scanner、Semgrep、Lighthouse、axe），昂贵的检查限定在 diff 范围。 |
| 网络外发 | 部分需要 | 用于安装检查工具和读取漏洞数据库等外部数据源。 |

## SKILL.md 头部信息（YAML）

```yaml
---
name: constraint-driven-development
description: Establishes a project's quality bar as a written contract and stops agents quietly lowering it. Interviews the user on which dimensions matter, supplies sane default thresholds when they have no number in mind, records everything in CONSTRAINTS.md, and watches the diff for a weakened bar — new @ts-ignore or eslint-disable suppressions, skipped or deleted tests, assertions stripped out, unimplemented stubs, thresholds edited down. Use when no quality bar is written down, when the user says "set up constraints" or "define our standards", when the user wants dimensions they care about — accessibility, web performance, coverage — set up as enforced constraints, when an agent keeps silencing checks or skipping tests to get to green, when you need a coverage or performance threshold and don't know what number to pick, or when an agent writes more code than anyone will read.
---
```

首页: https://www.myskills.tools/zh/ · URL: https://www.myskills.tools/zh/skills/constraint-driven-development/
