# 06-01 PLAN — Schema + API Agent Defs

## Tasks

1. **Add `arcadia_agent_defs` table to `shared/schema.ts`**
   - Fields: id, tenantId, userId, name, description, spec (jsonb), status, version, lastTaskId, createdAt, updatedAt
   - Run migration if needed

2. **Create `server/agent-defs/service.ts`**
   - `createAgentDef()`, `getAgentDef()`, `listAgentDefs()`, `updateAgentDef()`, `deleteAgentDef()`
   - `updateStatus()` helper for draft → assembling → ready → deployed
   - `incrementVersion()` on deploy

3. **Create `server/agent-defs/routes.ts`**
   - GET `/api/agent-defs` (list by tenantId)
   - POST `/api/agent-defs` (create)
   - PATCH `/api/agent-defs/:id` (update spec/status)
   - DELETE `/api/agent-defs/:id`
   - POST `/api/agent-defs/:id/deploy` (status → deployed, version++)
   - POST `/api/agent-defs/:id/run` (POST to blackboard task)

4. **Register routes in `server/routes.ts`**
   - Import and registerAgentDefRoutes()

## Reuse
- DB functions from existing patterns
- Blackboard service for task creation (no modification)

## Done Criteria
- API responds 200 on all endpoints
- Status transitions work: draft → assembling → ready → deployed
- `lastTaskId` links to blackboard_tasks
