@givolt/i3-composer-agent 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.agents/plugins/marketplace.json +23 -0
- package/.claude/commands/build.md +44 -0
- package/.claude/commands/code-simplify.md +22 -0
- package/.claude/commands/constraints.md +32 -0
- package/.claude/commands/plan.md +18 -0
- package/.claude/commands/review.md +16 -0
- package/.claude/commands/ship.md +72 -0
- package/.claude/commands/spec.md +17 -0
- package/.claude/commands/test.md +19 -0
- package/.claude/commands/webperf.md +32 -0
- package/.claude-plugin/marketplace.json +27 -0
- package/.claude-plugin/plugin.json +19 -0
- package/.codex-plugin/plugin.json +28 -0
- package/.gemini/commands/build.toml +43 -0
- package/.gemini/commands/code-simplify.toml +22 -0
- package/.gemini/commands/constraints.toml +32 -0
- package/.gemini/commands/planning.toml +18 -0
- package/.gemini/commands/review.toml +16 -0
- package/.gemini/commands/ship.toml +72 -0
- package/.gemini/commands/spec.toml +17 -0
- package/.gemini/commands/test.toml +19 -0
- package/.gemini/commands/webperf.toml +32 -0
- package/CHANGELOG.md +23 -0
- package/LICENSE +21 -0
- package/NOTICE.md +9 -0
- package/README.md +117 -2
- package/agents/code-reviewer.md +102 -0
- package/agents/security-auditor.md +112 -0
- package/agents/test-engineer.md +95 -0
- package/agents/web-performance-auditor.md +184 -0
- package/bin/i3-composer-agent.cjs +122 -0
- package/commands/build.toml +43 -0
- package/commands/code-simplify.toml +22 -0
- package/commands/constraints.toml +32 -0
- package/commands/planning.toml +18 -0
- package/commands/review.toml +16 -0
- package/commands/ship.toml +72 -0
- package/commands/spec.toml +17 -0
- package/commands/test.toml +19 -0
- package/commands/webperf.toml +32 -0
- package/docs/adoption-guide.md +129 -0
- package/docs/advanced-per-agent-configuration.md +70 -0
- package/docs/agents.md +123 -0
- package/docs/antigravity-setup.md +128 -0
- package/docs/codebuddy-setup.md +41 -0
- package/docs/codex-setup.md +34 -0
- package/docs/commandcode-setup.md +69 -0
- package/docs/comparison.md +131 -0
- package/docs/copilot-cli-setup.md +64 -0
- package/docs/copilot-setup.md +162 -0
- package/docs/cursor-setup.md +225 -0
- package/docs/developer-onboarding.md +116 -0
- package/docs/gemini-cli-setup.md +133 -0
- package/docs/getting-started.md +208 -0
- package/docs/opencode-setup.md +259 -0
- package/docs/other-hosts.md +7 -0
- package/docs/skill-anatomy.md +203 -0
- package/docs/windsurf-setup.md +48 -0
- package/evals/README.md +101 -0
- package/evals/cases/api-and-interface-design.json +45 -0
- package/evals/cases/browser-testing-with-devtools.json +44 -0
- package/evals/cases/ci-cd-and-automation.json +45 -0
- package/evals/cases/code-review-and-quality.json +49 -0
- package/evals/cases/code-simplification.json +45 -0
- package/evals/cases/constraint-driven-development.json +79 -0
- package/evals/cases/context-engineering.json +44 -0
- package/evals/cases/debugging-and-error-recovery.json +58 -0
- package/evals/cases/deprecation-and-migration.json +52 -0
- package/evals/cases/documentation-and-adrs.json +44 -0
- package/evals/cases/doubt-driven-development.json +43 -0
- package/evals/cases/frontend-ui-engineering.json +52 -0
- package/evals/cases/git-workflow-and-versioning.json +47 -0
- package/evals/cases/idea-refine.json +43 -0
- package/evals/cases/incremental-implementation.json +57 -0
- package/evals/cases/interview-me.json +42 -0
- package/evals/cases/observability-and-instrumentation.json +44 -0
- package/evals/cases/performance-optimization.json +53 -0
- package/evals/cases/planning-and-task-breakdown.json +45 -0
- package/evals/cases/security-and-hardening.json +53 -0
- package/evals/cases/shipping-and-launch.json +56 -0
- package/evals/cases/source-driven-development.json +44 -0
- package/evals/cases/spec-driven-development.json +72 -0
- package/evals/cases/test-driven-development.json +73 -0
- package/evals/cases/using-agent-skills.json +44 -0
- package/evals/fixtures/api-and-interface-design/service-brief.md +19 -0
- package/evals/fixtures/browser-testing-with-devtools/README.md +5 -0
- package/evals/fixtures/browser-testing-with-devtools/index.html +24 -0
- package/evals/fixtures/browser-testing-with-devtools/server.js +15 -0
- package/evals/fixtures/ci-cd-and-automation/package.json +8 -0
- package/evals/fixtures/ci-cd-and-automation/src/slug.js +3 -0
- package/evals/fixtures/ci-cd-and-automation/test/slug.test.js +9 -0
- package/evals/fixtures/code-review-and-quality/user-search.diff +16 -0
- package/evals/fixtures/code-simplification/config-parser.js +46 -0
- package/evals/fixtures/code-simplification/config-parser.test.js +15 -0
- package/evals/fixtures/context-engineering/context-audit.md +15 -0
- package/evals/fixtures/debugging-and-error-recovery/pagination.js +8 -0
- package/evals/fixtures/debugging-and-error-recovery/pagination.test.js +9 -0
- package/evals/fixtures/debugging-and-error-recovery/time-pressure.md +6 -0
- package/evals/fixtures/deprecation-and-migration/api-inventory.md +9 -0
- package/evals/fixtures/documentation-and-adrs/decision-context.md +16 -0
- package/evals/fixtures/doubt-driven-development/migration-plan.md +19 -0
- package/evals/fixtures/frontend-ui-engineering/Button.tsx +7 -0
- package/evals/fixtures/frontend-ui-engineering/design-system.md +11 -0
- package/evals/fixtures/git-workflow-and-versioning/.eval/working-tree.patch +21 -0
- package/evals/fixtures/git-workflow-and-versioning/app.js +7 -0
- package/evals/fixtures/git-workflow-and-versioning/app.test.js +9 -0
- package/evals/fixtures/incremental-implementation/reports.js +7 -0
- package/evals/fixtures/incremental-implementation/reports.test.js +12 -0
- package/evals/fixtures/incremental-implementation/tasks/plan.md +8 -0
- package/evals/fixtures/incremental-implementation-pressure/draft-export.js +17 -0
- package/evals/fixtures/incremental-implementation-pressure/scenario.md +9 -0
- package/evals/fixtures/observability-and-instrumentation/operations.md +11 -0
- package/evals/fixtures/observability-and-instrumentation/payment-retry.js +14 -0
- package/evals/fixtures/performance-optimization/benchmark.js +15 -0
- package/evals/fixtures/performance-optimization/products.js +14 -0
- package/evals/fixtures/planning-and-task-breakdown/notifications-spec.md +18 -0
- package/evals/fixtures/security-and-hardening/webhook.js +11 -0
- package/evals/fixtures/security-and-hardening/webhook.test.js +13 -0
- package/evals/fixtures/shipping-and-launch/authority-pressure.md +6 -0
- package/evals/fixtures/shipping-and-launch/launch-status.md +11 -0
- package/evals/fixtures/source-driven-development/framework-task.md +10 -0
- package/evals/fixtures/spec-driven-development/billing-brief.md +16 -0
- package/evals/fixtures/spec-driven-development-decomposition/portal-brief.md +22 -0
- package/evals/fixtures/test-driven-development/BUG.md +10 -0
- package/evals/fixtures/test-driven-development/README.md +28 -0
- package/evals/fixtures/test-driven-development/package.json +9 -0
- package/evals/fixtures/test-driven-development/src/split.js +8 -0
- package/evals/fixtures/test-driven-development/test/split.test.js +13 -0
- package/evals/fixtures/test-driven-development-ecosystem/README.md +9 -0
- package/evals/fixtures/test-driven-development-ecosystem/ledger.py +15 -0
- package/evals/fixtures/test-driven-development-ecosystem/test_ledger.py +19 -0
- package/evals/fixtures/using-agent-skills/incident.md +6 -0
- package/evals/plugin/code-review-fires/graders/off-by-one.md +7 -0
- package/evals/plugin/code-review-fires/graders/severity-labels.md +4 -0
- package/evals/plugin/code-review-fires/graders/skill-fired.md +5 -0
- package/evals/plugin/code-review-fires/prompt.md +31 -0
- package/evals/plugin/code-review-stays-quiet/graders/not-fired.md +8 -0
- package/evals/plugin/code-review-stays-quiet/graders/tdd-fired.md +6 -0
- package/evals/plugin/code-review-stays-quiet/prompt.md +8 -0
- package/evals/plugin/code-review-stays-quiet-on-commit-message/graders/not-fired.md +8 -0
- package/evals/plugin/code-review-stays-quiet-on-commit-message/prompt.md +25 -0
- package/evals/skill-impact.md +6 -0
- package/hooks/SDD-CACHE.md +167 -0
- package/hooks/SIMPLIFY-IGNORE.md +91 -0
- package/hooks/sdd-cache-post.sh +135 -0
- package/hooks/sdd-cache-pre.sh +106 -0
- package/hooks/sdd-cache-test.sh +246 -0
- package/hooks/session-start-test.sh +47 -0
- package/hooks/session-start.sh +33 -0
- package/hooks/simplify-ignore-test.sh +476 -0
- package/hooks/simplify-ignore.sh +352 -0
- package/package.json +89 -4
- package/plugin.json +7 -0
- package/rebrand/MAINTENANCE.md +112 -0
- package/rebrand/NOTICE.md +9 -0
- package/rebrand/PR-WORKFLOW.md +34 -0
- package/rebrand/UNIFICATION-SPEC.md +33 -0
- package/rebrand/VALIDATION.md +28 -0
- package/rebrand/VERSIONING.md +32 -0
- package/rebrand/apply.cjs +194 -0
- package/rebrand/brand.json +13 -0
- package/rebrand/catalog.cjs +56 -0
- package/rebrand/fork-patches.json +12 -0
- package/rebrand/overlay/.github/workflows/test-plugin-install.yml +177 -0
- package/rebrand/overlay/CHANGELOG.md +23 -0
- package/rebrand/overlay/bin/i3-composer-agent.cjs +122 -0
- package/rebrand/overlay/scripts/validate-brand.cjs +44 -0
- package/rebrand/overlay/tests/bundle.test.cjs +85 -0
- package/rebrand/package.template.json +82 -0
- package/rebrand/rebrand.sh +4 -0
- package/rebrand/record-upstream.cjs +37 -0
- package/rebrand/templates/README.md +86 -0
- package/rebrand/templates/codebuddy-setup.md +41 -0
- package/rebrand/templates/codex-setup.md +34 -0
- package/rebrand/tests/pipeline.test.cjs +185 -0
- package/rebrand/upstream.json +171 -0
- package/references/accessibility-checklist.md +160 -0
- package/references/definition-of-done.md +67 -0
- package/references/observability-checklist.md +92 -0
- package/references/orchestration-patterns.md +370 -0
- package/references/performance-checklist.md +236 -0
- package/references/security-checklist.md +248 -0
- package/references/testing-patterns.md +235 -0
- package/scripts/floor-guard-reference-test.js +291 -0
- package/scripts/lib/skill-lint-test.js +650 -0
- package/scripts/lib/skill-lint.js +584 -0
- package/scripts/run-evals-test.js +623 -0
- package/scripts/run-evals.js +638 -0
- package/scripts/validate-artifact-paths-test.js +179 -0
- package/scripts/validate-artifact-paths.js +128 -0
- package/scripts/validate-brand.cjs +44 -0
- package/scripts/validate-commands-test.js +216 -0
- package/scripts/validate-commands.js +222 -0
- package/scripts/validate-reference-links-test.js +495 -0
- package/scripts/validate-reference-links.js +187 -0
- package/scripts/validate-skills.js +69 -0
- package/scripts/validate-versions-test.js +32 -0
- package/scripts/validate-versions.js +35 -0
- package/skills/api-and-interface-design/SKILL.md +367 -0
- package/skills/browser-testing-with-devtools/SKILL.md +317 -0
- package/skills/ci-cd-and-automation/SKILL.md +390 -0
- package/skills/code-review-and-quality/SKILL.md +398 -0
- package/skills/code-simplification/SKILL.md +331 -0
- package/skills/constraint-driven-development/SKILL.md +311 -0
- package/skills/constraint-driven-development/references/floor-guard.md +182 -0
- package/skills/context-engineering/SKILL.md +353 -0
- package/skills/debugging-and-error-recovery/SKILL.md +300 -0
- package/skills/deprecation-and-migration/SKILL.md +247 -0
- package/skills/documentation-and-adrs/SKILL.md +288 -0
- package/skills/doubt-driven-development/SKILL.md +243 -0
- package/skills/frontend-ui-engineering/SKILL.md +340 -0
- package/skills/git-workflow-and-versioning/SKILL.md +355 -0
- package/skills/idea-refine/SKILL.md +178 -0
- package/skills/idea-refine/examples.md +238 -0
- package/skills/idea-refine/frameworks.md +99 -0
- package/skills/idea-refine/refinement-criteria.md +113 -0
- package/skills/idea-refine/scripts/idea-refine.sh +15 -0
- package/skills/incremental-implementation/SKILL.md +249 -0
- package/skills/interview-me/SKILL.md +235 -0
- package/skills/observability-and-instrumentation/SKILL.md +238 -0
- package/skills/performance-optimization/SKILL.md +267 -0
- package/skills/performance-optimization/references/optimization-patterns.md +250 -0
- package/skills/planning-and-task-breakdown/SKILL.md +257 -0
- package/skills/security-and-hardening/SKILL.md +216 -0
- package/skills/security-and-hardening/references/hardening-patterns.md +324 -0
- package/skills/shipping-and-launch/SKILL.md +330 -0
- package/skills/source-driven-development/SKILL.md +216 -0
- package/skills/spec-driven-development/SKILL.md +259 -0
- package/skills/test-driven-development/SKILL.md +398 -0
- package/skills/using-agent-skills/SKILL.md +192 -0
- package/tests/bundle.test.cjs +85 -0
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: code-simplification
|
|
3
|
+
description: Simplifies code for clarity. Use when refactoring code for clarity without changing behavior. Use when code works but is harder to read, maintain, or extend than it should be. Use when reviewing code that has accumulated unnecessary complexity.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Code Simplification
|
|
7
|
+
|
|
8
|
+
> Inspired by the [Claude Code Simplifier plugin](https://github.com/anthropics/claude-plugins-official/blob/main/plugins/code-simplifier/agents/code-simplifier.md). Adapted here as a model-agnostic, process-driven skill for any AI coding agent.
|
|
9
|
+
|
|
10
|
+
## Overview
|
|
11
|
+
|
|
12
|
+
Simplify code by reducing complexity while preserving exact behavior. The goal is not fewer lines — it's code that is easier to read, understand, modify, and debug. Every simplification must pass a simple test: "Would a new team member understand this faster than the original?"
|
|
13
|
+
|
|
14
|
+
## When to Use
|
|
15
|
+
|
|
16
|
+
- After a feature is working and tests pass, but the implementation feels heavier than it needs to be
|
|
17
|
+
- During code review when readability or complexity issues are flagged
|
|
18
|
+
- When you encounter deeply nested logic, long functions, or unclear names
|
|
19
|
+
- When refactoring code written under time pressure
|
|
20
|
+
- When consolidating related logic scattered across files
|
|
21
|
+
- After merging changes that introduced duplication or inconsistency
|
|
22
|
+
|
|
23
|
+
**When NOT to use:**
|
|
24
|
+
|
|
25
|
+
- Code is already clean and readable — don't simplify for the sake of it
|
|
26
|
+
- You don't understand what the code does yet — comprehend before you simplify
|
|
27
|
+
- The code is performance-critical and the "simpler" version would be measurably slower
|
|
28
|
+
- You're about to rewrite the module entirely — simplifying throwaway code wastes effort
|
|
29
|
+
|
|
30
|
+
## The Five Principles
|
|
31
|
+
|
|
32
|
+
### 1. Preserve Behavior Exactly
|
|
33
|
+
|
|
34
|
+
Don't change what the code does — only how it expresses it. All inputs, outputs, side effects, error behavior, and edge cases must remain identical. If you're not sure a simplification preserves behavior, don't make it.
|
|
35
|
+
|
|
36
|
+
```
|
|
37
|
+
ASK BEFORE EVERY CHANGE:
|
|
38
|
+
→ Does this produce the same output for every input?
|
|
39
|
+
→ Does this maintain the same error behavior?
|
|
40
|
+
→ Does this preserve the same side effects and ordering?
|
|
41
|
+
→ Do all existing tests still pass without modification?
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### 2. Follow Project Conventions
|
|
45
|
+
|
|
46
|
+
Simplification means making code more consistent with the codebase, not imposing external preferences. Before simplifying:
|
|
47
|
+
|
|
48
|
+
```
|
|
49
|
+
1. Read CLAUDE.md / project conventions
|
|
50
|
+
2. Study how neighboring code handles similar patterns
|
|
51
|
+
3. Match the project's style for:
|
|
52
|
+
- Import ordering and module system
|
|
53
|
+
- Function declaration style
|
|
54
|
+
- Naming conventions
|
|
55
|
+
- Error handling patterns
|
|
56
|
+
- Type annotation depth
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Simplification that breaks project consistency is not simplification — it's churn.
|
|
60
|
+
|
|
61
|
+
### 3. Prefer Clarity Over Cleverness
|
|
62
|
+
|
|
63
|
+
Explicit code is better than compact code when the compact version requires a mental pause to parse.
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
// UNCLEAR: Dense ternary chain
|
|
67
|
+
const label = isNew ? 'New' : isUpdated ? 'Updated' : isArchived ? 'Archived' : 'Active';
|
|
68
|
+
|
|
69
|
+
// CLEAR: Readable mapping
|
|
70
|
+
function getStatusLabel(item: Item): string {
|
|
71
|
+
if (item.isNew) return 'New';
|
|
72
|
+
if (item.isUpdated) return 'Updated';
|
|
73
|
+
if (item.isArchived) return 'Archived';
|
|
74
|
+
return 'Active';
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
```typescript
|
|
79
|
+
// UNCLEAR: Chained reduces with inline logic
|
|
80
|
+
const result = items.reduce((acc, item) => ({
|
|
81
|
+
...acc,
|
|
82
|
+
[item.id]: { ...acc[item.id], count: (acc[item.id]?.count ?? 0) + 1 }
|
|
83
|
+
}), {});
|
|
84
|
+
|
|
85
|
+
// CLEAR: Named intermediate step
|
|
86
|
+
const countById = new Map<string, number>();
|
|
87
|
+
for (const item of items) {
|
|
88
|
+
countById.set(item.id, (countById.get(item.id) ?? 0) + 1);
|
|
89
|
+
}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### 4. Maintain Balance
|
|
93
|
+
|
|
94
|
+
Simplification has a failure mode: over-simplification. Watch for these traps:
|
|
95
|
+
|
|
96
|
+
- **Inlining too aggressively** — removing a helper that gave a concept a name makes the call site harder to read
|
|
97
|
+
- **Combining unrelated logic** — two simple functions merged into one complex function is not simpler
|
|
98
|
+
- **Removing "unnecessary" abstraction** — some abstractions exist for extensibility or testability, not complexity
|
|
99
|
+
- **Optimizing for line count** — fewer lines is not the goal; easier comprehension is
|
|
100
|
+
|
|
101
|
+
### 5. Scope to What Changed
|
|
102
|
+
|
|
103
|
+
Default to simplifying recently modified code. Avoid drive-by refactors of unrelated code unless explicitly asked to broaden scope. Unscoped simplification creates noise in diffs and risks unintended regressions.
|
|
104
|
+
|
|
105
|
+
## The Simplification Process
|
|
106
|
+
|
|
107
|
+
### Step 1: Understand Before Touching (Chesterton's Fence)
|
|
108
|
+
|
|
109
|
+
Before changing or removing anything, understand why it exists. This is Chesterton's Fence: if you see a fence across a road and don't understand why it's there, don't tear it down. First understand the reason, then decide if the reason still applies.
|
|
110
|
+
|
|
111
|
+
```
|
|
112
|
+
BEFORE SIMPLIFYING, ANSWER:
|
|
113
|
+
- What is this code's responsibility?
|
|
114
|
+
- What calls it? What does it call?
|
|
115
|
+
- What are the edge cases and error paths?
|
|
116
|
+
- Are there tests that define the expected behavior?
|
|
117
|
+
- Why might it have been written this way? (Performance? Platform constraint? Historical reason?)
|
|
118
|
+
- Check git blame: what was the original context for this code?
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
If you can't answer these, you're not ready to simplify. Read more context first.
|
|
122
|
+
|
|
123
|
+
### Step 2: Identify Simplification Opportunities
|
|
124
|
+
|
|
125
|
+
Scan for these patterns — each one is a concrete signal, not a vague smell:
|
|
126
|
+
|
|
127
|
+
**Structural complexity:**
|
|
128
|
+
|
|
129
|
+
| Pattern | Signal | Simplification |
|
|
130
|
+
|---------|--------|----------------|
|
|
131
|
+
| Deep nesting (3+ levels) | Hard to follow control flow | Extract conditions into guard clauses or helper functions |
|
|
132
|
+
| Long functions (50+ lines) | Multiple responsibilities | Split into focused functions with descriptive names |
|
|
133
|
+
| Nested ternaries | Requires mental stack to parse | Replace with if/else chains, switch, or lookup objects |
|
|
134
|
+
| Boolean parameter flags | `doThing(true, false, true)` | Replace with options objects or separate functions |
|
|
135
|
+
| Repeated conditionals | Same `if` check in multiple places | Extract to a well-named predicate function |
|
|
136
|
+
|
|
137
|
+
**Naming and readability:**
|
|
138
|
+
|
|
139
|
+
| Pattern | Signal | Simplification |
|
|
140
|
+
|---------|--------|----------------|
|
|
141
|
+
| Generic names | `data`, `result`, `temp`, `val`, `item` | Rename to describe the content: `userProfile`, `validationErrors` |
|
|
142
|
+
| Abbreviated names | `usr`, `cfg`, `btn`, `evt` | Use full words unless the abbreviation is universal (`id`, `url`, `api`) |
|
|
143
|
+
| Misleading names | Function named `get` that also mutates state | Rename to reflect actual behavior |
|
|
144
|
+
| Comments explaining "what" | `// increment counter` above `count++` | Delete the comment — the code is clear enough |
|
|
145
|
+
| Comments explaining "why" | `// Retry because the API is flaky under load` | Keep these — they carry intent the code can't express |
|
|
146
|
+
|
|
147
|
+
**Redundancy:**
|
|
148
|
+
|
|
149
|
+
| Pattern | Signal | Simplification |
|
|
150
|
+
|---------|--------|----------------|
|
|
151
|
+
| Duplicated logic | Same 5+ lines in multiple places | Extract to a shared function |
|
|
152
|
+
| Dead code | Unreachable branches, unused variables, commented-out blocks | Remove (after confirming it's truly dead) |
|
|
153
|
+
| Unnecessary abstractions | Wrapper that adds no value | Inline the wrapper, call the underlying function directly |
|
|
154
|
+
| Over-engineered patterns | Factory-for-a-factory, strategy-with-one-strategy | Replace with the simple direct approach |
|
|
155
|
+
| Redundant type assertions | Casting to a type that's already inferred | Remove the assertion |
|
|
156
|
+
|
|
157
|
+
### Step 3: Apply Changes Incrementally
|
|
158
|
+
|
|
159
|
+
Make one simplification at a time. Run tests after each change. **Submit refactoring changes separately from feature or bug fix changes.** A PR that refactors and adds a feature is two PRs — split them.
|
|
160
|
+
|
|
161
|
+
```
|
|
162
|
+
FOR EACH SIMPLIFICATION:
|
|
163
|
+
1. Make the change
|
|
164
|
+
2. Run the test suite
|
|
165
|
+
3. If tests pass → commit (or continue to next simplification)
|
|
166
|
+
4. If tests fail → revert and reconsider
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
Avoid batching multiple simplifications into a single untested change. If something breaks, you need to know which simplification caused it.
|
|
170
|
+
|
|
171
|
+
**The Rule of 500:** If a refactoring would touch more than 500 lines, invest in automation (codemods, sed scripts, AST transforms) rather than making the changes by hand. Manual edits at that scale are error-prone and exhausting to review.
|
|
172
|
+
|
|
173
|
+
### Step 4: Verify the Result
|
|
174
|
+
|
|
175
|
+
After all simplifications, step back and evaluate the whole:
|
|
176
|
+
|
|
177
|
+
```
|
|
178
|
+
COMPARE BEFORE AND AFTER:
|
|
179
|
+
- Is the simplified version genuinely easier to understand?
|
|
180
|
+
- Did you introduce any new patterns inconsistent with the codebase?
|
|
181
|
+
- Is the diff clean and reviewable?
|
|
182
|
+
- Would a teammate approve this change?
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
If the "simplified" version is harder to understand or review, revert. Not every simplification attempt succeeds.
|
|
186
|
+
|
|
187
|
+
## Language-Specific Guidance
|
|
188
|
+
|
|
189
|
+
### TypeScript / JavaScript
|
|
190
|
+
|
|
191
|
+
```typescript
|
|
192
|
+
// SIMPLIFY: Unnecessary async wrapper
|
|
193
|
+
// Before
|
|
194
|
+
async function getUser(id: string): Promise<User> {
|
|
195
|
+
return await userService.findById(id);
|
|
196
|
+
}
|
|
197
|
+
// After
|
|
198
|
+
function getUser(id: string): Promise<User> {
|
|
199
|
+
return userService.findById(id);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// SIMPLIFY: Verbose conditional assignment
|
|
203
|
+
// Before
|
|
204
|
+
let displayName: string;
|
|
205
|
+
if (user.nickname) {
|
|
206
|
+
displayName = user.nickname;
|
|
207
|
+
} else {
|
|
208
|
+
displayName = user.fullName;
|
|
209
|
+
}
|
|
210
|
+
// After
|
|
211
|
+
const displayName = user.nickname || user.fullName;
|
|
212
|
+
|
|
213
|
+
// SIMPLIFY: Manual array building
|
|
214
|
+
// Before
|
|
215
|
+
const activeUsers: User[] = [];
|
|
216
|
+
for (const user of users) {
|
|
217
|
+
if (user.isActive) {
|
|
218
|
+
activeUsers.push(user);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
// After
|
|
222
|
+
const activeUsers = users.filter((user) => user.isActive);
|
|
223
|
+
|
|
224
|
+
// SIMPLIFY: Redundant boolean return
|
|
225
|
+
// Before
|
|
226
|
+
function isValid(input: string): boolean {
|
|
227
|
+
if (input.length > 0 && input.length < 100) {
|
|
228
|
+
return true;
|
|
229
|
+
}
|
|
230
|
+
return false;
|
|
231
|
+
}
|
|
232
|
+
// After
|
|
233
|
+
function isValid(input: string): boolean {
|
|
234
|
+
return input.length > 0 && input.length < 100;
|
|
235
|
+
}
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
### Python
|
|
239
|
+
|
|
240
|
+
```python
|
|
241
|
+
# SIMPLIFY: Verbose dictionary building
|
|
242
|
+
# Before
|
|
243
|
+
result = {}
|
|
244
|
+
for item in items:
|
|
245
|
+
result[item.id] = item.name
|
|
246
|
+
# After
|
|
247
|
+
result = {item.id: item.name for item in items}
|
|
248
|
+
|
|
249
|
+
# SIMPLIFY: Nested conditionals with early return
|
|
250
|
+
# Before
|
|
251
|
+
def process(data):
|
|
252
|
+
if data is not None:
|
|
253
|
+
if data.is_valid():
|
|
254
|
+
if data.has_permission():
|
|
255
|
+
return do_work(data)
|
|
256
|
+
else:
|
|
257
|
+
raise PermissionError("No permission")
|
|
258
|
+
else:
|
|
259
|
+
raise ValueError("Invalid data")
|
|
260
|
+
else:
|
|
261
|
+
raise TypeError("Data is None")
|
|
262
|
+
# After
|
|
263
|
+
def process(data):
|
|
264
|
+
if data is None:
|
|
265
|
+
raise TypeError("Data is None")
|
|
266
|
+
if not data.is_valid():
|
|
267
|
+
raise ValueError("Invalid data")
|
|
268
|
+
if not data.has_permission():
|
|
269
|
+
raise PermissionError("No permission")
|
|
270
|
+
return do_work(data)
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
### React / JSX
|
|
274
|
+
|
|
275
|
+
```tsx
|
|
276
|
+
// SIMPLIFY: Verbose conditional rendering
|
|
277
|
+
// Before
|
|
278
|
+
function UserBadge({ user }: Props) {
|
|
279
|
+
if (user.isAdmin) {
|
|
280
|
+
return <Badge variant="admin">Admin</Badge>;
|
|
281
|
+
} else {
|
|
282
|
+
return <Badge variant="default">User</Badge>;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
// After
|
|
286
|
+
function UserBadge({ user }: Props) {
|
|
287
|
+
const variant = user.isAdmin ? 'admin' : 'default';
|
|
288
|
+
const label = user.isAdmin ? 'Admin' : 'User';
|
|
289
|
+
return <Badge variant={variant}>{label}</Badge>;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
// SIMPLIFY: Prop drilling through intermediate components
|
|
293
|
+
// Before — consider whether context or composition solves this better.
|
|
294
|
+
// This is a judgment call — flag it, don't auto-refactor.
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
## Common Rationalizations
|
|
298
|
+
|
|
299
|
+
| Rationalization | Reality |
|
|
300
|
+
|---|---|
|
|
301
|
+
| "It's working, no need to touch it" | Working code that's hard to read will be hard to fix when it breaks. Simplifying now saves time on every future change. |
|
|
302
|
+
| "Fewer lines is always simpler" | A 1-line nested ternary is not simpler than a 5-line if/else. Simplicity is about comprehension speed, not line count. |
|
|
303
|
+
| "I'll just quickly simplify this unrelated code too" | Unscoped simplification creates noisy diffs and risks regressions in code you didn't intend to change. Stay focused. |
|
|
304
|
+
| "The types make it self-documenting" | Types document structure, not intent. A well-named function explains *why* better than a type signature explains *what*. |
|
|
305
|
+
| "This abstraction might be useful later" | Don't preserve speculative abstractions. If it's not used now, it's complexity without value. Remove it and re-add when needed. |
|
|
306
|
+
| "The original author must have had a reason" | Maybe. Check git blame — apply Chesterton's Fence. But accumulated complexity often has no reason; it's just the residue of iteration under pressure. |
|
|
307
|
+
| "I'll refactor while adding this feature" | Separate refactoring from feature work. Mixed changes are harder to review, revert, and understand in history. |
|
|
308
|
+
|
|
309
|
+
## Red Flags
|
|
310
|
+
|
|
311
|
+
- Simplification that requires modifying tests to pass (you likely changed behavior)
|
|
312
|
+
- "Simplified" code that is longer and harder to follow than the original
|
|
313
|
+
- Renaming things to match your preferences rather than project conventions
|
|
314
|
+
- Removing error handling because "it makes the code cleaner"
|
|
315
|
+
- Simplifying code you don't fully understand
|
|
316
|
+
- Batching many simplifications into one large, hard-to-review commit
|
|
317
|
+
- Refactoring code outside the scope of the current task without being asked
|
|
318
|
+
|
|
319
|
+
## Verification
|
|
320
|
+
|
|
321
|
+
After completing a simplification pass:
|
|
322
|
+
|
|
323
|
+
- [ ] All existing tests pass without modification
|
|
324
|
+
- [ ] Build succeeds with no new warnings
|
|
325
|
+
- [ ] Linter/formatter passes (no style regressions)
|
|
326
|
+
- [ ] Each simplification is a reviewable, incremental change
|
|
327
|
+
- [ ] The diff is clean — no unrelated changes mixed in
|
|
328
|
+
- [ ] Simplified code follows project conventions (checked against CLAUDE.md or equivalent)
|
|
329
|
+
- [ ] No error handling was removed or weakened
|
|
330
|
+
- [ ] No dead code was left behind (unused imports, unreachable branches)
|
|
331
|
+
- [ ] A teammate or review agent would approve the change as a net improvement
|
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: constraint-driven-development
|
|
3
|
+
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.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Constraint-Driven Development
|
|
7
|
+
|
|
8
|
+
## Overview
|
|
9
|
+
|
|
10
|
+
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.
|
|
11
|
+
|
|
12
|
+
This skill produces something different: a written record of **this project's** bar, with numbers, that outlives the conversation and can be checked mechanically.
|
|
13
|
+
|
|
14
|
+
The reason matters. When you wrote the code, reading it told you whether it was any good. An agent writes more in an afternoon than you will read that week, so the judgement moves out of your head and into checks that run around the loop. Those checks need to exist, they need numbers you actually chose, and they need to fire close enough to the work that the agent fixes its own output.
|
|
15
|
+
|
|
16
|
+
Spec-driven development says what to build. Test-driven development proves it works. Constraint-driven development defines what "good enough to ship" means, before anyone argues about it in a pull request.
|
|
17
|
+
|
|
18
|
+
## When to Use
|
|
19
|
+
|
|
20
|
+
Apply this skill when:
|
|
21
|
+
|
|
22
|
+
- Starting a project or a significant feature and no quality bar is written down
|
|
23
|
+
- The user asks to "set up constraints", "add quality gates", "define our standards", or "stop the agent shipping junk"
|
|
24
|
+
- An agent is producing volume nobody is reading line by line
|
|
25
|
+
- CI has checks but nobody can say which ones block a merge and which ones are decoration
|
|
26
|
+
- Coverage, performance, or accessibility numbers get argued about per-PR instead of decided once
|
|
27
|
+
- You're about to run `/build auto` or any autonomous loop, and the only thing standing between it and main is a test suite the agent also wrote
|
|
28
|
+
|
|
29
|
+
**When NOT to use:**
|
|
30
|
+
|
|
31
|
+
- The project already has a `CONSTRAINTS.md` and the user isn't changing it — read it and follow it instead
|
|
32
|
+
- One-off scripts, spikes, throwaway prototypes
|
|
33
|
+
- The user wants a code review right now (`code-review-and-quality`) or a CI pipeline built (`ci-cd-and-automation`)
|
|
34
|
+
- Pre-product-market-fit code with a two-week expected lifetime — the floor below is still worth it, the rest isn't
|
|
35
|
+
|
|
36
|
+
## Loading Constraints
|
|
37
|
+
|
|
38
|
+
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.
|
|
39
|
+
|
|
40
|
+
## The Process
|
|
41
|
+
|
|
42
|
+
### Step 1: Detect before you ask
|
|
43
|
+
|
|
44
|
+
Never ask what you can read. Before the first question, gather:
|
|
45
|
+
|
|
46
|
+
| What | Where to look |
|
|
47
|
+
|------|---------------|
|
|
48
|
+
| Language and stack | `package.json`, `pyproject.toml`, `go.mod`, `Cargo.toml` |
|
|
49
|
+
| Test runner | dev dependencies, `test` script, existing test files |
|
|
50
|
+
| Existing linters | `eslint.config.*`, `biome.json`, `.ruff.toml` |
|
|
51
|
+
| Coverage today | `coverage/` output, or run the suite once |
|
|
52
|
+
| CI | `.github/workflows/`, `.gitlab-ci.yml` |
|
|
53
|
+
| Agent harness | `.claude/`, `.codex/`, `AGENTS.md` |
|
|
54
|
+
|
|
55
|
+
Report what you found in two lines, then ask only what's left.
|
|
56
|
+
|
|
57
|
+
### Step 2: Four questions, each with a default
|
|
58
|
+
|
|
59
|
+
Follow the one-question-at-a-time discipline from `interview-me`, with one change: every question here has a default, so "I don't know" is a complete answer that still produces a working config.
|
|
60
|
+
|
|
61
|
+
```
|
|
62
|
+
Q1: Beyond the floor, which of these do you want enforced?
|
|
63
|
+
(a) Test coverage on new code
|
|
64
|
+
(b) Security scanning
|
|
65
|
+
(c) Performance budgets
|
|
66
|
+
(d) Accessibility
|
|
67
|
+
(e) Architecture boundaries
|
|
68
|
+
GUESS: (a) and (b) — you have a test runner already and you're handling user input.
|
|
69
|
+
DEFAULT if unsure: (a) and (b).
|
|
70
|
+
Say what each pick costs: (c) and (d) need a running URL, (e) needs a rules file written.
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
```
|
|
74
|
+
Q2: When a check fails while the agent is mid-task, should it block or warn?
|
|
75
|
+
GUESS: Block. You're running agents unattended and a warning nobody reads is a warning.
|
|
76
|
+
DEFAULT if unsure: Block on the floor, warn on everything else for the first two weeks.
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
```
|
|
80
|
+
Q3: Do you have target numbers in mind, or should I measure where you are today and hold that line?
|
|
81
|
+
GUESS: Measure. Most teams don't have a number, and an invented one gets ignored.
|
|
82
|
+
DEFAULT if unsure: Measure and hold. See "Ratchets" below.
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
```
|
|
86
|
+
Q4: What's the slowest check you'll tolerate before the agent hands work back?
|
|
87
|
+
GUESS: About 90 seconds. Longer and you'll stop running it.
|
|
88
|
+
DEFAULT if unsure: 90 seconds at task end, unlimited in CI.
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Stop at four. A twelve-question intake produces a config nobody understands and a user who regrets starting.
|
|
92
|
+
|
|
93
|
+
### Step 3: Write CONSTRAINTS.md
|
|
94
|
+
|
|
95
|
+
One file at the repo root. Any agent on any harness can read it, and a change to it shows up in review where it belongs.
|
|
96
|
+
|
|
97
|
+
```markdown
|
|
98
|
+
# Constraints
|
|
99
|
+
|
|
100
|
+
Last reviewed: 2026-08-08 by @addy
|
|
101
|
+
|
|
102
|
+
## Floor (always enforced, no setup required)
|
|
103
|
+
|
|
104
|
+
- No new suppression comments: `@ts-ignore`, `eslint-disable`, `# noqa`, `# type: ignore`
|
|
105
|
+
- No unimplemented stubs: `throw new Error("Not implemented")`, empty `catch {}`
|
|
106
|
+
- No skipped or deleted tests without a reason in the commit message
|
|
107
|
+
- No secrets in source
|
|
108
|
+
- This file does not get weakened to make a change pass
|
|
109
|
+
|
|
110
|
+
## Enforced with numbers
|
|
111
|
+
|
|
112
|
+
| Dimension | Rule | Checked by | Runs at |
|
|
113
|
+
|-----------|------|-----------|---------|
|
|
114
|
+
| Types | Zero type errors | `tsc --noEmit` | every edit |
|
|
115
|
+
| Lint | Zero errors from our config | `biome check` | every edit |
|
|
116
|
+
| Secrets | No secrets in source | `gitleaks detect --redact` | every edit |
|
|
117
|
+
| Coverage | Changed lines ≥ 80% covered | `vitest run --coverage` + git diff | task end, CI |
|
|
118
|
+
| Security: code | No high findings | `semgrep scan --config p/default` | CI |
|
|
119
|
+
| Security: deps | Nothing at high or above | `osv-scanner scan source -r .` | CI |
|
|
120
|
+
| Accessibility | Zero critical or serious | `axe $PREVIEW_URL --tags wcag2a,wcag2aa,wcag21aa` | preview deploy |
|
|
121
|
+
| Performance | LCP ≤ 2500ms, CLS ≤ 0.1 | `lighthouse $PREVIEW_URL --output=json` | preview deploy |
|
|
122
|
+
|
|
123
|
+
Every row names the command that produces the verdict. A dimension with a
|
|
124
|
+
number and no command in this column is an aspiration, not a constraint.
|
|
125
|
+
|
|
126
|
+
## Measured, not yet enforced
|
|
127
|
+
|
|
128
|
+
| Metric | Today | Direction |
|
|
129
|
+
|--------|-------|-----------|
|
|
130
|
+
| Project coverage | 62.4% | must not fall |
|
|
131
|
+
| Bundle size (main) | 184 kB | must not grow |
|
|
132
|
+
|
|
133
|
+
## Exceptions
|
|
134
|
+
|
|
135
|
+
| ID | Rule | Path | Reason | Owner | Expires |
|
|
136
|
+
|----|------|------|--------|-------|---------|
|
|
137
|
+
| W1 | `no-explicit-any` | `src/legacy/**` | Rewrite tracked in ENG-441 | @addy | 2026-11-01 |
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
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.`
|
|
141
|
+
|
|
142
|
+
### Step 4: Install what each dimension needs
|
|
143
|
+
|
|
144
|
+
Picking a dimension means installing something. Don't leave the user with a number and no mechanism, and don't invent your own checker when a de facto one exists — these tools are listed because their rule formats and thresholds are what everything else in the ecosystem targets, so the team's existing config keeps working.
|
|
145
|
+
|
|
146
|
+
| Dimension | Tool | Install | Run | Gate on |
|
|
147
|
+
|-----------|------|---------|-----|---------|
|
|
148
|
+
| Types (TS) | tsc | already there | `tsc --noEmit` | any error |
|
|
149
|
+
| Types (Python) | mypy | `pip install mypy` | `mypy .` | any error |
|
|
150
|
+
| Lint | your existing config | already there | `eslint .` / `biome check` / `ruff check` | any error |
|
|
151
|
+
| Coverage (JS) | your test runner | already there | `vitest run --coverage` (or `jest --coverage`) | coverage of changed lines |
|
|
152
|
+
| Coverage (Python) | pytest-cov | `pip install pytest-cov` | `pytest --cov --cov-report=lcov` | same |
|
|
153
|
+
| Security: code | Semgrep | `pipx install semgrep` | `semgrep scan --config p/default --config p/owasp-top-ten` | any high finding |
|
|
154
|
+
| Security: secrets | gitleaks | `brew install gitleaks` | `gitleaks detect --redact --no-banner` | any finding |
|
|
155
|
+
| Security: dependencies | osv-scanner | `brew install osv-scanner` | `osv-scanner scan source -r .` | high or above |
|
|
156
|
+
| Performance: page | Lighthouse | `npm i -D lighthouse` | `lighthouse $URL --output=json --quiet` | LCP, CLS, performance score |
|
|
157
|
+
| Performance: bundle | size-limit | `npm i -D size-limit` | `size-limit --json` | per-entry byte budget |
|
|
158
|
+
| Accessibility | axe-core | `npm i -D @axe-core/cli` | `axe $URL --tags wcag2a,wcag2aa,wcag21aa` | zero critical or serious |
|
|
159
|
+
| Architecture | dependency-cruiser | `npm i -D dependency-cruiser` | `depcruise --validate src` | any violation |
|
|
160
|
+
| Assertion quality | Stryker | `npm i -D @stryker-mutator/core` | `stryker run --mutate <changed files>` | mutation score |
|
|
161
|
+
|
|
162
|
+
Five things that will bite you if you skip them:
|
|
163
|
+
|
|
164
|
+
1. **`--redact` on gitleaks is not optional.** Without it the matched secret lands in the agent's transcript, which is how a leaked key ends up in a log, a summary, or a commit message. Report the rule and the location, never the value.
|
|
165
|
+
2. **Lighthouse and axe need a URL.** They only work against a running app, so they belong in the runtime stage against a preview deploy or a local server you start first. If the project has no URL to hit — a CLI, a library, a desktop app — say so and drop the dimension rather than inventing a check that can't run.
|
|
166
|
+
3. **Scope the expensive ones to the diff.** `stryker run --mutate` on the whole repo takes hours and gets turned off; on the files a change touched it takes under a minute. Same for Semgrep, which takes a path list.
|
|
167
|
+
4. **Coverage needs no second test run.** Read the lcov your suite already writes and intersect it with `git diff`. Running the suite twice to get a number is the fastest way to make people hate this.
|
|
168
|
+
5. **Semgrep's registry rules are free to run; check the licence before redistributing them.** `opengrep` is a drop-in fork with the same rule format and JSON output if that matters to your legal team.
|
|
169
|
+
|
|
170
|
+
Add each one to the project's own script so it's reproducible without an agent:
|
|
171
|
+
|
|
172
|
+
```json
|
|
173
|
+
{
|
|
174
|
+
"scripts": {
|
|
175
|
+
"check:fast": "tsc --noEmit && eslint . && gitleaks detect --redact --no-banner",
|
|
176
|
+
"check:task": "npm run check:fast && vitest run --coverage",
|
|
177
|
+
"check:full": "npm run check:task && semgrep scan --config p/default && osv-scanner scan source -r ."
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
That mapping matters more than the tools. `check:fast` is what runs after an edit, `check:task` when the agent thinks it's done, `check:full` in CI.
|
|
183
|
+
|
|
184
|
+
The commands now live in two places — the `Checked by` column in `CONSTRAINTS.md` and these scripts. `CONSTRAINTS.md` is the canonical source: it carries the reason alongside each command and it shows up in review. The scripts are convenience wrappers that must mirror it, not a second source of truth; if they drift, the file wins.
|
|
185
|
+
|
|
186
|
+
### Step 5: Wire it to the lifecycle
|
|
187
|
+
|
|
188
|
+
The single biggest mistake is running everything everywhere. A check that stalls the agent gets switched off, and a gate people switched off is worse than no gate, because the bar still looks like it exists.
|
|
189
|
+
|
|
190
|
+
| Phase | Command | What runs | Budget |
|
|
191
|
+
|-------|---------|-----------|--------|
|
|
192
|
+
| BUILD | `/build` | Types, lint, secrets, the floor | under 5s, changed file only |
|
|
193
|
+
| VERIFY | `/test` | Related tests, coverage on changed lines | under 90s |
|
|
194
|
+
| REVIEW | `/review` | Everything, plus the guards below | minutes |
|
|
195
|
+
| SHIP | `/ship` | Direction checks, no regressions | CI |
|
|
196
|
+
|
|
197
|
+
Two rules that keep this tolerable:
|
|
198
|
+
|
|
199
|
+
1. **Scope to the diff.** Check the lines this change touched, not the whole repo. Coverage of changed lines is a number the agent can move; project coverage is one it inherited.
|
|
200
|
+
2. **Cost decides placement.** Anything over a few seconds moves out of the edit loop. Mutation testing on a whole repo takes hours; on the files a change touched it takes under a minute, which is the difference between a check people run and one they don't.
|
|
201
|
+
|
|
202
|
+
### Step 6: Guard the bar itself
|
|
203
|
+
|
|
204
|
+
Someone will point out that if the agent writes the code and the checks, the checks prove nothing. Half right, and worth engineering around.
|
|
205
|
+
|
|
206
|
+
Agents don't craft clever loopholes. They hit a red check and take the cheapest road to green. Watch for these five moves in the diff, at review time:
|
|
207
|
+
|
|
208
|
+
1. **The threshold moved.** A budget lowered, a severity dropped, a check removed from the fast stage. Compare `CONSTRAINTS.md` against its state at the branch point.
|
|
209
|
+
2. **A test got easier.** `.skip` added, a test file deleted, assertions pulled out of tests that stayed.
|
|
210
|
+
3. **A checker got silenced.** New `@ts-ignore` or `eslint-disable`. Four suppressions deserve special attention because they switch off a check you're relying on: `istanbul ignore` drops code from coverage instead of testing it, `Stryker disable` hides a surviving mutant, `nosemgrep` and `gitleaks:allow` do it for security findings.
|
|
211
|
+
4. **Work is unfinished.** A stub that throws, an empty `catch` turning a failure into silence, a `TODO` standing where the implementation should be.
|
|
212
|
+
5. **An exception appeared.** A new row in the Exceptions table nobody discussed.
|
|
213
|
+
|
|
214
|
+
None of this needs tooling beyond `git diff`. Tightening the bar should be silent; loosening it should be loud.
|
|
215
|
+
|
|
216
|
+
Unlike the numbered dimensions, the floor has no de facto tool of its own, so an agent asked to enforce it tends to write a checker from scratch, and two agents write two different ones. A reference implementation of these five checks ships with this skill in [references/floor-guard.md](references/floor-guard.md) (diff-scoped, exit `0`/`1`/`2`, patterns adaptable per ecosystem). Adapt that rather than reinventing it, for the same reason every dimension names a de facto tool: so the mechanism is the same across runs and stacks.
|
|
217
|
+
|
|
218
|
+
**Not all checks are equally circular.** Rank them by one question: can the agent make this pass by writing code that doesn't work?
|
|
219
|
+
|
|
220
|
+
- **External** — axe-core encodes WCAG, `osv-scanner` reads a vulnerability database, Lighthouse measures a real browser. The agent can't argue with these.
|
|
221
|
+
- **Project** — your lint rules, your layer boundaries. A human owns the file.
|
|
222
|
+
- **Suite** — your own tests. Most useful, and the only genuinely circular one.
|
|
223
|
+
|
|
224
|
+
A bar made entirely of the third kind is worth less than one with an outside opinion in it. Check that at least one external constraint is present.
|
|
225
|
+
|
|
226
|
+
### Step 7: Ratchets, when you don't have a number
|
|
227
|
+
|
|
228
|
+
Set 80% coverage on a codebase at 62% and you get a red build forever, then a team that learns to ignore red builds.
|
|
229
|
+
|
|
230
|
+
The alternative asks for no decision: record where you are, then refuse to get worse. Put it in the "Measured, not yet enforced" table with today's number and a direction. Every check compares against the recorded value, not an aspiration. When a number improves, update it; when it drops, that's the finding.
|
|
231
|
+
|
|
232
|
+
This also answers a fair objection to training. Models are rewarded for passing tests, which you can evaluate in seconds. Architectural rot shows up over months and never reaches the weights. A ratchet is the missing penalty, written down where the build can see it.
|
|
233
|
+
|
|
234
|
+
## Sane Defaults
|
|
235
|
+
|
|
236
|
+
When the user has no opinion, use these. They're chosen to be met by most codebases on day one.
|
|
237
|
+
|
|
238
|
+
| Constraint | Default | Why this number |
|
|
239
|
+
|------------|---------|-----------------|
|
|
240
|
+
| Coverage of changed lines | ≥ 80% | High enough to force a test, low enough to allow a config line |
|
|
241
|
+
| Project coverage | today's value, must not fall | No argument needed to adopt |
|
|
242
|
+
| Mutation score (if used) | ≥ 60% to start | Typical for a suite never mutated before; 80% is mature |
|
|
243
|
+
| Dependency vulnerabilities | nothing at high or above | Below that is mostly noise |
|
|
244
|
+
| LCP | ≤ 2500 ms | Core Web Vitals "good" threshold |
|
|
245
|
+
| CLS | ≤ 0.1 | Same |
|
|
246
|
+
| Accessibility | zero critical or serious axe violations | Moderate and minor are often debatable |
|
|
247
|
+
| Exception lifetime | 90 days | Long enough to plan the fix, short enough to remember |
|
|
248
|
+
| Ratchet tolerance | 0.5% | Absorbs drift when an unrelated file moves the number |
|
|
249
|
+
|
|
250
|
+
State the number and the reason together. A threshold without a rationale gets deleted by the next person who hits it.
|
|
251
|
+
|
|
252
|
+
## Escalation Path
|
|
253
|
+
|
|
254
|
+
Constraints work at three levels of teeth. Start at the first.
|
|
255
|
+
|
|
256
|
+
1. **Written only.** `CONSTRAINTS.md` exists and agents read it. Costs nothing, catches the honest mistakes, relies on the agent complying.
|
|
257
|
+
2. **Scripted.** An `npm run check` (or `make check`) that runs the fast checks, wired into your agent's post-edit hook and your CI. Deterministic, no new dependency.
|
|
258
|
+
3. **Tool-backed.** A dedicated runner that handles diff scoping, budgets, ratchets, and the guard checks. Use when the config outgrows a shell script. The floor-guard reference in [references/floor-guard.md](references/floor-guard.md) is the starting point for the guard-checks half of this.
|
|
259
|
+
|
|
260
|
+
Most projects should stop at 2. Move to 3 when you're maintaining more than about thirty lines of check-running shell.
|
|
261
|
+
|
|
262
|
+
**A first run can be floor-only.** The floor guard is diff-only and needs no installs, so you can enforce the floor on day one and add numbered dimensions as you install each tool, rather than standing up every checker before the first commit is protected. Security tools that install machine-wide (gitleaks, osv-scanner) can also run CI-only if you'd rather keep laptops clean; declare where each dimension runs in the `Runs at` column.
|
|
263
|
+
|
|
264
|
+
## Common Rationalizations
|
|
265
|
+
|
|
266
|
+
| Excuse | Reality |
|
|
267
|
+
|--------|---------|
|
|
268
|
+
| "We'll add constraints once the code settles" | Code settles around whatever was allowed while it was moving |
|
|
269
|
+
| "The tests are the constraints" | Tests you wrote prove you agree with yourself; they say nothing about coverage of new code, dependency risk, or bundle growth |
|
|
270
|
+
| "We can't hit 80% coverage" | Then don't set 80%. Set today's number and hold it |
|
|
271
|
+
| "This will slow the agent down" | Only if you put slow checks in the fast loop. That's a placement error, not an argument against constraints |
|
|
272
|
+
| "I'll remember what our standards are" | The agent won't, and it's writing most of the code |
|
|
273
|
+
| "Constraints will block us shipping" | An exception with an owner and a date unblocks you. Deleting the constraint unblocks everyone forever |
|
|
274
|
+
|
|
275
|
+
## Red Flags
|
|
276
|
+
|
|
277
|
+
Stop and reconsider if you notice:
|
|
278
|
+
|
|
279
|
+
- The interview ran past four questions, or produced a config the user can't explain
|
|
280
|
+
- A budget was set that the codebase fails today, with no plan to reach it
|
|
281
|
+
- A dimension was written into CONSTRAINTS.md with a number but no tool behind it
|
|
282
|
+
- A checker was hand-rolled when a de facto one exists, so the team's existing config is ignored
|
|
283
|
+
- Every constraint is checked by the project's own test suite, with no external opinion
|
|
284
|
+
- `CONSTRAINTS.md` changed in the same commit as the feature that was failing
|
|
285
|
+
- An exception has no owner, or an expiry more than a year out
|
|
286
|
+
- The agent proposed relaxing a threshold instead of fixing the code
|
|
287
|
+
- Slow checks landed in the edit loop and someone has started passing `--no-verify`
|
|
288
|
+
- Nobody has opened `CONSTRAINTS.md` since it was written
|
|
289
|
+
|
|
290
|
+
## Verification
|
|
291
|
+
|
|
292
|
+
The skill was applied correctly when:
|
|
293
|
+
|
|
294
|
+
- [ ] `CONSTRAINTS.md` exists, and every number in it has a stated reason
|
|
295
|
+
- [ ] The floor is enforced and passes on the current codebase without changes
|
|
296
|
+
- [ ] Every dimension the user picked has a tool installed and a command that runs today
|
|
297
|
+
- [ ] Each constraint says where it runs, and the fast stage stays under a few seconds
|
|
298
|
+
- [ ] At least one constraint is external (not judged by this project's own tests)
|
|
299
|
+
- [ ] Measured-only metrics record today's value and a direction
|
|
300
|
+
- [ ] Exceptions have an owner and an expiry date
|
|
301
|
+
- [ ] `AGENTS.md` or `CLAUDE.md` points at the file
|
|
302
|
+
- [ ] A trial run on the current branch produces no failures the user disagrees with
|
|
303
|
+
|
|
304
|
+
## See Also
|
|
305
|
+
|
|
306
|
+
- `interview-me` — the one-question-at-a-time discipline this skill's intake borrows
|
|
307
|
+
- `code-review-and-quality` — how to review; this skill decides what the review enforces
|
|
308
|
+
- `ci-cd-and-automation` — building the pipeline these constraints run in
|
|
309
|
+
- `test-driven-development` — the suite that coverage and mutation constraints measure
|
|
310
|
+
- `security-and-hardening` — what the security dimension should contain
|
|
311
|
+
- `performance-optimization` — where the performance numbers come from
|