Cloister: AI Lifecycle Manager
Cloister is Panopticon’s intelligent agent lifecycle manager. It monitors all running agents and automatically handles:- Model Routing - Routes tasks to appropriate models based on complexity
- Stuck Detection - Identifies agents that have stopped making progress
- Automatic Handoffs - Escalates to specialists when needed
- Specialist Coordination - Manages test-agent, review-agent, and merge-agent
How Cloister Works
Starting Cloister
Specialists
Cloister manages specialized agents that handle specific phases of the development lifecycle:| Specialist | Purpose | Trigger |
|---|---|---|
| test-agent | Runs test suite after implementation | implementation_complete signal |
| review-agent | Code review before merge | After tests pass (manual trigger) |
| merge-agent | Handles git merge and conflict resolution | ”Approve & Merge” button |
Merge Agent Workflow
The merge-agent is a specialist that handles ALL merges, not just conflicts. This ensures:- It sees all code changes coming through the pipeline
- It builds context about the codebase over time
- When conflicts DO occur, it has better understanding for intelligent resolution
- Tests are always run before completing the merge
- Pull latest main - Ensures local main is up-to-date
- Analyze incoming changes - Reviews what the feature branch contains
- Perform merge - Merges feature branch into main
- Resolve conflicts - If conflicts exist, uses AI to resolve them intelligently
- Run tests - Verifies the merge didn’t break anything
- Commit merge - Commits the merge with descriptive message
- Report results - Returns success/failure with details
- Never force-push
- Always run tests before completing
- Document conflict resolution decisions
- Provide detailed feedback on what was merged
Review Pipeline Flow
The review pipeline is a sequential handoff between specialists:- Human-initiated start - A human must click “Review” to start the pipeline
- Automatic handoffs - review-agent → test-agent happens automatically
- Human approval for merge - Merge is NOT automatic; human clicks “Approve & Merge”
- Feedback loops - Failed reviews/tests send feedback back to the work-agent
Queue Processing
Each specialist has a task queue (~/.panopticon/specialists/{name}/hook.json) managed via the FPP (Fixed Point Principle):
urgent > high > normal > low
Completion triggers: When a specialist reports status (passed, failed, or skipped), the dashboard:
- Sets the specialist state to
idle - Checks the specialist’s queue for pending work
- If work exists, immediately wakes the specialist with the next task
Agent Self-Requeue (Circuit Breaker)
After a human initiates the first review, work-agents can request re-review up to 3 times automatically:- First human click resets the counter to 0
- Each
pan work request-reviewincrements the counter - After 3 automatic re-requests, returns HTTP 429
- Human must click “Review” in dashboard to continue
POST /api/workspaces/:issueId/request-review
Specialist Auto-Initialization
When Cloister starts, it automatically initializes specialists that don’t exist yet. This ensures the test-agent, review-agent, and merge-agent are ready to receive wake signals without manual setup.Automatic Handoffs
Cloister detects situations that require intervention:| Trigger | Condition | Action |
|---|---|---|
| stuck_escalation | No activity for 30+ minutes | Escalate to more capable model |
| complexity_upgrade | Task complexity exceeds model capability | Route to Opus |
| implementation_complete | Agent signals work is done | Wake test-agent |
| test_failure | Tests fail repeatedly | Escalate model or request help |
| planning_complete | Planning session finishes | Transition to implementation |
| merge_requested | User clicks “Approve & Merge” | Wake merge-agent |
Handoff Methods
Cloister supports two handoff methods, automatically selected based on agent type:| Method | When Used | How It Works |
|---|---|---|
| Kill & Spawn | General agents (agent-min-123, etc.) | 1. Captures full context (STATE.md, beads, git state) 2. Kills tmux session 3. Spawns new agent with handoff prompt 4. New agent continues work with preserved context |
| Specialist Wake | Permanent specialists (merge-agent, test-agent) | 1. Captures handoff context 2. Sends wake message to existing session 3. Specialist resumes with context injection |
- Capturing the agent’s current understanding (from STATE.md)
- Preserving beads task progress and open items
- Including relevant git diff and file context
- Building a comprehensive handoff prompt for the new model
Handoff Context Capture
When a handoff occurs, Cloister captures:~/.panopticon/agents/{agent-id}/handoffs/ for debugging.
Heartbeat Monitoring
Agents send heartbeats via Claude Code hooks. Cloister tracks:- Last tool use and timestamp
- Current task being worked on
- Git branch and workspace
- Process health
~/.panopticon/heartbeats/:
Heartbeat Hook Installation
The heartbeat hook is automatically synced to~/.panopticon/bin/heartbeat-hook via pan sync. It’s also installed automatically when you install or upgrade Panopticon via npm.
Manual installation:
~/.claude/settings.json:
- The heartbeats directory doesn’t exist
- Write permissions are missing
- The hook script has errors
Configuration
Cloister configuration lives in~/.panopticon/cloister/config.json:
Model Routing & Complexity Detection
Cloister automatically routes tasks to the appropriate model based on detected complexity, optimizing for cost while ensuring quality.Complexity Levels
| Level | Model | Use Case |
|---|---|---|
| trivial | Haiku | Typos, comments, documentation updates |
| simple | Haiku | Small fixes, test additions, minor changes |
| medium | Sonnet | Features, components, integrations |
| complex | Sonnet/Opus | Refactors, migrations, redesigns |
| expert | Opus | Architecture, security, performance optimization |
Complexity Detection Signals
Complexity is detected from multiple signals (in priority order):- Explicit field - Task has a
complexityfield set (e.g., in beads) - Labels/tags - Issue labels like
architecture,security,refactor - Keywords - Title/description contains keywords like “migration”, “overhaul”
- File count - Number of files changed (>20 files = complex)
- Time estimate - If estimate exceeds thresholds
Configuring Model Routing
Edit~/.panopticon/cloister/config.json:
Cost Optimization
Model routing helps optimize costs:| Model | Relative Cost | Best For |
|---|---|---|
| Haiku | 1x (cheapest) | Simple tasks, bulk operations |
| Sonnet | 3x | Most development work |
| Opus | 15x | Complex architecture, critical fixes |
- Start on Haiku for initial exploration
- Escalate to Sonnet for implementation
- Escalate to Opus only if stuck or complexity detected
Related Guides
- Specialists - Detailed specialist agent documentation
- Convoys - Multi-agent orchestration
- Core Commands - Cloister CLI commands