The 3-Step Agent Protocol
Aegil provides an agent-driven development architecture engineered specifically for autonomous AI coding assistants (such as Claude Code, Cursor, Windsurf, and Antigravity). By confining AI operations to declarative specifications and isolated hooks, Aegil’s deterministic compiler and verification harness mathematically prevent hallucinated code and architectural drift.
The problem with AI agents in full-stack repos
Section titled “The problem with AI agents in full-stack repos”AI coding assistants (such as Claude Code, Cursor, Windsurf, or Antigravity) are powerful, but when given an unstructured full-stack codebase, they frequently make subtle, dangerous errors:
- They edit generated ORM models or database migration files directly.
- They forget server-side authorization checks on newly added endpoints.
- They accept client-provided user IDs or roles (
actingUserId), introducing critical security vulnerabilities. - They modify native iOS or Android manifests by hand, breaking build scripts.
Aegil eliminates these risks by providing deterministic boundaries and a machine-readable protocol designed specifically for AI agents.
The 3-Step agent loop
Section titled “The 3-Step agent loop”Instruct your AI agent to follow this exact 3-step execution loop:

Step 1: Edit the Domain Specification (specs/<feature>/*.tsp)
Section titled “Step 1: Edit the Domain Specification (specs/<feature>/*.tsp)”The agent defines or updates entities, @validate bounds, @policy rules, @stateMachine transitions, or custom @mutation operations in specs/<feature>/*.tsp.
Note: Domain specs must reside in feature folders (e.g.
specs/notes/notes.tsp). Onlyapp.tspandplatforms.tsplive at the root. Placing domain specs at the root triggersERR_SPEC_MISPLACED.
Step 2: Run the Compiler in Agent Mode
Section titled “Step 2: Run the Compiler in Agent Mode”The agent executes:
aegil build --project . --agentAegil returns a structured JSON Action Manifest containing agentTasks:
{ "status": "PENDING_IMPLEMENTATION", "agentTasks": [ { "taskId": "escalateTicket", "targetFile": "hooks/escalate_ticket_hook.dart", "expectedClassName": "EscalateTicketHook", "implementsInterface": "EscalateTicketHandler", "contract": { "preconditionsGuaranteedByCompiler": [ "Caller identity and role verified from session", "Database transaction active", "Ticket entity pre-fetched", "CEL policy permissions verified", "State transition to Escalated verified" ], "postconditionsRequiredFromAgent": [ "Assign assignedAgentId", "Transition status to Escalated", "Save changes and return updated Ticket" ] } } ]}The agent reads the task’s contract:
- Preconditions: The agent knows that authentication, transactions, and permissions are already handled and must not be re-checked.
- Postconditions: The agent knows the exact output state required.
Step 3: Implement Hooks and Run the Verification Harness
Section titled “Step 3: Implement Hooks and Run the Verification Harness”When aegil build runs, it scaffolds hook templates with // AEGIL:STUB markers for any pending tasks. The agent replaces the stub logic at targetFile, then rebuilds and verifies:
aegil build --project . --agentaegil verify --project . --agentThe task is only complete when aegil verify --agent returns "status": "VERIFIED".
Essential prompt instructions for AI agents
Section titled “Essential prompt instructions for AI agents”Add these rules to your project’s agent instructions (e.g. AGENTS.md or CLAUDE.md):
- Never edit files in
.aegil/: All files in.aegil/are hash-locked. Modifying them triggersERR_TAMPERED_GENERATED_FILE. - Never accept caller ID or role from the client: All endpoints must derive user identity strictly from the server session.
- Always rebuild after editing hooks: Run
aegil buildbeforeaegil verifyto avoidERR_STALE_HOOK_MIRROR. - Always put domain specs in feature folders: Place specs in
specs/<feature>/*.tspto avoidERR_SPEC_MISPLACED. - Never stop on
VERIFIED_PARTIAL: Verification is only complete when Docker integration tests pass and status isVERIFIED.
What could go wrong?
Section titled “What could go wrong?”| What you see | Why | What to do |
|---|---|---|
ERR_TAMPERED_GENERATED_FILE |
The AI agent edited a generated file in .aegil/. |
Tell the agent to discard the edit and update specs/<feature>/*.tsp instead. |
ERR_STALE_HOOK_MIRROR |
The agent edited a hook file but forgot to run aegil build before aegil verify. |
Instruct the agent to run aegil build before verifying. |
ERR_SPEC_MISPLACED |
The agent created a spec file at specs/*.tsp root. |
Instruct the agent to place domain specs under specs/<feature>/*.tsp. |
Status: UNAVAILABLE |
Docker is not running in the agent environment. | Start Docker so the agent can execute the integration suite. |
Next steps
Section titled “Next steps”- Learn Agent Context & MCP Server.
- Learn Running & Debugging Locally.
- Learn 5-Stage Verification Harness.