Getting Started
Create a feedback loop between your domain spec and AI agents.
Blocks validates code semantically—AI understands your domain, not just syntax. Run blocks run during development, AI sees issues, fixes code, repeat until pass.
01. Install
npm install -g @blocksai/cli02. Initialize
blocks initCreates blocks.yml. This file can live anywhere—Blocks validates relative to its location.
03. Run
blocks run --allblocks run my.block04. AI Setup Prompt
Copy this into your AI coding assistant to configure Blocks for your project:
Prompt for AI Agent
Set up Blocks validation for this project. Blocks creates a feedback loop between your domain spec and AI agents—it validates code semantically so AI-generated code stays aligned with your requirements.
Docs: https://blocksai.dev
## What to Do
1. Identify repeating modules in this codebase (these are "blocks")
- Examples: themes, posts, endpoints, components, handlers, templates
- Anything you have multiples of that should follow consistent rules
2. Create a `blocks.yml` file (can live anywhere—validates relative to its location)
3. Define the domain:
- Philosophy: High-level principles guiding validation
- Entities: Domain objects with their fields
- Semantics: Concepts to validate (readability, accessibility, etc.)
4. Configure validators (extensible pipeline):
- `schema` - Type/structure validation
- `shape` - File structure and exports
- `domain` - AI-powered semantic validation
- Custom validators as needed
5. Define blocks with their inputs/outputs
## blocks.yml Structure
```yaml
$schema: "blocks/v2"
name: "Project Name"
philosophy:
- "Guiding principles for AI validation"
- "What matters in this domain"
domain:
entities:
entity_name:
fields: [required_field1, required_field2]
optional: [optional_field]
semantics:
quality_metric:
description: "What this measures"
validators:
- schema
- shape
- name: domain
config:
rules:
- id: rule_id
description: "What to enforce"
blocks:
namespace.block_name:
description: "What this block does"
path: "relative/path/to/block"
inputs:
- name: input_name
type: entity.entity_name
outputs:
- name: output_name
type: string
```
## Workflow
After setup, the feedback loop:
```
blocks run --all # Validate all blocks
blocks run block.name # Validate specific block
```
Fix issues, run again, iterate until pass.
Analyze this codebase and create an appropriate blocks.yml configuration.05. Environment
Domain validation uses AI. Set your provider's API key:
OPENAI_API_KEY=...ANTHROPIC_API_KEY=...GOOGLE_API_KEY=...Blocks is LLM agnostic—works with any provider.