Explore the megaplan repository at /Users/user_c042661f/Documents/megaplan. I need to understand:
The overall file structure (main modules, entry points)
How the current pipeline works (plan → execute → review flow)
Key files: megaplan.sh, any Python modules, prompt templates, config files
How steps are currently executed and reviewed
What "modes" or step types currently exist
Focus on src/ or the main code directory. Be thorough but skip .megaplan/ artifacts, docs/, and ops/ unless they contain core code. Report file paths and line numbers for [REDACTED]
Assistant
I'll explore the megaplan repository systematically. Let me start with the top-level structure and key files in parallel.
Assistant
Now let me read the core handlers, execution, and the _core module.
Assistant
I now have a thorough understanding of the codebase. Here is the complete report:
Megaplan Repository: Architecture Report
1. Overall File Structure
The project is a Python package at /Users/user_c042661f/Documents/megaplan/megaplan/ with the following top-level layout:
The pipeline is a typed state machine defined in /Users/user_c042661f/Documents/megaplan/megaplan/_core/workflow.py (line 31). States are constants in /Users/user_c042661f/Documents/megaplan/megaplan/types.py (lines 12–21).
Standard (default): skips prep — starts with plan directly.
Light: skips prep, skips gate, collapses revise → gated in one step, skips review.
Tiny: stubs out critique and gate entirely, jumps straight to gated.
The review step can cycle back: if review_verdict == "needs_rework", the state returns to finalized and execute runs again (up to max_review_rework_cycles, default 3).
/Users/user_c042661f/Documents/megaplan/megaplan/handlers.py:1337 — handle_execute() — dispatches to dispatch_execute_one_batch or dispatch_execute_auto_loop
Config stored in ~/.megaplan/config.json (not a repo file), loaded via _core/io.py
/Users/user_c042661f/Documents/megaplan/megaplan/types.py:298 — DEFAULTS dict (all configurable settings with defaults)
/Users/user_c042661f/Documents/megaplan/megaplan/types.py:267 — DEFAULT_AGENT_ROUTING (which agent handles each step)
Schemas:
/Users/user_c042661f/Documents/megaplan/megaplan/schemas.py — SCHEMAS dict with JSON schemas for plan.json, prep.json, revise.json, gate.json, critique.json, finalize.json, execution.json, loop_plan.json, loop_execute.json, review.json
4. How Steps Are Executed and Reviewed
Execution (execute step):
Requires --confirm-destructive flag and either auto_approve=True in config or --user-approved CLI flag (line 1340–1350 in handlers.py)
finalize.json is pre-split into dependency-ordered batches via compute_global_batches() / compute_task_batches()
Each batch is sent to the agent (codex by default) as an _execute_batch_prompt
After each batch, _validate_and_merge_batch() writes task statuses back to finalize.json
Quality audit: _observe_git_changes(), _check_done_task_evidence(), _collect_quality_deviations() run between batches
Session continuity: codex uses codex exec resume <session_id> for persistent sessions; --fresh forces a new session
Review (review step):
Mechanical pre-checks run first (run_pre_checks() in review_mechanical.py) for robustness ≥ standard
For superrobust, parallel review via run_parallel_review() (hermes splits checks)
The agent produces review.json with review_verdict = "approved" or "needs_rework"
_merge_review_verdicts() writes reviewer_verdict and evidence_files back into finalize.json for each task and sense check
If needs_rework, _resolve_review_outcome() decides whether to cycle back to finalized (re-execute) or block if coverage is incomplete
Review cycles are capped by max_review_rework_cycles (default 3) and max_robust_review_rework_cycles (default 2)
Auto-driver (megaplan auto):
/Users/user_c042661f/Documents/megaplan/megaplan/auto.py — shells out megaplan <step> in a loop, handles ESCALATE (default: force-proceed), and bails on stalls (default 5 consecutive same-state iterations)