Skip to content

About

TokenLock: The AI Design System & Token Drift Enforcer Agent Skill

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

11 Commits

Folders and files

Repository files navigation

🔒 TokenLock — The AI Design System & Token Drift Enforcer

License: MIT Standard: SKILL.md Dependencies: Zero Compatible: Claude Code | Cursor | Codex | Cline

TokenLock is an open-standard Agent Skill (SKILL.md) that prevents AI coding agents from corrupting production user interfaces with "vibecoded" arbitrary styles, fabricated hex codes, and component reinvention.


🚨 The Bottleneck

Human designers invest weeks crafting cohesive design systems (Tailwind theme scales, CSS variables, Figma tokens). However, when developers prompt an AI agent to build or edit screens:

  • The AI hallucinates arbitrary pixels: It fabricates p-[14px], m-[7px], w-[310px], rounded-[9px] rather than adhering to the 4px/8px grid scale (p-3.5, p-4, rounded-lg).
  • The AI invents custom hex codes: Rather than using semantic tokens (bg-primary, text-muted-foreground), it approximates hex codes (#3468F8 vs design #3B82F6), fragmenting the visual palette.
  • The AI rebuilds base components: It writes new inline <button className="..."> elements from scratch instead of consuming existing design system primitives (<Button>).

💻 Quickstart & Terminal Audit

Run TokenLock on any component, folder, or pull request diff with zero configuration:

# 1. Audit current directory
$ tokenlock

# 2. Audit a specific folder or file
$ tokenlock src/components/

# 3. Automatically fix arbitrary bracket values in-place!
$ tokenlock --fix

# 4. Install automated pre-commit hook in 1 second
$ tokenlock --install-hook
🚨 TokenLock: Found 3 design token drift violation(s):

  • src/components/UserCard.tsx:4
    Offender  : p-[14px] (arbitrary_bracket)
    Suggestion: p-3.5 (14px)

  • src/components/UserCard.tsx:4
    Offender  : #0F172A (hardcoded_hex)
    Suggestion: Use semantic theme color (e.g. text-foreground, bg-primary, var(--ink))

  • src/components/UserCard.tsx:7
    Offender  : rounded-[9px] (arbitrary_bracket)
    Suggestion: rounded-lg (8px)

💡 TokenLock: Found 2 auto-fixable violation(s). Apply fixes now? [Y/n]: y
🔧 Fixed 2 token violation(s) in src/components/UserCard.tsx

🛡️ The 4 Laws of TokenLock

  1. The Token-First Rule: Inspect the project's token source of truth (tailwind.config.*, CSS variables, theme objects) before writing styles. Never invent a color or spacing unit.
  2. The Ban on Arbitrary Brackets: Never emit bracketed arbitrary overrides (p-[...], rounded-[...]). Always map to the nearest valid scale token.
  3. The Hex Code Prohibition: Zero raw hex strings in component markup. Always use semantic theme tokens.
  4. Primitive Component Reuse: Mandatory reuse of existing design system primitives (<Button>, <Card>, <Input>) over inline reinventions.

🚀 Universal Agent Installation

1. Claude Code

Install directly into your project's skills directory:

git clone https://github.com/subinz1/tokenlock-skill.git .claude/skills/tokenlock

2. Cursor

Copy SKILL.md into your .cursor/rules/ directory or add it to Cursor Project Rules.

3. Codex CLI & Cline

Clone into .codex/skills/ or reference SKILL.md in your system prompt.

4. Git Pre-Commit Hook

Prevent arbitrary styles from ever entering git:

echo "python3 scripts/tokenlock.py --path src/" >> .git/hooks/pre-commit
chmod +x .git/hooks/pre-commit

5. GitHub Actions CI

name: TokenLock Lint
on: [pull_request]
jobs:
  tokenlock:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: python3 scripts/tokenlock.py --path src/ --strict

⚡ Zero Dependencies

TokenLock is built with zero external npm or pip dependencies. It runs on any standard Python 3.8+ runtime in under 5 milliseconds, making it fast enough to run on every file save and pre-commit hook.


📂 Repository Structure

tokenlock-skill/
├── SKILL.md                      # Universal Agent Skill specification
├── scripts/
│   └── tokenlock.py              # Zero-dependency static token drift auditor
├── references/
│   └── TOKEN_TAXONOMY.md         # 4px grid spacing tables & semantic token scale
├── fixtures/
│   ├── sloppy_component.tsx      # Real-world AI-generated component with drift
│   └── locked_component.tsx      # Token-hardened production version
├── tests/
│   └── test_tokenlock.py         # Automated unit test suite
├── package.json
├── LICENSE                       # MIT License
└── TODO.md                       # Phase 2 roadmap (Figma API sync, auto-fixer)

📄 License

MIT © Subin George

About

TokenLock: The AI Design System & Token Drift Enforcer Agent Skill

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages