Apply design system

From lightspeedwp/.github · View interactive version

Apply design system is an AI agent skill from the GitHub repository lightspeedwp/.github. Review an existing design and connect it to design system components.

How to use this skill

Skill file

Connect A Design To A Design System

Use this skill for an existing Figma design that should reuse a published design system instead of detached layers, local wrappers, or one-off components.

This skill supports two entry modes:

Load these capabilities first:

Do not use this skill as the default follow-up to a single audit-design-system finding. For one targeted issue, use fix-design-system-finding so the write scope stays narrow.

Core Rule

Do not treat a section as "connected" just because it contains a few design-system buttons or icons.

This skill is for multi-section reconciliation. If the task can be satisfied by fixing one specific reviewed node, the narrower finding-fix skill is the better choice.

Classify each section into exactly one bucket:

Required Workflow

1. Determine Scope First

Before gathering replacement candidates, decide whether the screen needs an initial audit.

If scope is not already identified:

  1. Run audit-design-system or perform an equivalent internal audit pass.
  2. Collapse the review output into section-sized work packages instead of treating every micro-finding as a separate rewrite task.
  3. If the review produces only one narrow finding, switch to fix-design-system-finding instead of continuing here.

If scope is already identified, continue directly.

Do not skip component discovery just because a review already exists. Review identifies drift; this skill still has to choose the actual replacement primitives and variants.

2. Capture the Current State

Before writing:

  1. Get the target frame metadata with get_metadata.
  2. Get a screenshot with get_screenshot.
  3. If you need get_design_context and Figma asks the Code Connect question, ask the user exactly as instructed by the tool before proceeding.

For this skill, prefer get_metadata plus use_figma for structure discovery. get_design_context is optional unless it unlocks missing context.

3. Back Up the Target Screen

Before destructive edits, duplicate the frame or page and place the backup to the right.

Name it clearly, for example:

Do this in its own use_figma call and return the created node ID.

4. Inventory the Existing Screen

Inspect the target frame before searching the library.

Use use_figma to gather:

Prefer exact keys over names. Names are only hints.

Useful read-only inventory pattern:

(async () => {
  try {
    await figma.setCurrentPageAsync(figma.root.children.find(p => p.id === "PAGE_ID"));
    const frame = await figma.getNodeByIdAsync("FRAME_ID");
    const sections = frame.findAll(n => n.type === "INSTANCE").map(inst => {
      const mc = inst.mainComponent;
      const cs = mc?.parent?.type === "COMPONENT_SET" ? mc.parent : null;
      return {
        instanceId: inst.id,
        instanceName: inst.name,
        componentName: mc?.name ?? null,
        componentKey: mc?.key ?? null,
        componentSetName: cs?.name ?? null,
        componentSetKey: cs?.key ?? null,
      };
    });
    figma.closePlugin(JSON.stringify({ createdNodeIds: [], mutatedNodeIds: [], sections }));
  } catch (e) {
    figma.closePluginWithFailure(e.message);
  }
})()

5. Build a Component Map From the Design System

Prefer authoritative sources in this order:

  1. Existing screens in the same library or workfile that already use the system
  2. Known library pages inspected directly with use_figma
  3. search_design_system as a fallback only

When using search_design_system, remember:

For each candidate, capture:

Do not default blindly to the library's primary or default variant.

Before choosing a variant, inspect the original node for:

Then compare those cues against the available component-set variants and choose the closest match. If the family is correct but the variant match is ambiguous, call that out instead of silently using the default variant.

6. Decide Section Strategy

Use these heuristics:

Common patterns:

7. Update One Section At A Time

Never rewrite the entire screen in one script.

For each section:

  1. Read the current node IDs.
  2. Import or locate the library component.
  3. Match the closest variant to the original section before swapping or rebuilding.
  4. Detect whether the parent uses auto-layout.
  5. Create or swap only that section.
  6. Return all mutated node IDs.
  7. Validate with get_screenshot.

Prefer swapComponent() when the existing node is already an instance of a compatible family and you want to preserve overrides.

Prefer rebuilding beside the original when:

When the parent is not auto-layout, treat replacement as a layout-risk operation.

For non-auto-layout parents:

8. Handle Import Failures Explicitly

If importComponentSetByKeyAsync() or importComponentByKeyAsync() fails or times out:

  1. Stop.
  2. Do not continue making unrelated edits and pretend the section is connected.
  3. Check whether exact component keys already exist elsewhere in the target file.
  4. If the library file is accessible, verify the exact component key there.
  5. Try importing the exact component key instead of the component-set key.
  6. If imports still fail, mark the section blocked and report the blocker clearly.

Treat these as real blockers:

9. Validate What Actually Changed

After each section:

At the end, validate the full screen screenshot as well.

Writing Rules

Deliverable Format

When closing the task, report:

If everything is blocked, say that plainly and include the exact failure mode instead of a vague summary.

_This page brought to you by the 🦄 Magic Automation Unicorns of LightSpeedWP._

Automation Docs

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.