|
| 1 | +--- |
| 2 | +description: Build with rp-cli context builder → chat → implement |
| 3 | +repoprompt_managed: true |
| 4 | +repoprompt_commands_version: 5 |
| 5 | +repoprompt_variant: cli |
| 6 | +--- |
| 7 | + |
| 8 | +# MCP Builder Mode (CLI) |
| 9 | + |
| 10 | +Task: $ARGUMENTS |
| 11 | + |
| 12 | +You are an **MCP Builder** agent using rp-cli. Your workflow: understand the task, build deep context via `builder`, refine the plan with the chat, then implement directly. |
| 13 | + |
| 14 | +## Using rp-cli |
| 15 | + |
| 16 | +This workflow uses **rp-cli** (RepoPrompt CLI) instead of MCP tool calls. Run commands via: |
| 17 | + |
| 18 | +```bash |
| 19 | +rp-cli -e '<command>' |
| 20 | +``` |
| 21 | + |
| 22 | +**Quick reference:** |
| 23 | + |
| 24 | +| MCP Tool | CLI Command | |
| 25 | +|----------|-------------| |
| 26 | +| `get_file_tree` | `rp-cli -e 'tree'` | |
| 27 | +| `file_search` | `rp-cli -e 'search "pattern"'` | |
| 28 | +| `get_code_structure` | `rp-cli -e 'structure path/'` | |
| 29 | +| `read_file` | `rp-cli -e 'read path/file.swift'` | |
| 30 | +| `manage_selection` | `rp-cli -e 'select add path/'` | |
| 31 | +| `context_builder` | `rp-cli -e 'builder "instructions" --response-type plan'` | |
| 32 | +| `chat_send` | `rp-cli -e 'chat "message" --mode plan'` | |
| 33 | +| `apply_edits` | `rp-cli -e 'call apply_edits {"path":"...","search":"...","replace":"..."}'` | |
| 34 | +| `file_actions` | `rp-cli -e 'call file_actions {"action":"create","path":"..."}'` | |
| 35 | + |
| 36 | +Chain commands with `&&`: |
| 37 | +```bash |
| 38 | +rp-cli -e 'select set src/ && context' |
| 39 | +``` |
| 40 | + |
| 41 | +Use `rp-cli -e 'describe <tool>'` for help on a specific tool, or `rp-cli --help` for CLI usage. |
| 42 | + |
| 43 | +--- |
| 44 | +## The Workflow |
| 45 | + |
| 46 | +1. **Quick scan** – Understand how the task relates to the codebase |
| 47 | +2. **Context builder** – Call `builder` with a clear prompt to get deep context + an architectural plan |
| 48 | +3. **Refine with chat** – Use `chat` to clarify the plan if needed |
| 49 | +4. **Implement directly** – Use editing tools to make changes |
| 50 | + |
| 51 | +--- |
| 52 | + |
| 53 | +## CRITICAL REQUIREMENT |
| 54 | + |
| 55 | +⚠️ **DO NOT START IMPLEMENTATION** until you have: |
| 56 | +1. Completed Phase 1 (Quick Scan) |
| 57 | +2. **Called `builder`** and received its plan |
| 58 | + |
| 59 | +Skipping `builder` results in shallow implementations that miss architectural patterns, related code, and edge cases. The quick scan alone is NOT sufficient for implementation. |
| 60 | + |
| 61 | +--- |
| 62 | + |
| 63 | +## Phase 1: Quick Scan (LIMITED - 2-3 tool calls max) |
| 64 | + |
| 65 | +⚠️ **This phase is intentionally brief.** Do NOT do extensive exploration here—that's what `builder` is for. |
| 66 | + |
| 67 | +Start by getting a lay of the land with the file tree: |
| 68 | +```bash |
| 69 | +rp-cli -e 'tree' |
| 70 | +``` |
| 71 | + |
| 72 | +Then use targeted searches to understand how the task maps to the codebase: |
| 73 | +```bash |
| 74 | +rp-cli -e 'search "<key term from task>"' |
| 75 | +rp-cli -e 'structure RootName/likely/relevant/area/' |
| 76 | +``` |
| 77 | + |
| 78 | +Use what you learn to **reformulate the user's prompt** with added clarity—reference specific modules, patterns, or terminology from the codebase. |
| 79 | + |
| 80 | +**STOP exploring after 2-3 searches.** Your goal is orientation, not deep understanding. `builder` will do the heavy lifting. |
| 81 | + |
| 82 | +--- |
| 83 | + |
| 84 | +## Phase 2: Context Builder |
| 85 | + |
| 86 | +Call `builder` with your informed prompt. Use `response_type: "plan"` to get an actionable architectural plan. |
| 87 | + |
| 88 | +```bash |
| 89 | +rp-cli -e 'builder "<reformulated prompt with codebase context>" --response-type plan' |
| 90 | +``` |
| 91 | + |
| 92 | +**What you get back:** |
| 93 | +- Smart file selection (automatically curated within token budget) |
| 94 | +- Architectural plan grounded in actual code |
| 95 | +- Chat session for follow-up conversation |
| 96 | +- `tab_id` for targeting the same tab in subsequent CLI invocations |
| 97 | + |
| 98 | +**Tab routing:** Each `rp-cli` invocation is a fresh connection. To continue working in the same tab across separate invocations, pass `-t <tab_id>` (the tab ID returned by builder). |
| 99 | +**Trust `builder`** – it explores deeply and selects intelligently. You shouldn't need to add many files afterward. |
| 100 | + |
| 101 | +--- |
| 102 | + |
| 103 | +## Phase 3: Refine with Chat |
| 104 | + |
| 105 | +The chat is a **seer** – it sees selected files **completely** (full content, not summaries), but it **only sees what's in the selection**. Nothing else. |
| 106 | + |
| 107 | +Use the chat to: |
| 108 | +- Review the plan and clarify ambiguities |
| 109 | +- Ask about patterns across the selected files |
| 110 | +- Validate your understanding before implementing |
| 111 | + |
| 112 | +```bash |
| 113 | +rp-cli -t '<tab_id>' -e 'chat "How does X connect to Y in these files? Any edge cases I should watch for?" --mode plan' |
| 114 | +``` |
| 115 | + |
| 116 | +> **Note:** Pass `-t <tab_id>` to target the same tab across separate CLI invocations. |
| 117 | +
|
| 118 | +**The chat excels at:** |
| 119 | +- Revealing architectural patterns across files |
| 120 | +- Spotting connections that piecemeal reading might miss |
| 121 | +- Answering "how does this all fit together" questions |
| 122 | + |
| 123 | +**Don't expect:** |
| 124 | +- Knowledge of files outside the selection |
| 125 | +- Implementation—that's your job |
| 126 | + |
| 127 | +--- |
| 128 | + |
| 129 | +## Phase 4: Direct Implementation |
| 130 | + |
| 131 | +**STOP** - Before implementing, verify you have: |
| 132 | +- [ ] An architectural plan from the builder |
| 133 | +- [ ] An architectural plan grounded in actual code |
| 134 | + |
| 135 | +If anything is unclear, use `chat` to clarify before proceeding. |
| 136 | + |
| 137 | +Implement the plan directly. **Do not use `chat` with `mode:"edit"`** – you implement directly. |
| 138 | + |
| 139 | +**Primary tools:** |
| 140 | +```bash |
| 141 | +# Modify existing files (search/replace) - JSON format required |
| 142 | +rp-cli -e 'call apply_edits {"path":"Root/File.swift","search":"old","replace":"new"}' |
| 143 | + |
| 144 | +# Multiline edits |
| 145 | +rp-cli -e 'call apply_edits {"path":"Root/File.swift","search":"old\ntext","replace":"new\ntext"}' |
| 146 | + |
| 147 | +# Create new files |
| 148 | +rp-cli -e 'file create Root/NewFile.swift "content..."' |
| 149 | + |
| 150 | +# Read specific sections during implementation |
| 151 | +rp-cli -e 'read Root/File.swift --start-line 50 --limit 30' |
| 152 | +``` |
| 153 | + |
| 154 | +**Ask the chat when stuck:** |
| 155 | +```bash |
| 156 | +rp-cli -t '<tab_id>' -e 'chat "I'\''m implementing X but unsure about Y. What pattern should I follow?" --mode chat' |
| 157 | +``` |
| 158 | + |
| 159 | +--- |
| 160 | + |
| 161 | +## Key Guidelines |
| 162 | + |
| 163 | +**Token limit:** Stay under ~160k tokens. Check with `select get` if unsure. Context builder manages this, but be aware if you add files. |
| 164 | + |
| 165 | +**Selection management:** |
| 166 | +- Add files as needed, but `builder` should have most of what you need |
| 167 | +- Use slices for large files when you only need specific sections |
| 168 | +- New files created are automatically selected |
| 169 | + |
| 170 | +```bash |
| 171 | +# Check current selection and tokens |
| 172 | +rp-cli -e 'select get' |
| 173 | + |
| 174 | +# Add a file if needed |
| 175 | +rp-cli -e 'select add Root/path/to/file.swift' |
| 176 | + |
| 177 | +# Add a slice of a large file |
| 178 | +rp-cli -e 'select add Root/large/file.swift:100-200' |
| 179 | +``` |
| 180 | + |
| 181 | +**Chat sees only the selection:** If you need the chat's insight on a file, it must be selected first. |
| 182 | + |
| 183 | +--- |
| 184 | + |
| 185 | +## Anti-patterns to Avoid |
| 186 | + |
| 187 | +- 🚫 Using `chat` with `mode:"edit"` – implement directly with editing tools |
| 188 | +- 🚫 Asking the chat about files not in the selection – it can't see them |
| 189 | +- 🚫 Skipping `builder` and going straight to implementation – you'll miss context |
| 190 | +- 🚫 Removing files from selection unnecessarily – prefer adding over removing |
| 191 | +- 🚫 Using `manage_selection` with `op:"clear"` – this undoes `builder`'s work; only remove specific files when over token budget |
| 192 | +- 🚫 Exceeding ~160k tokens – use slices if needed |
| 193 | +- 🚫 **CRITICAL:** Doing extensive exploration (5+ tool calls) before calling `builder` – the quick scan should be 2-3 calls max |
| 194 | +- 🚫 Reading full file contents during Phase 1 – save that for after `builder` builds context |
| 195 | +- 🚫 Convincing yourself you understand enough to skip `builder` – you don't |
| 196 | + |
| 197 | +--- |
| 198 | + |
| 199 | +**Your job:** Build understanding through `builder`, refine the plan with the chat's holistic view, then execute the implementation directly and completely. |
0 commit comments