mapcoder
Scannednpx machina-cli add skill NewJerseyStyle/plugin-map-coder/mapcoder --openclawMapCoder: Multi-Agent Code Generation Pipeline
You are orchestrating the MapCoder pipeline, a multi-agent system that replicates the human programming cycle through four specialized agents:
- Retrieval Agent - Generates similar problems from knowledge
- Planning Agent - Creates step-by-step algorithmic plans
- Coding Agent - Translates plans into executable code
- Debugging Agent - Fixes bugs using plans and test feedback
Argument Parsing
Parse $ARGUMENTS to extract:
--lang <language>: Target programming language (default: Python)--sandbox: Use Docker sandbox for code execution (safer)- Remaining text: The problem description or file path
Example inputs:
/mapcoder implement binary search→ Python, direct execution/mapcoder --lang javascript implement binary search→ JavaScript/mapcoder --sandbox --lang rust implement linked list→ Rust, sandboxed
Pipeline Execution
Step 1: Problem Analysis
First, analyze the input:
- If it's a file path, read the file to get the problem description
- Extract any sample test cases from the problem
- Identify the target language from arguments (default: Python)
Step 2: Retrieval Phase
Use the Task tool to spawn the retrieval agent:
Spawn a retrieval agent to generate 3-5 similar problems for:
[problem description]
The agent should return:
- Similar problem descriptions
- Solution patterns/approaches used
- Key algorithmic concepts
Use subagent_type: "general-purpose" with the retrieval-agent.md system prompt.
Step 3: Planning Phase
Use the Task tool to spawn the planning agent with the retrieved examples:
Spawn a planning agent to create step-by-step plans for:
[problem description]
Using these similar problems as reference:
[retrieved examples]
Generate 2-3 alternative algorithmic plans.
Step 4: Coding Phase
Use the Task tool to spawn the coding agent:
Spawn a coding agent to implement the solution in [language]:
[problem description]
Following this plan:
[selected plan]
Test against these sample cases:
[test cases]
If --sandbox flag is set, instruct the agent to use scripts/sandbox-runner.sh instead of direct execution.
Step 5: Validation Loop
After coding completes:
If tests pass: Return the solution with explanation.
If tests fail: Enter debugging loop (max 3 iterations):
Spawn a debugging agent to fix the failing code:
Original problem: [problem]
Current code: [code]
Error output: [errors]
Original plan: [plan]
Identify the bug and generate corrected code.
Step 6: Solution Output
When successful, output using the solution template:
## Solution
**Language**: [language]
**Status**: [Passed/Failed after N attempts]
### Code
[final code]
### Explanation
[step-by-step explanation of the approach]
### Test Results
[test output]
Adaptive Traversal
The pipeline supports adaptive routing:
- If retrieval produces highly relevant examples → use single best plan
- If planning produces uncertain results → try multiple plans in parallel
- If debugging fails 3 times → try alternative plan from Step 3
- If all plans exhausted → report failure with analysis
Configuration
- MAX_DEBUG_ITERATIONS: 3
- MAX_PLAN_ATTEMPTS: 3
- DEFAULT_LANGUAGE: Python
Error Handling
- If any agent fails to spawn, report the error and suggest manual intervention
- If code execution times out, treat as test failure and enter debugging
- If problem is ambiguous, ask user for clarification before proceeding
Source
git clone https://github.com/NewJerseyStyle/plugin-map-coder/blob/main/skills/mapcoder/SKILL.mdView on GitHub Overview
MapCoder orchestrates a four-agent pipeline (Retrieval, Planning, Coding, Debugging) to tackle coding problems. It’s designed for algorithmic challenges, feature implementation from specs, or iterative refinement, helping developers move from idea to tested code faster.
How This Skill Works
MapCoder analyzes the input problem, determines the target language (default Python), and runs through a sequence of specialized agents: Retrieval to surface similar problems, Planning to craft step-by-step algorithms, Coding to implement the solution, and Debugging to fix issues based on test feedback. It supports --lang and --sandbox arguments, uses a sandbox for safe execution when requested, and loops through validation until tests pass or the maximum debug iterations are reached.
When to Use It
- Solving algorithmic problems that require a clear, testable plan.
- Implementing features from a detailed specification or API contract.
- Code needs iterative refinement based on test results or feedback.
- Learning from similar problems to apply proven patterns and approaches.
- Debugging challenging code with structured, plan-driven fixes.
Quick Start
- Step 1: Provide the problem description and optional flags (e.g., --lang Python).
- Step 2: Run MapCoder to perform retrieval, planning, coding, and debugging.
- Step 3: Review the generated solution and run tests; iterate if needed.
Best Practices
- Clearly present the problem description, constraints, and sample tests.
- Specify the target language up front with --lang and opt into sandbox if needed.
- Review retrieved examples to ensure relevance before crafting plans.
- Document the chosen plan and validate it against representative cases.
- Limit debug iterations (MAX_DEBUG_ITERATIONS) and summarize fixes after each pass.
Example Use Cases
- Implement binary search using a plan-driven approach and test cases.
- Translate a feature specification into robust API functions with unit tests.
- Refactor a complex function by iteratively refining with debugging feedback.
- Solve a graph or DP problem by decomposing into retrieval-backed patterns.
- Fix a memory leak in a Python module via a sequence of plan-guided edits.