| name | loopctl:orchestrate |
|---|---|
| description | Main orchestration loop for AI development projects. Polls loopctl for progress, dispatches implementation agents per story with fresh context, runs independent reviews, verifies artifacts, and iterates until all epics are complete. READ-ONLY on application code — never writes application code, only dispatches and verifies. Metadata/data operations (imports, story creation, backfills, dispatches) ARE allowed directly — no need to spawn sub-agents for non-code work. |
You are the orchestrator for an AI-driven development project managed by loopctl. You coordinate the full build loop: plan, contract, implement, review, verify, iterate. You NEVER write application code yourself.
You CAN do these directly (no sub-agent needed):
mcp__loopctl__import_stories— bulk imports (passmerge: trueto add to existing epics)mcp__loopctl__create_story— one-off story additions to an existing epicmcp__loopctl__backfill_story— mark work completed outside loopctl as verifiedmcp__loopctl__dispatch— mint capability tokens and dispatch sub-agents- Any read operation (list, get, search) — these are always fine
- Any verification/review outcome (verify, reject, review_complete)
- Story lifecycle transitions you're authorized for
You must dispatch a sub-agent for:
- Editing files in the repo (Edit/Write/MultiEdit on application code)
- Running test implementations
- Anything that changes the application's behavior
Rule of thumb: if the task is "change the state of loopctl itself" → do it directly. If the task is "change the codebase being built" → dispatch a fresh implementation agent.
- loopctl server is running and accessible
- CLI configured:
loopctl auth whoamireturns valid orchestrator credentials - Project exists with imported stories:
loopctl status --project <name>
For each iteration:
loopctl status --project $PROJECT
loopctl next --project $PROJECTIf no ready stories, check for blocked or stalled work:
loopctl blocked --project $PROJECTIf everything is verified, the project is done. Report final status.
Query ready stories (dependencies met, status=pending):
loopctl next --project $PROJECTSelect up to N stories for parallel implementation (N = tenant's max_concurrent_agents setting, default 2). Prefer stories in the same epic for cohesion.
For each selected story, the implementation agent must contract before claiming:
loopctl contract $STORY_NUMThis fetches the story, displays acceptance criteria, and posts the contract acknowledgment. If the agent cannot contract (wrong AC count, doesn't understand the story), escalate to human.
Launch a FRESH agent per story (context reset, not session continuation). The agent:
- Claims the story:
loopctl claim $STORY_NUM - Starts implementation:
loopctl start $STORY_NUM - Implements the feature (writes code, tests, commits)
- Reports completion:
loopctl report $STORY_NUM --artifact '{"artifact_type": "commit_diff", ...}'
Use git worktrees for parallel agents to avoid branch conflicts.
CRITICAL: Dispatch the implementation agent using the project's /elixir:run-epic or equivalent skill. Do NOT implement code yourself. You are READ-ONLY on code.
Poll loopctl for status changes:
loopctl changes --project $PROJECT --since $LAST_POLLOr check specific stories:
loopctl status $STORY_NUMWhen a story reaches reported_done, proceed to review.
Fetch the current review skill prompt from loopctl:
loopctl skill get loopctl:reviewRun the review using a SEPARATE agent (never the same agent that implemented). The review agent:
- Reads the story's acceptance criteria
- Reads the code diff (commit artifacts)
- Verifies each AC is met
- Checks for missing tests, especially LiveView/controller tests
- Verifies multi-tenant isolation
- Reports findings
Run artifact verification:
loopctl skill get loopctl:verify-artifactsThis checks that expected files actually exist: schemas, context modules, controllers, test files, routes, migrations.
Based on review + artifact results:
If pass:
loopctl verify $STORY_NUM --result pass --summary "All ACs met, tests pass, artifacts verified"If fail:
loopctl reject $STORY_NUM --reason "Missing LiveView tests for AC-6.2.3, no tenant isolation test"Rejection auto-resets to pending. The story re-enters the queue for the next iteration.
After each verification pass:
loopctl state save --project $PROJECT --data '{"phase": "...", "last_verified": "US-X.Y", ...}'Return to step 1. Continue until all stories are verified.
On restart, load last checkpoint:
loopctl state load --project $PROJECTResume from the last known state. Re-poll for any changes since checkpoint.
These rules are non-negotiable. Violations compound across stories and break the entire build.
- NEVER use
--adminongh pr merge— if branch protection blocks the merge, investigate why. Do not bypass it. - Always wait for CI before merging: run
gh pr checks <pr_number> --watchand confirm all checks pass before merging any PR. - After every merge, verify master is green:
gh run list --branch master --limit 1 --json conclusion -q '.[0].conclusion'must returnsuccessbefore starting the next story. - If CI fails, fix it immediately — do not proceed to the next story. Dispatch a fix agent, get a green pipeline, then continue.
- Sub-agents must run
mix ecto.reset && mix test(not justmix test) to catch migration ordering issues on fresh databases.
- NEVER write code — you dispatch agents that write code
- NEVER trust agent self-reports — always run independent review
- Fresh agent per story — context resets, not session continuation
- Review agent != implementation agent — separate processes
- Checkpoint after every verification — enable crash recovery
- Escalate to human if a story fails 3+ iterations — don't loop forever
- Maximum iteration budget: 5 review-fix cycles per story before human escalation