Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
199 changes: 199 additions & 0 deletions .claude/commands/rp-build-cli.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
---
description: Build with rp-cli context builder → chat → implement
repoprompt_managed: true
repoprompt_commands_version: 5
repoprompt_variant: cli
---

# MCP Builder Mode (CLI)

Task: $ARGUMENTS

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.

## Using rp-cli

This workflow uses **rp-cli** (RepoPrompt CLI) instead of MCP tool calls. Run commands via:

```bash
rp-cli -e '<command>'
```

**Quick reference:**

| MCP Tool | CLI Command |
|----------|-------------|
| `get_file_tree` | `rp-cli -e 'tree'` |
| `file_search` | `rp-cli -e 'search "pattern"'` |
| `get_code_structure` | `rp-cli -e 'structure path/'` |
| `read_file` | `rp-cli -e 'read path/file.swift'` |
| `manage_selection` | `rp-cli -e 'select add path/'` |
| `context_builder` | `rp-cli -e 'builder "instructions" --response-type plan'` |
| `chat_send` | `rp-cli -e 'chat "message" --mode plan'` |
| `apply_edits` | `rp-cli -e 'call apply_edits {"path":"...","search":"...","replace":"..."}'` |
| `file_actions` | `rp-cli -e 'call file_actions {"action":"create","path":"..."}'` |

Chain commands with `&&`:
```bash
rp-cli -e 'select set src/ && context'
```

Use `rp-cli -e 'describe <tool>'` for help on a specific tool, or `rp-cli --help` for CLI usage.

---
## The Workflow

1. **Quick scan** – Understand how the task relates to the codebase
2. **Context builder** – Call `builder` with a clear prompt to get deep context + an architectural plan
3. **Refine with chat** – Use `chat` to clarify the plan if needed
4. **Implement directly** – Use editing tools to make changes

---

## CRITICAL REQUIREMENT

⚠️ **DO NOT START IMPLEMENTATION** until you have:
1. Completed Phase 1 (Quick Scan)
2. **Called `builder`** and received its plan

Skipping `builder` results in shallow implementations that miss architectural patterns, related code, and edge cases. The quick scan alone is NOT sufficient for implementation.

---

## Phase 1: Quick Scan (LIMITED - 2-3 tool calls max)

⚠️ **This phase is intentionally brief.** Do NOT do extensive exploration here—that's what `builder` is for.

Start by getting a lay of the land with the file tree:
```bash
rp-cli -e 'tree'
```

Then use targeted searches to understand how the task maps to the codebase:
```bash
rp-cli -e 'search "<key term from task>"'
rp-cli -e 'structure RootName/likely/relevant/area/'
```

Use what you learn to **reformulate the user's prompt** with added clarity—reference specific modules, patterns, or terminology from the codebase.

**STOP exploring after 2-3 searches.** Your goal is orientation, not deep understanding. `builder` will do the heavy lifting.

---

## Phase 2: Context Builder

Call `builder` with your informed prompt. Use `response_type: "plan"` to get an actionable architectural plan.

```bash
rp-cli -e 'builder "<reformulated prompt with codebase context>" --response-type plan'
```

**What you get back:**
- Smart file selection (automatically curated within token budget)
- Architectural plan grounded in actual code
- Chat session for follow-up conversation
- `tab_id` for targeting the same tab in subsequent CLI invocations

**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).
**Trust `builder`** – it explores deeply and selects intelligently. You shouldn't need to add many files afterward.

---

## Phase 3: Refine with Chat

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.

Use the chat to:
- Review the plan and clarify ambiguities
- Ask about patterns across the selected files
- Validate your understanding before implementing

```bash
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'
```

> **Note:** Pass `-t <tab_id>` to target the same tab across separate CLI invocations.

**The chat excels at:**
- Revealing architectural patterns across files
- Spotting connections that piecemeal reading might miss
- Answering "how does this all fit together" questions

**Don't expect:**
- Knowledge of files outside the selection
- Implementation—that's your job

---

## Phase 4: Direct Implementation

**STOP** - Before implementing, verify you have:
- [ ] An architectural plan from the builder
- [ ] An architectural plan grounded in actual code

If anything is unclear, use `chat` to clarify before proceeding.

Implement the plan directly. **Do not use `chat` with `mode:"edit"`** – you implement directly.

**Primary tools:**
```bash
# Modify existing files (search/replace) - JSON format required
rp-cli -e 'call apply_edits {"path":"Root/File.swift","search":"old","replace":"new"}'

# Multiline edits
rp-cli -e 'call apply_edits {"path":"Root/File.swift","search":"old\ntext","replace":"new\ntext"}'

# Create new files
rp-cli -e 'file create Root/NewFile.swift "content..."'

# Read specific sections during implementation
rp-cli -e 'read Root/File.swift --start-line 50 --limit 30'
```

**Ask the chat when stuck:**
```bash
rp-cli -t '<tab_id>' -e 'chat "I'\''m implementing X but unsure about Y. What pattern should I follow?" --mode chat'
```

---

## Key Guidelines

**Token limit:** Stay under ~160k tokens. Check with `select get` if unsure. Context builder manages this, but be aware if you add files.

**Selection management:**
- Add files as needed, but `builder` should have most of what you need
- Use slices for large files when you only need specific sections
- New files created are automatically selected

```bash
# Check current selection and tokens
rp-cli -e 'select get'

# Add a file if needed
rp-cli -e 'select add Root/path/to/file.swift'

# Add a slice of a large file
rp-cli -e 'select add Root/large/file.swift:100-200'
```

**Chat sees only the selection:** If you need the chat's insight on a file, it must be selected first.

---

## Anti-patterns to Avoid

