Constraint-Driven Development
Overview
Other skills in this pack describe what good looks like. code-review-and-quality gives you five axes. test-driven-development gives you a cycle. security-and-hardening gives you a threat list. All of that lives in prose the agent reads and may or may not follow, and none of it survives the end of the session.
This skill produces something different: a written record of this backend project's bar, with numbers, that outlives the conversation and can be checked mechanically.
When an agent writes more code in an afternoon than anyone will read that week, judgment moves into automated checks around the loop. Those checks need explicit thresholds, real commands, and fast feedback close to the edit.
Spec-driven development says what to build. Test-driven development proves it works. Constraint-driven development defines what "good enough to merge and deploy" means, before anyone argues about it in a pull request.
When to Use
Apply this skill when:
- Starting a backend service or major feature and no quality bar is written down
- The user asks to "set up constraints", "add quality gates", "define our standards", or "stop the agent shipping junk"
- An agent is producing volume nobody is reading line by line
- CI has checks but nobody can say which ones block a merge and which ones are decoration
- Coverage, latency, security, or API contract numbers get argued about per-PR instead of decided once
- You're about to run
/build autoor any autonomous loop and need external gates beyond agent-written tests
When NOT to use:
- The project already has a
CONSTRAINTS.mdand the user isn't changing it — read it and follow it instead - One-off scripts, spikes, or throwaway prototypes
- The user wants a code review right now (
code-review-and-quality) or a CI pipeline built (ci-cd-and-automation)
Loading Constraints
The interview needs a live user. Don't run it in non-interactive contexts (CI, /loop, autonomous runs). If constraints are missing and you're in one of those, apply the Floor below, note that you did, and flag the rest for a human.
The Process
Step 1: Detect before you ask
Never ask what you can read. Before the first question, gather:
| What | Where to look |
|---|---|
| Language and stack | *.sln/*.csproj, pom.xml/build.gradle*, go.mod, package.json |
| Test runner | dotnet test, ./mvnw/./gradlew, go test, vitest/jest/node --test |
| Existing linters & analyzers | .editorconfig, Directory.Build.props, checkstyle.xml, .golangci.yml, eslint.config.*, biome.json |
| API contracts | openapi.yaml / swagger.json / *.proto / schema.graphql |
| Coverage today | coverage/ / Cobertura / JaCoCo / cover.out, or run the suite once |
| CI & Agent harness | .github/workflows/, .gitlab-ci.yml, .claude/, .codex/, AGENTS.md |
Report what you found in two lines, then ask only what's left.
Step 2: Four questions, each with a default
Follow the one-question-at-a-time discipline from interview-me, with one change: every question has a default so "I don't know" still produces a working config.
Q1: Beyond the floor, which of these do you want enforced?
(a) Test coverage, duplication (< 3%), and SonarQube quality gate
(b) Security & dependency scanning (SAST + CVE + secrets)
(c) API contract & schema linting (OpenAPI / Protobuf)
(d) Latency & load budgets (p95/p99 via k6 or benchmarks)
(e) Architecture boundaries (ArchUnit / NetArchTest / depcruise)
GUESS: (a) and (b) — you have a test runner already and you handle external requests.
DEFAULT if unsure: (a) and (b).
Say what each pick costs: (c) needs a committed schema, (d) needs a running service or benchmark target, (e) needs a boundary test/rules file.
Q2: When a check fails while the agent is mid-task, should it block or warn?
GUESS: Block. You're running agents with limited review bandwidth and warnings get ignored.
DEFAULT if unsure: Block on the floor, warn on everything else for the first two weeks.
Q3: Do you have target numbers in mind, or should I measure where you are today and hold that line?
GUESS: Measure. Most teams don't have a number, and an invented one gets ignored.
DEFAULT if unsure: Measure and hold. See "Ratchets" below.
Q4: What's the slowest check you'll tolerate before the agent hands work back?
GUESS: About 90 seconds. Longer and people pass --no-verify.
DEFAULT if unsure: 90 seconds at task end, unlimited in CI.
Stop at four.
Step 3: Write CONSTRAINTS.md
One file at the repo root. Any agent on any harness can read it, and changes show up in review where they belong.
# Constraints
Last reviewed: 2026-08-08 by @owner
## Floor (always enforced, no setup required)
- No new suppression comments: `@ts-ignore`, `eslint-disable`, `//nolint`, `@SuppressWarnings`, `#pragma warning disable`
- No unimplemented stubs: `throw new Error("Not implemented")`, `NotImplementedException`, `UnsupportedOperationException`, `panic("not implemented")`, empty `catch {}`
- No skipped or deleted tests without a reason in the commit message
- No secrets in source
- This file does not get weakened to make a change pass
## Enforced with numbers
| Dimension | Rule | Checked by | Runs at |
|-----------|------|-----------|---------|
| Compile / Types | Zero compiler/type errors or warnings | `dotnet build -warnaserror` / `go vet ./...` / `tsc --noEmit` | every edit |
| Lint | Zero errors from project config | `golangci-lint run` / `eslint .` / `./gradlew checkstyleMain` | every edit |
| Secrets | No secrets in source | `gitleaks dir . --redact --no-banner` | every edit |
| Coverage | Changed lines ≥ 80% covered | repo coverage command + git diff | task end, CI |
| Duplication & Complexity | Duplicated lines < 3%, cognitive complexity ≤ 15 | `npx jscpd --threshold 3 src/` + SonarQube Quality Gate | task end, CI |
| SonarQube Quality Gate | Clean as You Code: 0 new bugs/vulns, Rating A, < 3% dup | `sonar-scanner -Dsonar.qualitygate.wait=true` (or `quality-gate.mjs sonarqube`) | CI |
| Security: code | Nothing at high or above | `semgrep scan --config p/default --strict --json > semgrep.json && node scripts/quality-gate.mjs semgrep semgrep.json` | CI |
| Security: deps | Nothing at high or above | `osv-scanner scan source -r .` (or `govulncheck ./...` / `dotnet list package --vulnerable`) | CI |
| API Contract | Zero OpenAPI errors | `spectral lint openapi.yaml -f json > spectral.json && node scripts/quality-gate.mjs spectral spectral.json` | task end, CI |
| Performance | Read p95 ≤ 150ms, 5xx < 0.5% | `k6 run --threshold 'http_req_duration{p(95)}<150' loadtests/smoke.js` | staging / CI |
Every row names the command that produces the verdict. A dimension with a
number and no command in this column is an aspiration, not a constraint.
## Measured, not yet enforced
| Metric | Today | Direction |
|--------|-------|-----------|
| Project coverage | 68.4% | must not fall |
| Container image size | 112 MB | must not grow |
## Exceptions
| ID | Rule | Path | Reason | Owner | Expires |
|----|------|------|--------|-------|---------|
| W1 | `CA1062` | `src/Legacy/**` | Rewrite tracked in ENG-441 | @owner | 2026-11-01 |
Then add one line to AGENTS.md and CLAUDE.md: Read CONSTRAINTS.md before writing code. Do not weaken it to make a change pass.
Step 4: Install what each dimension needs
Picking a dimension means wiring a real tool — don't hand-roll checkers when de facto tools exist:
| Dimension | Tool | Example Run Command | Gate on |
|---|---|---|---|
| Compile / Types | dotnet build, javac, go vet, tsc | dotnet build -warnaserror / go vet ./... / tsc --noEmit | any error |
| Lint | golangci-lint, Checkstyle/SpotBugs, Roslyn, ESLint/Biome | golangci-lint run / ./gradlew check / eslint . | any error |
| Coverage | Coverlet (C#), JaCoCo (Java), go test -cover, Vitest/c8 | go test -coverprofile=cover.out ./... / vitest run --coverage | changed-line coverage |
| Duplication | jscpd (polyglot) / PMD CPD (Java) / SonarQube | npx jscpd --threshold 3 src/ | < 3% duplicated lines |
| Static Quality Gate | SonarQube / SonarCloud (dotnet-sonarscanner, Gradle/Maven Sonar, sonar-scanner) | sonar-scanner -Dsonar.qualitygate.wait=true + quality-gate.mjs sonarqube | Quality Gate OK (0 new bugs/vulns, < 3% dup, Rating A, complexity ≤ 15) |
| Security: code | Semgrep | semgrep scan --config p/default --strict --json + quality-gate.mjs | high / critical / ERROR |
| Security: secrets | gitleaks | gitleaks dir . --redact --no-banner | any finding |
| Security: deps | osv-scanner, govulncheck, dotnet list --vulnerable, npm audit | osv-scanner scan source -r . | high or above |
| API Contract | Spectral (OpenAPI) / buf breaking (gRPC) | spectral lint openapi.yaml -f json + quality-gate.mjs | zero errors |
| Latency / Load | k6, vegeta, go test -bench, BenchmarkDotNet, JMH | k6 run loadtests/smoke.js | p95/p99 & error rate |
| Architecture | ArchUnit (Java), NetArchTest (C#), dependency-cruiser (TS/JS) | Runs inside test suite or depcruise src | any boundary violation |
Five things that will bite you if you skip them:
--redacton gitleaks is not optional. Without it the matched secret lands in agent transcripts and logs.- Load tests need a running target. Run
k6against a local test container or staging URL; if the project is a library or batch CLI, use micro-benchmarks (go test -bench, JMH, BenchmarkDotNet) instead. - Scope expensive checks to the diff. Run Semgrep or mutation testing on changed files rather than the whole monorepo so it stays fast.
- Coverage needs no second test run. Read the coverage report your test run already emits and intersect it with
git diff. - Verify the gate fails closed.
semgrep,spectral, and SonarQube status checks can be bypassed if not wired strictly; copy scripts/quality-gate.mjs into your project'sscripts/directory (semgrep,spectral, orsonarqube) so blocking findings exit1and unreadable/incomplete reports exit2.
Wire commands into a Makefile, Taskfile, or package.json so they are reproducible without an agent:
check-fast:
go vet ./... && golangci-lint run && gitleaks dir . --redact --no-banner
check-task: check-fast
go test -race -coverprofile=cover.out ./...
check-security:
semgrep scan --config p/default --strict --json > semgrep-results.json && \
node scripts/quality-gate.mjs semgrep semgrep-results.json
check-contract:
spectral lint openapi.yaml -f json > spectral-results.json && \
node scripts/quality-gate.mjs spectral spectral-results.json
check-full: check-task check-security check-contract
osv-scanner scan source -r .
Before calling any row enforced, test it against a deliberate violation and a clean control to confirm the violation fails, the control passes, and scanner errors fail closed.
Step 5: Wire it to the lifecycle
| Phase | Command | What runs | Budget |
|---|---|---|---|
| BUILD | /build | Compile/types, lint, secrets, the floor | under 5s, changed packages/files |
| VERIFY | /test | Focused unit + integration tests, changed-line coverage, contract lint | under 90s |
| REVIEW | /review | Full suite, SAST, architecture boundaries, floor guard | minutes |
| SHIP | /ship | Full CI matrix, dependency audit, migration/load checks | CI |
Step 6: Guard the bar itself
Agents hit a red check and take the cheapest road to green. Watch the diff for five moves:
- The threshold moved. A budget lowered, a severity dropped, or a check removed from
CONSTRAINTS.md. - A test got easier.
.skip,@Disabled,[Fact(Skip=...)],t.Skip, a deleted test file, or removed assertions. - A checker got silenced. New
@ts-ignore,eslint-disable,//nolint,@SuppressWarnings,#pragma warning disable,nosemgrep, orgitleaks:allow. - Work is unfinished.
NotImplementedException,UnsupportedOperationException,panic("not implemented"), emptycatch {}, or placeholderTODO. - An exception appeared. A new row in the Exceptions table nobody approved.
A reference diff-scoped implementation of these five checks ships in references/floor-guard.md (exit 0/1/2). Adapt its patterns rather than reinventing a guard from scratch.
Include at least one external check. Your own unit tests are circular (an agent can write passing tests for broken code); external checks (osv-scanner, semgrep, gitleaks, spectral, Testcontainers against real PostgreSQL) bring an independent opinion.
Step 7: Ratchets, when you don't have a number
Record where the project stands today in "Measured, not yet enforced" with a direction (must not fall / must not grow). Refuse regressions; raise the baseline whenever metrics improve.
Sane Defaults
| Constraint | Default | Why this number |
|---|---|---|
| Coverage of changed lines | ≥ 80% | High enough to force behavioral tests, allows trivial wiring/config |
| Duplicated lines (new code) | < 3% | Matches SonarQube's Clean-as-You-Code gate; stops copy-paste drift |
| Cognitive complexity per function | ≤ 15 | SonarQube default; keeps control flow readable during incidents |
| SonarQube Quality Gate | OK (0 new bugs/vulns, Rating A) | Enforces unified maintainability, security hotspots, coverage, and duplication |
| Project coverage | today's value, must not fall | Zero-friction adoption on legacy services |
| Dependency vulnerabilities | nothing at high or above | Below that is mostly noise |
| Read endpoint p95 | ≤ 150 ms | Keeps multi-hop API calls responsive |
| Error rate under smoke load | < 0.5% | Catches broken routes, pool exhaustion, and uncaught exceptions |
| OpenAPI contract lint | zero errors | Prevents malformed or breaking specs reaching consumers |
| Exception lifetime | 90 days | Long enough to schedule remediation, short enough not to rot |
| Ratchet tolerance | 0.5% | Absorbs minor variance from unrelated edits |
Escalation Path
- Written only.
CONSTRAINTS.mdexists and agents read it. - Scripted.
make check-fast/npm run check:fastwired into hooks and CI. Most projects stop here. - Tool-backed. Dedicated diff-scoped runner + references/floor-guard.md when shell glue grows past ~30 lines.
Common Rationalizations
| Excuse | Reality |
|---|---|
| "We'll add constraints once the service stabilizes" | Services stabilize around whatever shortcuts were allowed while moving fast. |
| "The tests are the constraints" | Self-written tests say nothing about changed-line coverage, CVEs, leaked secrets, or contract drift. |
| "We can't hit 80% coverage" | Set today's number as a ratchet and hold the line instead of picking nothing. |
| "This will slow the agent down" | Only if slow checks are placed in the edit loop. Match check cost to lifecycle stage. |
| "Constraints will block shipping" | A timed exception with an owner unblocks a release safely; deleting the rule removes the guardrail forever. |
Red Flags
- Interview ran past four questions or produced rules the team can't explain
- A dimension written in
CONSTRAINTS.mdwith a number but no runnable command - Every check is self-authored tests with zero external scanners or schema validators
CONSTRAINTS.mdweakened in the same commit as a failing feature change- An exception row with no owner or an expiry more than a year out
- Slow checks placed in the fast edit loop causing engineers to pass
--no-verify
Verification
The skill was applied correctly when:
-
CONSTRAINTS.mdexists and every threshold states a rationale and runnable command - The floor is enforced and passes on the current branch without edits
- Every selected dimension has an installed tool and working command
- Fast edit checks finish within seconds; heavier gates live at task end or CI
- At least one external constraint (SAST, CVE scan, contract lint, or real DB/load check) is active
- Measured-only metrics record today's baseline and direction
- Exceptions have an owner and expiry date
-
AGENTS.mdorCLAUDE.mdpoints toCONSTRAINTS.md - Each enforced command fails closed on a deliberate violation and scanner error, and passes on a clean control
See Also
interview-me— one-question-at-a-time intake disciplinecode-review-and-quality— review axes aligned with these constraintsci-cd-and-automation— running these gates in CItest-driven-development— test suites measured by coverage gatessecurity-and-hardening— security scanning and supply-chain controlsperformance-optimization— latency and load budgets