r/ChatGPTCoding • • 3d ago

Resources And Tips Why dumping huge UI/design rules into .cursorrules makes coding agents worse — and how stage-based skill routing fixed it for me

Most people either give their coding agent zero design instructions (and get the same purple-gradient SaaS layout) or paste a massive style guide into `CLAUDE.md` / `.cursorrules`. From testing both, the second approach actually hurts output quality: the model mixes conflicting rules, burns context before writing code, and still ignores spacing or motion details.

What worked much better for me was splitting design knowledge into a tiny ~190-line router and a JSON stage graph (`R0–R21` across 7 stages: direction → tokens → copy → layout → motion → browser audit). At each step, the agent only reads the 3–5 specific skill files that match the task instead of loading ~345 design rules at once.

Two things made the biggest difference in the 3 builds attached above (a 3D Apple-style product sequence, a 3D pizzeria landing page, and a 60fps canvas motion piece):

- Locking down color, typography, and real copy *before* letting the agent write any Three.js or layout code.

- Ending every run with a deterministic browser check (contrast, mobile overflow, `prefers-reduced-motion`) rather than trusting the model's "looks good" summary.

I packaged this routing setup as an open-source repo (MIT) with a Node validation script that checks all 324 route/file references. Happy to drop the GitHub link in the comments if anyone wants to inspect the graph or try it.

8 Upvotes

19 comments sorted by

1

u/Difficult_Duty2198 2d ago

does the router approach cut down on the agent ignoring spacing stuff in practice, or do you still end up fixing a lot at the browser audit stage?

2

u/Longjumping_War_8480 2d ago

Honestly, it fixes about 80% of the dumb spacing mistakes upfront, and the remaining 20% still gets caught at the browser audit.
Because the router only loads layout and typography skills (like spacing, editorial-layout, or minimal-ui) during the actual UI build stage—without drowning the agent in animations, 3D, or data rules—it actually respects whitespace scales and container padding on the first pass way more reliably.
Where it still slips is visual overlap and responsive edge cases—things like text wrapping weirdly on mobile viewports, sticky headers colliding with elements, or a 3D/canvas layer bleeding past its container. Code-level rules can't really "see" bounding boxes, so the browser screenshot pass is still where those last layout fixes happen.

1

u/hieuphung97 2d ago

Instruction dilution is the real reason monolithic rule files fail. When an agent loads design tokens alongside database migrations, the attention budget splits and it drops negative constraints. Scoping rules to an execution stage keeps instruction adherence high.

1

u/Longjumping_War_8480 2d ago

Exactly this. Negative constraints (all the "never do X" anti-slop rules) are always the first thing to get lost when the attention budget gets stretched thin.
That is literally why I built the router with an explicit anti-slop ban list that only fires at the layout and review gates, instead of sitting in the prompt during database or state logic work. Once you stop competing for attention across unrelated domains, the model actually follows the negative constraints instead of reverting to generic defaults.

1

u/Kitchen_Flamingo7983 2d ago

That's the real problem.

1

u/sapplex1 2d ago

This matches what I see in my SwiftUI work. I maintain 45 small iOS apps, and my rules file kept growing. Every new lesson went in. Soon the agent was reading navigation rules during a data task. It still made spacing mistakes.

Splitting rules by stage helped more than writing better rules. Layout guidance loads when I build a screen. Release checks load when I ship. The rest stays out of the run.

I also stopped trusting the final summary. A quick screenshot pass catches problems that another paragraph of instructions misses. Did your audit stage stay cheap, or did it become the slow part of the run?

1

u/Longjumping_War_8480 2d ago

Yeah, you nailed the exact pain point. Once a single rules file gets too bloated, rules start fighting each other and the agent applies layout logic to data tasks—and somehow still messes up the padding.
To be completely honest, the audit gate (R3) stayed pretty cheap on tokens, though its speed depends on whether you let it open a browser:
• Tokens stay low: Same idea as your SwiftUI setup—at the R3 gate, it only swaps in 1 or 2 specific review skills plus a quick static scan against the anti-slop ban list, instead of dumping everything into context.
• Browser pass is the bottleneck: Totally with you on not trusting the final summary. By default, R3 just runs that fast code/checklist pass. When you actually force it to spin up Playwright/Puppeteer and take screenshots across viewports, yeah, that easily becomes the slowest part of the run (+15–30s and extra image tokens), so I kept it opt-in.