- 🚫 Using `chat` with `mode:"edit"` – implement directly with editing tools
- 🚫 Asking the chat about files not in the selection – it can't see them
- 🚫 Skipping `builder` and going straight to implementation – you'll miss context
- 🚫 Removing files from selection unnecessarily – prefer adding over removing
- 🚫 Using `manage_selection` with `op:"clear"` – this undoes `builder`'s work; only remove specific files when over token budget
- 🚫 Exceeding ~160k tokens – use slices if needed
- 🚫 **CRITICAL:** Doing extensive exploration (5+ tool calls) before calling `builder` – the quick scan should be 2-3 calls max
- 🚫 Reading full file contents during Phase 1 – save that for after `builder` builds context
- 🚫 Convincing yourself you understand enough to skip `builder` – you don't

---

**Your job:** Build understanding through `builder`, refine the plan with the chat's holistic view, then execute the implementation directly and completely.
167 changes: 167 additions & 0 deletions .claude/commands/rp-investigate-cli.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
---
description: Deep codebase investigation and architecture research with rp-cli commands
repoprompt_managed: true
repoprompt_commands_version: 5
repoprompt_variant: cli
---

# Deep Investigation Mode (CLI)

Investigate: $ARGUMENTS

You are now in deep investigation mode for the issue described above. Follow this protocol rigorously.

## Using rp-cli

This workflow uses **rp-cli** (RepoPrompt CLI) instead of MCP tool calls. Run commands via:

```bash
rp-cli -e '<command>'
```

**Quick reference:**

| MCP Tool | CLI Command |
|----------|-------------|
| `get_file_tree` | `rp-cli -e 'tree'` |
| `file_search` | `rp-cli -e 'search "pattern"'` |
| `get_code_structure` | `rp-cli -e 'structure path/'` |
| `read_file` | `rp-cli -e 'read path/file.swift'` |
| `manage_selection` | `rp-cli -e 'select add path/'` |
| `context_builder` | `rp-cli -e 'builder "instructions" --response-type plan'` |
| `chat_send` | `rp-cli -e 'chat "message" --mode plan'` |
| `apply_edits` | `rp-cli -e 'call apply_edits {"path":"...","search":"...","replace":"..."}'` |
| `file_actions` | `rp-cli -e 'call file_actions {"action":"create","path":"..."}'` |

Chain commands with `&&`:
```bash
rp-cli -e 'select set src/ && context'
```

Use `rp-cli -e 'describe <tool>'` for help on a specific tool, or `rp-cli --help` for CLI usage.

---
## Investigation Protocol

### Core Principles
1. **Don't stop until confident** - pursue every lead until you have solid evidence
2. **Document findings as you go** - create/update a report file with observations
3. **Question everything** - if something seems off, investigate it
4. **Use `builder` aggressively** - it's designed for deep exploration

### Phase 1: Initial Assessment

1. Read any provided files/reports (traces, logs, error reports)
2. Summarize the symptoms and constraints
3. Form initial hypotheses

### Phase 2: Systematic Exploration (via `builder` - REQUIRED)

⚠️ **Do NOT skip this step.** You MUST call `builder` to get proper context before drawing conclusions.

Use `builder` with detailed instructions:

```bash
rp-cli -e 'builder "Investigate: <specific area>

Symptoms observed:
- <symptom 1>
- <symptom 2>

Hypotheses to test:
- <theory 1>
- <theory 2>

Areas to explore:
- <files/patterns/subsystems>
" --response-type plan'
```

### Phase 3: Follow-up Deep Dives

After `builder` returns, continue with targeted questions:

```bash
rp-cli -t '<tab_id>' -e 'chat "<specific follow-up based on findings>" --mode plan'
```

> Pass `-t <tab_id>` to target the same tab across separate CLI invocations.

### Phase 4: Evidence Gathering

- Check git history for recent relevant changes
- Look for patterns across similar files
- Trace data/control flow through the codebase
- Identify any leaks, retained references, or improper cleanup

### Phase 5: Conclusions

Document:
- Root cause identification (with evidence)
- Eliminated hypotheses (and why)
- Recommended fixes
- Preventive measures for the future

---

## Context Builder Tips

The `builder` operates in two phases:
1. **Discovery**: Intelligently explores the codebase
2. **Analysis**: A capable model analyzes the captured context

**Give it good guidance:**
- Be specific about what parts of the codebase to investigate
- Describe symptoms precisely
- List specific technical questions to answer
- Mention any relevant constraints or context

---

## Report Template

Create a findings report as you investigate:

```markdown
# Investigation: [Title]

## Summary
[1-2 sentence summary of findings]

## Symptoms
- [Observed symptom 1]
- [Observed symptom 2]

## Investigation Log

### [Timestamp/Phase] - [Area Investigated]
**Hypothesis:** [What you were testing]
**Findings:** [What you found]
**Evidence:** [File:line references]
**Conclusion:** [Confirmed/Eliminated/Needs more investigation]

## Root Cause
[Detailed explanation with evidence]

## Recommendations
1. [Fix 1]
2. [Fix 2]

## Preventive Measures
- [How to prevent this in future]
```

---

## Anti-patterns to Avoid

- 🚫 **CRITICAL:** Skipping `builder` and attempting to investigate by reading files manually – you'll miss critical context
- 🚫 Doing extensive exploration (5+ tool calls) before calling `builder` – initial assessment should be brief
- 🚫 Drawing conclusions before `builder` has built proper context
- 🚫 Reading many full files during Phase 1 – save deep reading for after `builder`
- 🚫 Assuming you understand the issue without systematic exploration via `builder`
- 🚫 Using only chat follow-ups without an initial `builder` call

---

Now begin the investigation. Read any provided context, then **immediately** use `builder` to start systematic exploration. Do not attempt manual exploration first.
Loading
Loading