Workflow Phases
Relevant source files
The following files were used as context for generating this wiki page:
M31 Autonomous (M31A) operates through a structured seven-phase sequential workflow designed to automate the software development lifecycle from project detection to final deployment. This system ensures that the AI assistant "thinks before acting" by enforcing rigorous planning and verification steps before committing code to a git repository.
The workflow supports multiple operational modes: Auto (adaptive), Full (all 7 phases), Fast (skips Plan), and Direct (skips Discuss, Plan, and Verify). These modes allow the system to scale its procedural overhead based on task complexity.
Sources: internal/engine/workflow/prompts/base.md:20-33, README.md:126-130
Phase Overview and Transitions
The engine moves through phases based on the active WorkflowMode. While the standard path is linear, certain modes allow for shortcutting specific phases to speed up simple tasks.
The diagram shows the linear progression of the seven-phase workflow and the optional shortcuts provided by specific operational modes.
Sources: internal/ui/tui/app_update_phase.go:17-57, internal/engine/workflow/prompts/base.md:20-33
Workflow Phase Descriptions
| Phase | Purpose | Key Activities |
|---|---|---|
| Initialize | Context Setup | Project detection, git initialization, deep analysis, environment pre-flight. |
| Discuss | Requirement Gathering | Clarifying questions to resolve ambiguities in the user's goal. |
| Plan | Strategy Generation | Researching approach, task decomposition, and implementation plan generation. |
| Execute | Code Implementation | Topological task execution using tools (Bash, FileWrite, Edit). |
| Verify | Quality Assurance | Build/test execution and autonomous self-healing of failures. |
| Runtime | Live Validation | Dev server lifecycle management and smoke testing. |
| Ship | Finalization | Pre-ship checklists, final commits, and changelog generation. |
Sources: internal/engine/workflow/prompts/base.md:20-33, README.md:164-173
1. Initialize Phase
The Initialize phase is responsible for setting the project's foundation. It detects the ProjectType (e.g., Go, Node, Python), ensures a git repository exists, and performs optional deep analysis to identify frameworks and project health.
- Key Function:
runInitialize(ctx, goal) - Artifacts: Creates a planning directory and initializes
PROJECT.mdandSTATE.md. - Deep Analysis: Optionally calculates dependency counts, test file ratios, and an overall health score.
Sources: internal/engine/workflow/initialize.go:16-103
2. Discuss Phase
In this phase, the system generates clarifying questions if the user's goal is ambiguous. It captures answers to populate the project context, ensuring the subsequent Plan phase has high-fidelity requirements.
- Logic: Receives project context and goal; provides questions for user response.
- Modes: Skipped in
ModeDirectandModeFast.
Sources: internal/engine/workflow/prompts/base.md:37, internal/ui/tui/app_update_phase.go:21-30
3. Plan Phase
The Plan phase transforms the goal into a structured Implementation Plan. It employs a multi-step process including research, task breakdown, and quality gates.
Planning Sub-steps
- Pre-plan Research: Investigates the codebase to identify existing patterns and risks.
- Plan Generation: Produces a Markdown implementation plan containing a JSON task list.
- Plan Checker: An autonomous revision loop that identifies blockers or missing requirements.
- Coverage Gates: Validates task granularity, security implications, and requirement coverage.
Sources: internal/engine/workflow/plan.go:21-177, internal/engine/workflow/research.go:13-41
Chunked Planning
For complex goals in large codebases (>30 files), the system uses runChunkedPlan. This breaks the implementation into "waves," where wave N only depends on tasks from waves 1 to N-1.
Sources: internal/engine/workflow/plan_chunk.go:48-56, internal/engine/workflow/plan.go:225-272
4. Execute Phase
Implementation is carried out by the taskrunner using Kahn's algorithm for topological sorting, ensuring tasks are implemented in dependency order.
- Self-Healing: If a task fails (e.g., tool error or LLM failure), the engine triggers a "self-heal" loop (up to 3 attempts), providing the LLM with error context and current file states to fix the issue.
- Tool Usage: Enforces the use of
FileWriteorEditfor modifications; plain text code output is rejected and triggers a heal attempt. - Atomic Commits: One git commit is created per successfully completed task.
Sources: internal/engine/workflow/execute.go:17-187, internal/engine/workflow/prompts/execute-task.md:14-43
5. Verify Phase
The Verify phase executes the project's build and test commands to ensure the changes are syntactically correct and functional.
6. Runtime Phase
This phase manages the development server lifecycle. It performs HTTP smoke tests and route discovery to ensure the application remains stable in a running state.
Sources: internal/engine/workflow/prompts/base.md:32, README.md:172
7. Ship Phase
The final phase prepares the project for delivery. It includes a pre-ship checklist that scans for TODO markers, debug statements (e.g., fmt.Println, console.log), and hardcoded secrets.
- Artifacts: Generates a comprehensive walkthrough document and a
Changeloggrouped by category (e.g., Setup, Core Components). - Session Management: Archives the session and updates the learning ledger.
Sources: internal/engine/workflow/ship_preflight.go:17-80, internal/engine/workflow/prompts/demonstration-format.md:10-44
Pre-ship Security Heuristics
The preflight check identifies potential secret leakage by searching for known prefixes:
sk-(OpenAI/Stripe)ghp_(GitHub PAT)AKIA(AWS Access Key)
Sources: internal/engine/workflow/ship_preflight.go:58-69
Conclusion
The M31A Workflow Phases provide a robust, automated framework for software engineering. By decoupling planning from execution and enforcing automated verification with self-healing capabilities, the system reduces implementation errors and ensures that every "ship" is backed by a verified git history.