Detect design drift

From Intense-Visions/harness-engineering · View interactive version

Detect design drift is an AI agent skill from the GitHub repository Intense-Visions/harness-engineering. > Detect design-system drift — hardcoded values where tokens exist, and raw HTML primitives where registered components exist. The rule-based floor of design-pipeline (detect half). Reports findings;

How to use this skill

Skill file

Detect Design Drift

Detect design-system drift — hardcoded values where tokens exist, and raw HTML primitives where registered components exist. The rule-based floor of design-pipeline (detect half). Reports findings; never modifies source. Pairs with a separate align-design-system fixer skill (deferred to a sibling sub-project).

When to Use

Capability Roles

<!-- Capability seam: this skill participates in a real extension point whose three roles are named and concrete. A seam with only one role filled is accidental single-implementation lock-in. See harness-skill-authoring Phase 1C. -->

Process

Phase 1: SCAN — Load resolvers + walk files

  1. Read project configuration. Check harness.config.json for:
  1. Load resolvers (soft-dependency — silent skip when absent):
  1. Collect candidate files. Walk the project root (or honor an explicit files arg from the caller). Skip node_modules, dist, build, coverage, and any dotfile directory. Honor only these extensions: .ts, .tsx, .js, .jsx, .css, .scss.

Phase 2: APPLY RULES — Two rule families

  1. Token bypass rules (DRIFT-T\*) — regex-based detection. For each file when tokens were loaded:
  1. Primitive adoption rules (DRIFT-P\*) — TS Compiler API JSX parsing. For each .jsx/.tsx file when the registry was loaded:

Phase 3: REPORT — Severity, aggregate, persist

  1. Severity from design.strictness:
  1. Aggregate the run summary. bySeverity, byCode, totalFiles, durationMs. Also report catalog.rulesApplied (which rule families fired) and meta.{tokensLoaded, registryLoaded, mode} so callers can see what was active.
  1. Persist findings to the graph (when composed by check-design). The check-design orchestrator passes drift findings to DesignConstraintAdapter.recordFindings() alongside anatomy and craft findings. Each finding becomes an idempotent VIOLATES_design edge keyed by (file, code, line) — re-runs do not double-write.

Harness Integration

Success Criteria

See docs/changes/design-pipeline/detect-design-drift/proposal.md for the full 34 success criteria. Highlights:

Rationalizations to Reject

These are common rationalizations that sound reasonable but lead to incorrect results. When you catch yourself thinking any of these, stop and follow the documented process instead.

| Rationalization | Why It Is Wrong |

| ----------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |

| "I found the hardcoded #ff0000 and the token swap is obvious, so I'll just replace it in the source." | This skill detects only and NEVER modifies source. Findings carry codemod-todo fix hints; applying them is the separate align-design-system fixer's job. Emit the DRIFT-T001 finding and stop. |

| "tokens.json is absent, but I know the brand palette, so I'll flag hardcoded colors anyway." | No findings without resolved inputs. When tokens.json doesn't load, all T\* rules silently skip — a missing resolver means the project hasn't opted in, not that drift exists. Speculative findings are false positives. |

| "The project registered a component for <select>, so I'll add a primitive-adoption finding for raw <select>." | Only the four registered tags are in scope for v1 — <button>, <input>, <a>, <textarea>. Other tags are out of scope even if a component exists; subsumption ships in v1.x. |

| "harness.config.json doesn't set strictness, so I'll treat every finding as error to be safe." | Strictness is read from config, not assumed — default to standard, not strict. Under standard only DRIFT-T001/T002/P001 are errors; forcing everything to error misrepresents severity and can wrongly block CI. |

| "Graph persistence threw, so I'll abort the run." | The graph is a consumer, not a gate. If recordFindings() fails, skip graph integration for that run — the findings still appear in the report. Never fail the verifier on a persistence error. |

Examples

Example: Hardcoded brand color outside the palette

Input: src/Card.tsx contains const styles = { color: "#ff0000" };, and design-system/tokens.json defines color.brand.primary as #0066cc (but no #ff0000).

Output:

DRIFT-T001 [error] src/Card.tsx:14 — Hardcoded color "#ff0000" is not in the design token palette
  Fix: Replace "#ff0000" with a token reference (e.g. var(--color-...) or a token-system lookup).
       If the color is intentionally one-off, add it to tokens.json first.

Severity is error under standard because brand-color drift is high-impact.

Example: Raw `<button>` where Button is registered

Input: src/SaveButton.tsx contains <button onClick={...}>Save</button>, and design-system/DESIGN.md ## Component Registry lists Button mapped to packages/ui/src/Button.tsx.

Output:

DRIFT-P001 [error] src/SaveButton.tsx:8 — Raw <button> element where the registered component "Button" should be used
  Fix: Import Button from your component library and replace <button> with <Button>.
       If this raw primitive is intentional (e.g. inside the Button component's own implementation),
       add a JSDoc `@allow-raw-primitive` annotation on the file.

Example: Reference to a deprecated token

Input: src/legacy.css contains .x { color: var(--color-brand-500); }, and tokens.json flags color.brand.500 as $deprecated: true with $description: "Use color.brand.primary instead".

Output:

DRIFT-T004 [warn] src/legacy.css:3 — Token "color.brand.500" is deprecated and should be migrated
  Fix: Migrate references to "color.brand.500" to the replacement token noted in tokens.json $description,
       or remove the deprecation if the token is still load-bearing.

Gates

Escalation

Status

v1 — in implementation. See:

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.