Kirak for AI Coding Agents
Kirak is designed from the ground up for autonomous and collaborative AI coding agents (Claude Code, Cursor, Codex, Gemini / Google Antigravity, GitHub Copilot).
Because Kirak applications are declarative (data schemas, access policies, modules, and background tasks are defined in structured JSON rather than imperative boilerplate), AI agents can build, refactor, and maintain production-grade APIs with extraordinary reliability.
The Golden Rules for AI Agents
Section titled “The Golden Rules for AI Agents”- Ask the CLI Instead of Guessing: Kirak’s CLI reports every module, provider setting, schema rule, and environment variable for the exact installed version. Never hallucinate configuration keys.
- Validate After Every Edit: Always run
kirak validate --jsonafter modifying configuration or code. - Kirak First, Python Last: Implement functionality using declarative models, row-level access rules, built-in modules, and providers before writing custom Python hooks or FastAPI routes.
- Data Access Strictly Through the Facade: Access application data strictly via
kirak.<operation>()orkirak.graphql(). Never open raw database connections or execute unchecked SQL queries.
Autonomous Agent Workflow
Section titled “Autonomous Agent Workflow”flowchart TD START["User Prompt / Feature Request"] --> INSPECT["1. Inspect Project Facts<br/>kirak info --json / kirak catalog --json"] INSPECT --> PLAN["2. Plan Schema & Access Rules<br/>Declare in models/*.json & kirak.json"] PLAN --> DRAFT["3. Test Draft (Pre-Write Validation)<br/>kirak validate models --file draft.json --json"] DRAFT --> VALID{"Draft Valid?"} VALID -->|No| FIX["Refine JSON according to problem codes"] FIX --> DRAFT VALID -->|Yes| WRITE["4. Write File to Disk"]
WRITE --> CODE_VAL["5. Validate Entire Project & Code<br/>kirak validate --code --json"] CODE_VAL --> DRY_RUN["6. Review Migration SQL (Dry Run)<br/>kirak db makemigrations --dry-run --json"] DRY_RUN --> SAFE{"Schema Changes Safe?"} SAFE -->|Destructive| REVIEW["Halt & Prompt User for Confirmation"] SAFE -->|Safe| MIGRATE["7. Apply Migration<br/>kirak db makemigrations & kirak db migrate"] MIGRATE --> VERIFY["8. Verify Endpoints via GET /docs or API"]Agent Setup & Orientation Files
Section titled “Agent Setup & Orientation Files”When kirak new scaffolds a project, it generates specialized assets for coding agents:
1. AGENTS.md
Section titled “1. AGENTS.md”A standardized instruction file placed in the repository root. Most coding agents read AGENTS.md automatically upon launching in a workspace. It instructs the agent to:
- Use the virtual environment’s executable (
.venv/bin/kirakor.venv\Scripts\kirak.exe). - Query facts using
--jsonflags. - Run
kirak validateafter every file operation. - Inspect migrations before executing DDL.
- Handle
kirak deployresults as in Deploying: what an agent does with each result.
2. KIRAK.md
Section titled “2. KIRAK.md”The project document: what the app does, its roles, models, modules and design decisions. AGENTS.md tells the agent to read it before starting work and to keep it current.
3. CLAUDE.md and GEMINI.md
Section titled “3. CLAUDE.md and GEMINI.md”Claude Code and Gemini CLI read their own file instead of AGENTS.md. Each holds only imports of AGENTS.md and KIRAK.md (@AGENTS.md in CLAUDE.md, @./AGENTS.md in GEMINI.md), so both tools load the same instructions. Write instructions in AGENTS.md, not in these files.
4. JSON Schemas (.kirak/)
Section titled “4. JSON Schemas (.kirak/)”Contains the JSON Schemas corresponding to the exact Kirak version installed:
manifest.schema.jsonmodel.schema.jsonagent.schema.jsonmcp.schema.json
Every scaffolded kirak.json and models/*.json includes a "$schema" property referencing .kirak/, enabling schema compliance in editors and agent tool loops.
Querying Project Facts via CLI
Section titled “Querying Project Facts via CLI”Agents should never guess parameter names or configuration options. Every facts command outputs a consistent JSON envelope with --json:
{ "kirak_version": "0.1.1", "command": "info", "ok": true, "data": { "..." }, "problems": []}Essential Fact Commands
Section titled “Essential Fact Commands”| Command | Question Answered | Agent Usage |
|---|---|---|
kirak info --json |
What modules, models, agents, and migrations exist in this project? | Run at the start of any conversation to orient context. |
kirak modules [NAME] --json |
What operations, typed parameters, and hook events does this module offer? | Run before implementing a module feature. |
kirak providers MODULE [TYPE] --json |
What configuration keys, secrets, and pip extras does this provider need? | Run before configuring third-party providers. |
kirak env --json |
Which environment variables are required, and are they set? | Run before diagnosing runtime startup errors. (Masks secret values). |
kirak schema --print NAME |
What is the exact JSON Schema for models or manifests? | Run when verifying valid JSON properties. |
kirak db status --json |
Which migrations are pending or applied? | Run before applying schema migrations. |
kirak db makemigrations --dry-run --json |
What SQL will Kirak generate for the current model changes? | Run to review generated DDL before writing migration files. |
Modules the Catalog Describes
Section titled “Modules the Catalog Describes”| Module | Install | Summary |
|---|---|---|
auth |
always on | Registration, login (password, OTP, social, MFA), JWT and API keys, email verification and password reset. Always enabled. |
ai |
pip install "kirak[ai]" |
LLM prompts and agents (defined in agents/*.json) with native Kirak tools, conversations, cost caps and review loops, on pydantic-ai. |
integrations |
pip install "kirak[integrations]" |
Users connect their own accounts (OAuth 2) or save API keys. App code calls the provider’s API with an authenticated httpx client; Kirak holds and refreshes the tokens. |
mcp |
pip install "kirak[mcp]" |
MCP servers for AI agents, one JSON file each in mcp/: the Kirak operations each server offers as tools, who may connect, and a rate limit. Served at /mcp/ |
monitoring |
pip install "kirak[monitoring]" |
Request metrics, slow requests, captured logs, audit and AI run records in a local SQLite file, with retention and read endpoints for dashboards. |
notifications |
an extra per provider | Email, SMS, push, instant messages and outgoing webhooks through named provider instances, plus an in-app inbox and per-user channel preferences. |
payments |
an extra per provider | Payments through named provider instances: checkout, webhooks with signature checks, refunds, subscriptions, saved payment methods, marketplace payouts. |
scheduler |
an extra per provider | Background jobs and recurring tasks: enqueue, delay, retry with backoff, several queues and queue backends. |
storage |
pip install "kirak[storage]" |
Image and file uploads through named provider instances, with type and size limits, compression, resizing and thumbnails. |
vector |
an extra per provider | Vector stores and embeddings for retrieval (RAG): indexes, upsert, delete, fetch, search and embed. No HTTP endpoints; call it from your own routes, hooks and agent tools. |
Validating Drafts Before Writing
Section titled “Validating Drafts Before Writing”Agents can validate draft configurations in memory without creating temporary files or touching the filesystem:
1. Test a Draft File via CLI
Section titled “1. Test a Draft File via CLI”# Validate a draft model file against project schemas and relationshipskirak validate models --file ./draft_model.json --json2. Test an In-Memory Override
Section titled “2. Test an In-Memory Override”# Validate how a proposed change to 'orders.json' interacts with existing modelskirak validate --override model:orders=./proposed_orders.json --json3. Static Python Code Inspection
Section titled “3. Static Python Code Inspection”# Check Python hooks, custom routes, and imports without running codekirak validate --code --json--code parses Python files into ASTs to check:
- That hook listeners subscribe to valid model events (
before_create,after_update). - That imports reference existing Kirak modules or dependencies.
- That custom FastAPI routes do not shadow declarative Kirak endpoints.
Running the Dev MCP Server (kirak dev mcp)
Section titled “Running the Dev MCP Server (kirak dev mcp)”Kirak includes a built-in Model Context Protocol (MCP) server designed to connect directly to coding agents over standard input/output (stdio):
kirak dev mcpSupported IDE Integrations
Section titled “Supported IDE Integrations”Claude Code Configuration
claude mcp add --transport stdio kirak-dev -- .venv/bin/kirak dev mcpCursor Configuration (`.cursor/mcp.json`)
{ "mcpServers": { "kirak": { "command": ".venv/bin/kirak", "args": ["dev", "mcp"] } }}VS Code Configuration (`.vscode/mcp.json`)
{ "servers": { "kirak": { "type": "stdio", "command": ".venv/bin/kirak", "args": ["dev", "mcp"] } }}MCP Tool Safety Gate
Section titled “MCP Tool Safety Gate”The dev MCP server filters exposed tools to protect developer environments:
- Sensitive operations (
login,register,verify_otp,create_api_key) are taggedtool_safe: falsein Kirak’s catalog. - The MCP server strictly blacklists these tools from LLM tool discovery, preventing credentials, private keys, and passwords from leaking into model prompt contexts.
Database Migrations: The Agent Safety Protocol
Section titled “Database Migrations: The Agent Safety Protocol”When assisting users with schema changes, AI agents must adhere to the following sequence:
- Modify Model Definition: Edit or create
models/<name>.json. - Dry Run Verification: Execute
kirak db makemigrations --dry-run --json. - Inspect Output:
- If
destructive: true(e.g. dropping columns or tables), halt and warn the user before proceeding. - If safe, generate the migration:
kirak db makemigrations <name>.
- If
- Apply Migration: Run
kirak db migrate. - Verify: Check
kirak db status --jsonto ensure zero pending migrations remain.
Deploying: what an agent does with each result
Section titled “Deploying: what an agent does with each result”kirak deploy --json returns the same envelope as every other command. An agent deploys only when the user asks, reads the code of each problem, and never retries a refused deploy unchanged. The project’s AGENTS.md carries the same rules.
| Result | What the agent does |
|---|---|
Deployed, with claim_url, restricted and python_files |
The instance is unclaimed. Give the user the claim_url and tell them kirak deploy claim-code prints their claim code. python_files is how many custom Python files the bundle has. Do not redeploy: custom Python endpoints answer 403 INSTANCE_NOT_CLAIMED (with the X-Kirak-Restricted: custom_python_blocked header) until the claim, and a redeploy does not change that. Wait for the user. |
STUDIO_AHEAD |
Studio has edits the local code does not include. The message names the Studio PR to merge (or the studio/changes branch when no PR is linked). After the user merges it, git pull and deploy again. Add --discard-studio-changes only when the user says to drop Studio’s edits. |
DEPLOY_AHEAD |
Someone deployed a newer version. Run git pull origin main, then deploy again. There is no Studio PR to merge. |
MISSING_KEYS warning |
The deploy went live, but keys the project needs are not set. Tell the user the key names exactly as listed; they add them in Studio or with kirak env push. Do not ignore the warning. |
DATA_LOSS_BLOCKED |
The migration would drop tables or columns. List each one (the problems name them) and ask the user. Pass --allow-data-loss (or --force) only after their explicit approval. |
| “This project has been claimed. Log in with ‘kirak login’ and redeploy.” | Ask the user to run kirak login (it opens a browser), then deploy again. |
| “The unclaimed deployment has expired.” | The unclaimed instance’s time ran out. kirak deploy again creates a new one. |