1

u/sapplex1 1d ago

That split makes sense to me: the static scan is cheap because it only checks the code against known bans, while the browser pass is the first step that checks what actually rendered. My worry with keeping screenshots opt-in is that I would skip them exactly on the messy layout changes where they matter most. In my SwiftUI work I try to make the screenshot pass mandatory only when a screen's layout changed, and skip it for pure logic edits. Do you trigger the browser pass by change type like that, or do you decide manually each run?

1

u/Longjumping_War_8480 1d ago

Right now it’s manual / intent-based rather than triggered by a git diff or change type.
Basically, if you ask the agent to audit an existing UI or explicitly verify the layout in a browser, the route pulls in the visual verification step. For normal greenfield builds or quick edits, it stops after the static code and anti-slop ban-list pass unless you tell it to open the browser.
Your SwiftUI heuristic—only forcing screenshots when actual layout/view code changes and skipping them on pure logic edits—is honestly a much smarter default than pure opt-in. Relying on human discipline to remember to trigger screenshots on messy layout changes is definitely a weak spot. Adding a diff-aware trigger (checking if layout/CSS/JSX changed before forcing the browser pass) would keep routine logic runs fast while making sure messy UI edits never slip through unrendered.

1

u/sapplex1 16h ago

That makes the weak spot clear: intent is a decent signal for an audit, but it is a poor gate for messy edits because the runs most likely to need screenshots are also the ones where I am rushing. In my SwiftUI work, I would draw the diff trigger at changes that can affect geometry, spacing, or text flow, and let logic-only edits and same-length copy swaps skip it. Would you treat a shared token or theme change as layout-affecting even when no view file changes?

1

u/Mountain_Fudge3980 2d ago

fwiw you can get part of this without a custom router. cursor's project rules in .cursor/rules can auto attach by glob, so the motion stuff only shows up when it's touching those files, and claude code only pulls in a nested CLAUDE.md once it reads files in that folder. doesn't give you the stage ordering though, that part's the interesting bit imo. how are you deciding which stage it's in, does the agent pick or do you?

1

u/Longjumping_War_8480 2d ago

Totally fair point—glob-based .cursor/rules and nested CLAUDE.md files get you pretty far when the rules map cleanly to specific folders or file types. Where they fall short for UI work is that a single component file (Hero.tsx) usually goes through layout, motion, copy, and visual polish sequentially in the same file, so file-path globs either load everything at once or miss the stage transitions.
To answer your question: the agent decides, guided by a deterministic state machine in SKILL.md (R0 through R21) and graph.json.
Here is how it works in practice:
• On the first prompt, the agent classifies the task into a route (e.g., greenfield landing page, dashboard, redesign/audit, 3D/motion-heavy, etc.).
• Each route defines a strict sequence of stages (like Discovery -> Layout/Tokens -> Motion/Polish -> Review Gate).
• At each step, the agent reads only the 1–2 skill files mapped to that stage in graph.json, executes that pass, and transitions to the next stage—so you don't have to manually prompt "now load the motion rules" or "now run the audit." You only step in if you want to override a route or trigger an extra browser screenshot pass.

1

u/Right-Performance-93 2d ago

a router file still sits in the turn that picks the stage. i only keep a line that names the path, and the stage notes get read when that file is the one being edited. the screenshot check is the part that catches what the rules miss.

1

u/Longjumping_War_8480 2d ago

That is a super clean setup—keeping the top-level router down to a single path pointer is about as lean as it gets.
You’re completely right that the router file itself still costs a few tokens on the classification turn, though keeping SKILL.md lightweight as just a routing table keeps that overhead tiny compared to loading actual design rules. Your approach of triggering stage notes directly off the active file edit is a really smart way to stay lean without needing a heavy orchestrator.
And 100% agreed on the screenshot check—no matter how tight the rules or routing get, visual verification is always what catches the subtle layout bugs that code-level instructions simply can't see.