Align design system

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

Align design system is an AI agent skill from the GitHub repository Intense-Visions/harness-engineering. > Apply codemods for safe DRIFT-T001/T002/T003 token-bypass findings (replace hex / font-family / px-spacing literals with token references) and emit precise suggestions for DRIFT-T004 (deprecated tok

How to use this skill

Skill file

Align Design System

Apply codemods for safe DRIFT-T001/T002/T003 token-bypass findings (replace hex / font-family / px-spacing literals with token references) and emit precise suggestions for DRIFT-T004 (deprecated tokens) and all DRIFT-P\* (primitive adoption). The FIX half of design-pipeline drift-remediation sub-project, paired with detect-design-drift.

When to Use

Process

Phase 1: GATHER — Load drift findings

  1. Read project configuration. Check harness.config.json for:
  1. In standalone mode (default): invoke detect-design-drift internally with the same project root + strictness; receive the full DriftFinding[].
  1. In pipeline mode: read .harness/handoff.json and pull pipeline.driftFindings (pre-classified by the orchestrator). Honor pipeline.fixBatch if present to limit application to a specific subset of findings (the orchestrator may apply fixes in batches across iterations).

Phase 2: CLASSIFY — Pre-flight safe-codemod vs suggestion

For each finding, the pre-flight classifier inspects file context and chooses:

Token import discovery recognizes three forms:

Phase 3: APPLY — Codemod or emit suggestion

For each finding classified as safe-codemod:

  1. Read the source file (cached per-run to avoid re-reads when multiple findings hit the same file).
  2. Locate the exact match position from the finding's line + evidence.snippet.
  3. Compute the replacement using file-extension-aware syntax:
  1. Replace in-place. Emit FixOutcome.applied with a structured diff (file / line / before / after).
  2. If --dry-run: compute the diff but DO NOT write to disk.
  3. If the file changed between detect-time and apply-time: skip with kind: 'skipped-unsafe', reason: 'file changed since finding'.

For each finding classified as suggestion: emit a human-readable description plus a preview of the suggested change. No file mutation.

Phase 4: REPORT — Aggregate + (pipeline-mode) handoff writeback

  1. Aggregate FixOutcome[] into a summary: counts by kind (applied / suggestion / skipped / failed) plus files modified and duration.
  2. Build a catalog of finding codes that produced codemods and codes that produced suggestions.
  3. In pipeline mode: write pipeline.fixesApplied: FixOutcome[] back to .harness/handoff.json so the orchestrator can re-verify only the affected findings on the next loop iteration.

Harness Integration

Success Criteria

See docs/changes/design-pipeline/align-design-system/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 |

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

| "The token import is missing, but I can just add the import line and then apply the codemod." | Adding an import is its own ambiguity surface — named vs default vs barrel vs relative alias. The classifier deliberately downgrades to a suggestion when no import is present; synthesizing one turns a safe replacement into an unverified edit. |

| "This literal is 13px and the nearest spacing token is 12px — close enough to snap it." | Non-exact px matches are a design decision, not a mechanical fix. T003 is safe-codemod only when the px matches a spacing token's $value EXACTLY. Rounding invents intent the tool has no authority to invent. |

| "This raw <button> obviously maps to the registered <Button> — I'll translate the props and apply it." | Prop translation across <button> ⇄ <Button> is genuinely ambiguous (event handlers, ref forwarding, class merging). v1 ALWAYS emits a suggestion for DRIFT-P\*; there is no codemod path, and auto-applying one produces broken markup. |

| "Two tokens share this hex value, but the brand one is clearly intended — I'll pick it and apply." | When multiple tokens match a value the classifier downgrades to a suggestion by design. Choosing "the obvious one" is exactly the judgment call the pre-flight gate refuses to make; the resolution belongs in DESIGN.md or the source, not a guess. |

| "The file changed since detect ran, but the finding's line still looks right — I'll apply anyway." | Applying against content that moved risks mutating the wrong span. The contract is to skip with skipped-unsafe / reason: file changed since finding; re-run detect to get fresh line positions instead of trusting a stale offset. |

Examples

Example: Apply a T001 codemod (hex → token reference)

Input:

design-system/tokens.json has:

{ "color": { "brand": { "primary": { "$type": "color", "$value": "#0066cc" } } } }

src/Card.tsx has:

import { tokens } from '@/design-system/tokens';
const styles = { color: '#0066cc' }; // raw literal where token exists

Output:

src/Card.tsx
  ✓ DRIFT-T001:2 — Hex color "#0066cc" should use a token reference instead of a raw literal
     before: const styles = { color: "#0066cc" };
     after:  const styles = { color: tokens.color.brand.primary };

Summary: 1 applied, 0 suggestions, 0 skipped, 0 failed (1 files modified, 5ms)

Example: Downgrade to suggestion (no token import)

Same finding as above, but src/Card.tsx does NOT import tokens. align emits a suggestion instead:

src/Card.tsx
  ? DRIFT-T001:2 — Hex color "#0066cc" should use a token reference instead of a raw literal

Summary: 0 applied, 1 suggestions, 0 skipped, 0 failed (0 files modified, 3ms)

(Run with --verbose to see the suggestion text and the classifier's reason for downgrading.)

Example: Suggestion-only for DRIFT-P001

Input:

design-system/DESIGN.md registers Button in ## Component Registry. src/SaveButton.tsx has:

export const S = () => <button onClick={() => save()}>Save</button>;

Output:

src/SaveButton.tsx
  ? DRIFT-P001:1 — Raw <button> element where the registered component "Button" should be used

(use --verbose to see prop-translation suggestion)

v1 never auto-applies primitive adoption — prop translation across <button> ⇄ <Button> is the kind of judgment-call that benefits from a human or LLM review.

Example: Revert the last batch

After a write run, the applied diffs (plus a SHA-256 of each post-apply file) are persisted to .harness/align/last-batch.json. Running harness align-design-system --revert reads that batch and inverse-applies each diff:

src/Card.tsx
  ✓ DRIFT-T001:2 — Hex color "#0066cc" should use a token reference instead of a raw literal
     before: const styles = { color: tokens.color.brand.primary };
     after:  const styles = { color: "#0066cc" };

Summary: 1 reverted, 0 suggestions, 0 skipped, 0 failed (1 files modified, 4ms)

If the file has been edited externally between apply and revert (the SHA-256 doesn't match), every entry for that file is skipped with skipped-unsafe / reason: file changed externally since apply. A second revert on the same batch is a no-op for the same reason — the file's post-revert content no longer matches the recorded post-apply text.

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.