This document describes the end-to-end workflow for the Cursor ACE Orchestrator, from initialization to the automated write-back loop.
The workflow begins by preparing the repository for agent orchestration.
- Creates the
.ace/directory for tracked metadata. - Creates the
.ace-local/directory for local session state (git-ignored). - Generates a default
AGENTS.mdin the root if it doesn't exist. - Sets up the
agents.yamlregistry andownership.yaml.
Before running tasks, agents are defined and code modules are mapped to them.
- Create Agent:
ace agent create --name Aegis --role auth - Assign Ownership:
ace own src/auth --agent <agent-id> - Registry Update: The orchestrator updates
.ace/agents.yamland.ace/ownership.yaml. - Playbook Creation: A corresponding
.cursor/rules/<role>.mdcis created using a template if it doesn't exist.
The core loop consists of four distinct phases, with an optional iterative wrapper.
When a user runs ace run "task" or ace loop "task", the orchestrator:
- Resolves Agent: Finds the owner of the target file(s) via longest-prefix match in
ownership.yaml. - Gathers Memory:
- Reads global rules (
_global.mdc). - Reads the agent-specific playbook (
<role>.mdc). - Fetches recent decisions (ADRs) from
.ace/decisions/. - Retrieves state from the last session in
.ace/sessions/. - Injects shared learnings from
.ace/shared-learnings.mdc.
- Reads global rules (
- Composes Prompt: Wraps the user task with a "Task Frame" (e.g.,
implement,debug,review) and the gathered context. - Token Management: Applies context pruning based on the selected Token Mode (Low, Medium, High).
- Execute: The orchestrator invokes the
cursor-agentin headless mode. - Verify (TDD): If running via
ace loop, the orchestrator executes the specified test command (e.g.,npm test). - Analyze: If tests fail, a reflection prompt analyzes the failure to update the memory for the next iteration.
- Coordinate (SOP-driven): If multiple agents are involved, they follow the Consensus SOP via Agent Mail.
- UI/UX Mockup: If the task involves UI, the agent uses Google Stitch to generate mockups and extract code before implementation.
- Review: Other agents may perform a PR Review SOP on the changes if the Token Mode is set to Medium or High.
Once the task is completed (or max iterations reached):
- Reflection Prompt: The orchestrator sends the agent's output and test results to a reflection model.
- Extraction: The model identifies:
- Strategies (
[str-XXX]) that worked or failed (updatinghelpful/harmfulcounters). - Pitfalls (
[mis-XXX]) encountered. - Decisions (
[dec-XXX]) for ADRs.
- Strategies (
- Delta Update: A JSON delta is generated for the playbook.
- Audit (Optional): If Token Mode is High, a Subsystem Health SOP is triggered to check for DRY/YAGNI violations.
- Playbook Update: The
.cursor/rules/<role>.mdcis updated incrementally. - Session Logging: Detailed logs are stored in
.ace/sessions/. - Principles Enforcement:
- TDD: No code without a failing test first.
- YAGNI: Implement only what is needed to pass the current test.
- DRY: Shared utilities are extracted if used in >1 place.
Over time, the orchestrator maintains the playbooks:
- Pruning:
ace memory pruneremoves strategies whereharmfulcounts significantly outweighhelpfulcounts. - History:
ace memory historyallows the user to browse past session logs.
graph TD
A[User: ace run/loop] --> B[Context Builder]
B --> C[Resolve Agent & Memory]
C --> D[Execute cursor-agent]
D --> E{Tests Pass?}
E -- No (ace loop) --> F[Analyze Failure]
F --> G[Update Memory]
G --> D
E -- Yes --> H[Reflection Model]
H --> I[Extract Delta]
I --> J[Update .mdc Playbook]
I --> K[Log Session .md]
J --> L[End Task]
K --> L