constraint-driven-development

Establishes a backend 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 suppression comments, 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 — coverage, API contracts, latency budgets, security scanning — set up as enforced constraints, when an agent keeps silencing checks or skipping tests to get to green, when you need a coverage or latency threshold and don't know what number to pick, or when an agent writes more code than anyone will read.

Qu'est-ce que constraint-driven-development ?

constraint-driven-development is a Claude Code agent skill that establishes a backend 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 suppression comments, 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 — coverage, API contracts, latency budgets, security scanning — set up as enforced constraints, when an agent keeps silencing checks or skipping tests to get to green, when you need a coverage or latency threshold and don't know what number to pick, or when an agent writes more code than anyone will read.

Compatible avec✓Claude Code✓Codex CLI~Cursor
npx skills add https://github.com/naimsulejmani/agent-skills-backend/tree/HEAD/skills/constraint-driven-development

Installed? Explore more Développement et programmation skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

Demander à votre IA préférée

Ouvre une nouvelle conversation avec cette compétence d'agent déjà préchargée.

Documentation

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 auto or any autonomous loop and need external gates beyond agent-written tests

When NOT to use:

  • The project already has a CONSTRAINTS.md and 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:

WhatWhere to look
Language and stack*.sln/*.csproj, pom.xml/build.gradle*, go.mod, package.json
Test runnerdotnet 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 contractsopenapi.yaml / swagger.json / *.proto / schema.graphql
Coverage todaycoverage/ / 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:

DimensionToolExample Run CommandGate on
Compile / Typesdotnet build, javac, go vet, tscdotnet build -warnaserror / go vet ./... / tsc --noEmitany error
Lintgolangci-lint, Checkstyle/SpotBugs, Roslyn, ESLint/Biomegolangci-lint run / ./gradlew check / eslint .any error
CoverageCoverlet (C#), JaCoCo (Java), go test -cover, Vitest/c8go test -coverprofile=cover.out ./... / vitest run --coveragechanged-line coverage
Duplicationjscpd (polyglot) / PMD CPD (Java) / SonarQubenpx jscpd --threshold 3 src/< 3% duplicated lines
Static Quality GateSonarQube / SonarCloud (dotnet-sonarscanner, Gradle/Maven Sonar, sonar-scanner)sonar-scanner -Dsonar.qualitygate.wait=true + quality-gate.mjs sonarqubeQuality Gate OK (0 new bugs/vulns, < 3% dup, Rating A, complexity ≤ 15)
Security: codeSemgrepsemgrep scan --config p/default --strict --json + quality-gate.mjshigh / critical / ERROR
Security: secretsgitleaksgitleaks dir . --redact --no-bannerany finding
Security: depsosv-scanner, govulncheck, dotnet list --vulnerable, npm auditosv-scanner scan source -r .high or above
API ContractSpectral (OpenAPI) / buf breaking (gRPC)spectral lint openapi.yaml -f json + quality-gate.mjszero errors
Latency / Loadk6, vegeta, go test -bench, BenchmarkDotNet, JMHk6 run loadtests/smoke.jsp95/p99 & error rate
ArchitectureArchUnit (Java), NetArchTest (C#), dependency-cruiser (TS/JS)Runs inside test suite or depcruise srcany boundary violation

Five things that will bite you if you skip them:

  1. --redact on gitleaks is not optional. Without it the matched secret lands in agent transcripts and logs.
  2. Load tests need a running target. Run k6 against 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.
  3. Scope expensive checks to the diff. Run Semgrep or mutation testing on changed files rather than the whole monorepo so it stays fast.
  4. Coverage needs no second test run. Read the coverage report your test run already emits and intersect it with git diff.
  5. 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's scripts/ directory (semgrep, spectral, or sonarqube) so blocking findings exit 1 and unreadable/incomplete reports exit 2.

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

PhaseCommandWhat runsBudget
BUILD/buildCompile/types, lint, secrets, the floorunder 5s, changed packages/files
VERIFY/testFocused unit + integration tests, changed-line coverage, contract lintunder 90s
REVIEW/reviewFull suite, SAST, architecture boundaries, floor guardminutes
SHIP/shipFull CI matrix, dependency audit, migration/load checksCI

Step 6: Guard the bar itself

Agents hit a red check and take the cheapest road to green. Watch the diff for five moves:

  1. The threshold moved. A budget lowered, a severity dropped, or a check removed from CONSTRAINTS.md.
  2. A test got easier. .skip, @Disabled, [Fact(Skip=...)], t.Skip, a deleted test file, or removed assertions.
  3. A checker got silenced. New @ts-ignore, eslint-disable, //nolint, @SuppressWarnings, #pragma warning disable, nosemgrep, or gitleaks:allow.
  4. Work is unfinished. NotImplementedException, UnsupportedOperationException, panic("not implemented"), empty catch {}, or placeholder TODO.
  5. 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

ConstraintDefaultWhy 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≤ 15SonarQube default; keeps control flow readable during incidents
SonarQube Quality GateOK (0 new bugs/vulns, Rating A)Enforces unified maintainability, security hotspots, coverage, and duplication
Project coveragetoday's value, must not fallZero-friction adoption on legacy services
Dependency vulnerabilitiesnothing at high or aboveBelow that is mostly noise
Read endpoint p95≤ 150 msKeeps multi-hop API calls responsive
Error rate under smoke load< 0.5%Catches broken routes, pool exhaustion, and uncaught exceptions
OpenAPI contract lintzero errorsPrevents malformed or breaking specs reaching consumers
Exception lifetime90 daysLong enough to schedule remediation, short enough not to rot
Ratchet tolerance0.5%Absorbs minor variance from unrelated edits

Escalation Path

  1. Written only. CONSTRAINTS.md exists and agents read it.
  2. Scripted. make check-fast / npm run check:fast wired into hooks and CI. Most projects stop here.
  3. Tool-backed. Dedicated diff-scoped runner + references/floor-guard.md when shell glue grows past ~30 lines.

Common Rationalizations

ExcuseReality
"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.md with a number but no runnable command
  • Every check is self-authored tests with zero external scanners or schema validators
  • CONSTRAINTS.md weakened 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.md exists 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.md or CLAUDE.md points to CONSTRAINTS.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 discipline
  • code-review-and-quality — review axes aligned with these constraints
  • ci-cd-and-automation — running these gates in CI
  • test-driven-development — test suites measured by coverage gates
  • security-and-hardening — security scanning and supply-chain controls
  • performance-optimization — latency and load budgets

Individual skills in this repo

This repo contains 1 individual skill — each has its own dedicated page.

Skills associés