Engineering Standards for Chemical X
AI models do not just need more context; they need strictly bounded context. These 7 pillars eradicate context rot, prevent phantom imports, and keep Claude, Gemini, Antigravity, and Cursor fully reliable.
The 7 Pillars of Molecular Architecture
Every AST hazard check executed locally in under 5 seconds by the Chemical X auditor. Guarantees single-purpose files, reduces context token burn, and eliminates LLM hallucinations.
Pillar 1: File Line Budget (< 500 LOC)
LINE_BUDGET_FILECalibrated 3-tier sliding scale: Warning (500-999), Severe (1000-1999), and Extreme (2000+) monoliths.
Pillar 1: Molecule Capsule Limit (< 100 LOC)
LINE_BUDGET_MOLECULEEnforces strictly single-purpose UI capsules with declarative bindings and zero business logic bloat.
Pillar 2: Two-Stage Atomic Booleans
CONTROL_FLOW_INLINE_BOOLEANCatches multi-clause inline logic: single-concept atomic booleans composed into unified decisions.
Pillar 2: Zero Nested Ternaries
CONTROL_FLOW_NESTED_TERNARYEliminates nested conditional branches that cause AI hallucination and logical degradation.
Pillar 3: Composable Destructuring Contract
HOOK_SATURATIONLimits hooks to 3-5 return properties; flags components importing more than 5 individual hooks.
Pillar 4: Domain Type Co-Location
TYPE_COLOCATIONProhibits type monoliths; mandates co-located types/*.d.ts capsules (< 100 LOC) per feature.
Pillar 5: 4-Tier Zero-Inline-Style & Anti-Tailwind-Soup
RAW_INLINE_STYLEProhibits raw inline styles and long utility chains (> 4-5 classes); mandates Level 1 atom props or scoped classes via @apply or mixins.
Pillar 6: Self-Cleaning Lifecycle Timers
TIMER_DISCIPLINEDetects raw setInterval or setTimeout calls lacking automatic unmount disposal.
Explore the 7 Chapter Specifications
Expand each chapter below to inspect key architectural takeaways, clean molecular code patterns, and common monolith traps.
Every entity in the codebase has a single, indivisible molecular responsibility. Keep top-level views under 20 lines reading like a Table of Contents.
Quantum Architectural Rules & Code Locked
To protect our competitive edge, full code patterns and copyable AGENTS.md rules for Chapter 1 are reserved for Vault members.
Unlock the Complete Vault & Agent Directives
Get unrestricted access to the complete 7-chapter specification, ready-to-use .cursorrules, AGENTS.md, CI pre-commit gates, and the private starter repository.
Engineered for Machine Cognition
Deterministic architecture and runtime intelligence engineered for autonomous coding agents. Chemical X isolates the exact mechanical guardrails models need to operate without context rot or prompt fatigue.
AST Symbol-Index vs. Context Dumps
Don’t force LLMs to grep blindly or dump 600-line files into prompt windows. Chemical X builds an in-memory SQLite WAL index (.chemx/index.db). Agents resolve symbol signatures, export boundaries, and hook dependencies in sub-100ms for ~30 tokens.
- ✓In-memory SQLite WAL mode indexation
- ✓Sub-100ms symbol signature extraction
- ✓Transitive caller & hook dependency graphs
// 28 Tokens Ingestion (vs 2,400 raw LOC)
$ chemx q useCheckout --inspect
Symbol: useCheckout (Composable)
Exports: [isUnlocked, openCheckout, lockAccess]
File: src/composables/useCheckout.ts (48 LOC)
Transitive Callers: [AppHeader, FunnelOfferSection]Syntactic AI Slop & Code Decay Detection
Standard linters only check syntax; Chemical X detects when an LLM writes hallucinated or degrading code. Catches conversational chat residue, echo comments, shallow paranoia try/catches, and lazy truncation placeholders before they reach git.
- ✓Flags conversational residue & chat preambles
- ✓Catches shallow empty catch {} and echo comments
- ✓Blocks lazy '// ...rest of code' truncation placeholders
// AST Slop Prevention in Pre-Commit
✖ AI Slop Detected in src/views/dashboard.vue:
Line 42: Conversational residue comment
Line 88: Lazy truncation placeholder "// ..."
Line 114: Shallow empty try/catch block
Result: Commit blocked before hitting git.Single-Permission MCP Master Gateway
Eliminate tool sprawl and continuous permission prompts. Instead of configuring 14 disparate MCP tools, Chemical X exposes AST queries, surgical line patching, and silent verification through a single consolidated tool gateway.
- ✓1-time MCP approval for the entire agent toolchain
- ✓Surgical line-bounded patching (chemx patch)
- ✓Zero-config integration for Claude Code, Cursor & Cline
// Single Master Tool Gateway (Zero Permission Spam)
await mcp.callTool("chemx", {
action: "patch",
params: {
path: "src/atoms/Button.vue",
lines: "12-28",
replacement: "<button :class='atomClasses'>..."
}
});Silent Closed-Loop Verification & Telemetry
Stop blasting 15,000+ tokens of raw compiler logs into agent context windows. Chemical X orchestrates AST validation, TypeScript typechecks, and tests into a token-budgeted 45-token receipt, surfacing failure diffs only when code breaks.
- ✓Compacts 17,000 tokens of noisy logs down to ~45 tokens
- ✓Automated PR token cost & telemetry tracking
- ✓Isolated failure-diff injection on test breaks
// Silent Verification Receipt (45 Tokens vs 17,200)
$ chemx verify
✔ AST Architecture: Clean (0 hazards, Grade A)
✔ TypeScript Check: Clean (0 errors across 48 files)
✔ Vitest Suite: 18 passed (214ms)
Token Telemetry: 45 tokens ingested | $0.0001 est.
Status: Pipeline verified green.Master MCP Gateway & SQLite Concurrency
Beyond search and passive memory: Chemical X provides active multi-agent concurrency leases and closed-loop verification for autonomous development teams.
Master MCP Gateway (chemx)
Eliminates per-tool confirmation prompts. A single chemx({ action, params }) call gives agents verified file patching, AST querying, line slicing, and test execution without prompt fatigue.
SQLite Concurrency & File Leases
Dedicated file_leases and file_lock_queue SQLite tables in WAL mode prevent race conditions when multiple autonomous agents edit the same repository simultaneously.
Closed-Loop Gated Verification
When an agent reports a task 'Done', Chemical X automatically re-runs the rule against the AST. Completion is strictly rejected unless the violation is provably eliminated.
The 7 Layers of Chemical X
Chemical X is not a single CLI or scaffolder. It is an architecture-and-tooling protocol that makes software legible, bounded, and mechanically verifiable to AI coding agents.
Architecture Layer
Software shaped like small, independently understandable molecules rather than giant monoliths.
Enforces hard file bounds (<500 LOC), capsules (<100 LOC), TOC views (<20 LOC), and 2-stage atomic booleans.
Narrows the working context an agent holds in memory, eliminating hallucinated state mutations.
Mechanical Enforcements & Deliverables
- ✓< 500 LOC file ceiling (< 100 LOC capsules)
- ✓< 20 LOC top-level TOC views
- ✓Two-stage atomic booleans with early guards
- ✓Composables returning 3-5 properties max
- ✓[data, error] = await toResult(...) tuples
How to Adopt Chemical X: The 3-Step Loop
Free Instant Audit → Agent MCP Loop → Full Vault Blueprint Run npx chemx audit locally. Zero cloud code upload. Instant MHI score and hazard detection in 5s.
Equip Claude, Gemini, or Cursor with chemx:mcp. Query AST slices and verify edits deterministically.
Unlock the complete 7-chapter specification, ready-to-use .cursorrules, and CI pre-commit gates from $27.