kern
by jpoindexter
README.md
# KERN
**One scan. Every tool. Full codebase intelligence.**
KERN scans your codebase once — components, hooks, routes, tokens, imports, patterns, database schemas — then feeds that context to every AI coding tool you use. Claude Code, Cursor, Windsurf, Copilot, Gemini, Cline — all get the same rich context, automatically.
```
Without KERN: AI guesses your codebase → generic output → manual corrections
With KERN: kern scan → every AI tool knows your codebase → accurate output
```
## Quick Start
```bash
# Scan your codebase (25 scanners, 8 output formats)
npx @usekern/cli scan
# Initialize with your design system
npx @usekern/cli init
# Install Claude Code hooks for automatic context injection
npx @usekern/cli activate
# Check your code for design violations
npx @usekern/cli check
# Auto-fix what it finds
npx @usekern/cli fix
```
## How It Works
### Codebase Intelligence
`kern scan` runs 25 scanners across your project and outputs context files for 8 AI tools:
| Output | Tool |
| --------------------------------- | --------------------------------------------- |
| `AGENTS.md` | Universal (Cursor, Copilot, Gemini, Zed, 20+) |
| `CLAUDE.md` | Claude Code |
| `.cursorrules` | Cursor (legacy) |
| `.cursor/rules/` | Cursor (new MDC format) |
| `.github/copilot-instructions.md` | GitHub Copilot |
| `.windsurfrules` | Windsurf (Codeium) |
| `GEMINI.md` | Google Gemini CLI |
| `.clinerules` | Cline / Roo Code |
The scan covers: framework detection, components, hooks, API routes, design tokens, import graphs, database schemas, env vars, test coverage, security audit, anti-patterns, and more.
### Claude Code Integration
`kern activate` installs PreToolUse hooks so Claude Code automatically gets file-level context (component info, imports, design rules) before every read/edit — zero manual prompting.
### Design System Enforcement
Pick from 8 built-in design system presets. KERN serves them via MCP tools — AI queries for components, tokens, and patterns instead of guessing, then KERN checks the output with regex-based rules.
```
AI: → calls kern_suggest("settings page")
← components, layout pattern, spacing rules
AI: → calls kern_component("Card")
← import path, variants, props, example, rules
AI: → calls kern_tokens("colors")
← ONLY your valid semantic tokens
AI: → writes code → calls kern_check(code)
← "0 violations"
```
No AI in the enforcement layer. File lookup + regex + BM25 search. Deterministic.
## Scanners
25 built-in scanners run in parallel:
| Scanner | What it finds |
| ------------------ | ------------------------------------------------- |
| `framework` | Framework, language, router, styling |
| `components` | React components with props, complexity, imports |
| `hooks` | Custom React hooks and their requirements |
| `api-routes` | Next.js API routes with methods and Zod schemas |
| `imports` | Import graph, hub files, circular dependencies |
| `tokens` | Design tokens from CSS variables and Tailwind |
| `database` | Prisma and Drizzle schemas |
| `type-exports` | Exported TypeScript types, interfaces, enums |
| `stats` | File counts, line counts, size |
| `env-vars` | Environment variables from .env and source |
| `tests` | Test coverage mapped to components |
| `patterns` | Code patterns (react-hook-form, Zustand, tRPC) |
| `security` | npm audit and outdated packages |
| `complexity` | Codebase complexity with AI model recommendations |
| `git` | Git history, branches, uncommitted changes |
| `variants` | CVA variant definitions |
| `dependencies` | Component import dependencies |
| `barrels` | Barrel export files |
| `utilities` | cn(), shadcn/ui, Radix, CVA detection |
| `file-tree` | Visual file tree representation |
| `monorepo` | Workspace configuration (pnpm, yarn, lerna) |
| `graphql` | GraphQL type definitions |
| `commands` | npm scripts |
| `existing-context` | Existing AI docs (CLAUDE.md, .cursorrules) |
| `anti-patterns` | Context-aware anti-patterns from scan data |
## Available Presets (all free)
| Preset | Style | Font | Radius | Key trait |
| --------------------- | --------------------------- | --------------- | ------ | ---------------------------- |
| **Swiss Industrial** | Sharp, monospace, UPPERCASE | Monospace | 0px | Brutalist precision |
| **Material Design 3** | Rounded, tonal, dynamic | Roboto | 28px | M3 color system |
| **Apple Glass** | Clean, native, vibrancy | System (SF Pro) | 12px | 44px touch targets |
| **IBM Carbon** | Structured, productive | IBM Plex Sans | 0px | 2x grid, layer model |
| **GitHub Primer** | Neutral, accessible | System | 6px | Sentence case, green actions |
| **Linear** | Dense, keyboard-first | Inter | 6px | Command palette, compact |
| **Shopify Polaris** | Friendly, commerce | Inter | 8px | Commerce patterns |
| **TypeScript Strict** | Type-safe, predictable | System | 6px | Exhaustive checks, no-any |
## MCP Setup
`kern init` auto-configures your AI tool. Or add manually:
**Claude Code** (`.claude/settings.local.json`):
```json
{
"mcpServers": {
"kern": {
"command": "npx",
"args": ["@usekern/mcp-server"]
}
}
}
```
**Cursor** (`.cursor/mcp.json`):
```json
{
"mcpServers": {
"kern": {
"command": "npx",
"args": ["@usekern/mcp-server"]
}
}
}
```
### MCP Tools (21)
**Codebase Intelligence** (reads from `kern scan` cache):
| Tool | What it does |
| ----------------------- | -------------------------------------------------------------------- |
| `kern_scan_project` | Full project analysis: framework, components, stats, recommendations |
| `kern_file_context` | Everything known about a file: component info, imports, rules |
| `kern_dependency_graph` | Import graph: hub files, circular deps, unused files |
| `kern_related_files` | Find files that import or reference a given symbol |
| `kern_project_stats` | Codebase metrics: files, lines, types, database health |
| `kern_search_codebase` | Cross-category keyword search across scan results |
**Design System** (requires active preset):
| Tool | What it does |
| ---------------- | -------------------------------------------------------------------- |
| `kern_presets` | Lists available design system presets |
| `kern_init` | Initializes a preset, returns all files to write |
| `kern_system` | Full design system reference in one call |
| `kern_suggest` | Recommends components and patterns for a UI task |
| `kern_component` | Returns full component spec: import, variants, props, example, rules |
| `kern_tokens` | Returns design tokens: colors, spacing, typography, sizing |
| `kern_pattern` | Returns code templates for common UI compositions |
| `kern_check` | Validates code against design system rules |
**Infrastructure**:
| Tool | What it does |
| ----------------------- | ----------------------------------------------- |
| `kern_scan` | Analyzes a codebase for design system patterns |
| `kern_snapshot_create` | Captures a point-in-time compliance snapshot |
| `kern_snapshot_list` | Lists all saved snapshots |
| `kern_snapshot_diff` | Compares two snapshots to show drift |
| `kern_snapshot_restore` | Restores code to a previous snapshot state |
| `kern_scrape_url` | Scrapes a URL for design tokens (llms.txt, CSS) |
| `kern_extract_css` | Extracts design tokens from CSS/HTML content |
Plus 6 MCP resources for direct context access.
## CLI Commands
### `kern scan [--format <id>] [--dry-run] [--json]`
Scan your codebase with 25 scanners and generate context files for all AI tools:
```bash
kern scan # Full scan, all formats
kern scan --format claude-md # Generate only CLAUDE.md
kern scan --dry-run # Preview without writing
kern scan --json # Output raw scan data
```
### `kern activate` / `kern deactivate`
Install or remove Claude Code PreToolUse hooks for automatic context injection:
```bash
kern activate # Install hooks + scan if cache is stale
kern deactivate # Remove hooks, preserve other settings
```
### `kern check [file] [--staged] [--strict]`
Find design system violations:
```
KERN: 3 violations
src/app/settings/page.tsx:23
✗ bg-gray-100 → use bg-muted
[auto-fixable]
src/app/settings/page.tsx:45
✗ rounded-lg → use mode.radius
[auto-fixable]
Run `kern fix` to auto-repair (3/3 fixable).
```
Use `--staged` for pre-commit hooks. Use `--strict` for CI (exits with code 1).
### `kern fix [file] [--staged]`
Auto-repair fixable violations (string replacements).
### `kern guard [--threshold <n>] [--fix]`
Pre-commit enforcement. Blocks commits below compliance threshold.
### `kern init [--preset <name>] [--force] [--hook]`
Initialize KERN in your project:
- Copies preset to `.kern/preset/`
- Generates `mode.ts` (typed design token accessor)
- Writes MCP config for detected AI tools
- `--hook`: installs pre-commit hook
### `kern sync`
Generates AI tool context files from your preset (KERN.md, .cursorrules, etc.).
## For Agencies & Freelancers
KERN is built for teams that juggle multiple projects with different brands:
```bash
# Client A: Their brand tokens from Figma
cd client-a && FIGMA_TOKEN=xxx kern sync --from-figma ABC123
# Client B: Material Design
cd client-b && kern init --preset material-design
# Client C: Custom preset from their existing code
cd client-c && kern init --preset ./their-brand/
```
Each project has its own preset in `.kern/`. AI adapts to whichever project is open. No style bleeding between clients.
## CI Integration
Add to your GitHub Actions:
```yaml
- name: KERN Design System Check
uses: jpoindexter/kern/actions/kern-check@main
with:
directory: src
strict: true
```
Or use the CLI directly:
```yaml
- run: npx @usekern/cli check --strict
```
## Preset Format
Each preset is a collection of JSON files:
```
.kern/preset/
├── registry.json # Metadata, component list
├── tokens.json # Colors, spacing, typography, sizing
├── rules.json # FORBIDDEN/REQUIRED patterns
├── patterns.json # Code templates for UI compositions
├── examples.json # Wrong vs. right code examples
└── components/ # Per-component specs
├── Button.json
├── Card.json
└── ...
```
## Packages
| Package | Description |
| -------------------------------------------- | --------------------------------------------------------------- |
| [`@usekern/cli`](packages/cli) | CLI tool (23 commands, 25 scanners, 8 format generators) |
| [`@usekern/mcp-server`](packages/mcp-server) | MCP server (21 tools + 6 resources) |
| [`@usekern/core`](packages/core) | Rules engine, suggest engine, fixer, preset loader, composition |
| [`@usekern/action`](packages/action) | GitHub Action — check mode, PR review bot, LLM review pass |
| [`@usekern/gitlab`](packages/gitlab) | GitLab CI — inline MR discussion comments via Discussions API |
| [`@usekern/bitbucket`](packages/bitbucket) | Bitbucket Pipelines — Code Insights annotations |
| [`kern-vscode`](packages/vscode) | VS Code extension — inline squiggles, quick-fix, @kern chat |
## Development
```bash
pnpm install
pnpm build # Build all packages (turbo)
pnpm test # Run all 245 tests
pnpm type-check # TypeScript validation
```
## License
MIT
This server cannot be deployed
Maintenance
ActivityInactive
ResponsivenessNo recent community issues