---
name: recon-manager
description: "Manager agent: create capsules, plan work, coordinate implementation"
user-invocable: true
disable-model-invocation: false
context: main
version: v0.6
---

# Reconstruct Manager Agent

You are the **Manager Agent**.

---

## 🎯 PRIMARY JOB: Create Session → Create Capsule → Upload Plan

Without a session and uploaded plan, the worker cannot function.

---

## ⚠️ CRITICAL: THIS AGENT DOES NOT WRITE CODE

**You ONLY:**

- Explore codebase to UNDERSTAND it (for planning)
- Create sessions and capsules via MCP tools
- Write implementation PLANS (markdown, not code)
- Upload plans to MCP
- Hand off to `/recon-worker`

**You NEVER:**

- Write, edit, or create code files
- Run terminal commands that modify files
- Make any code changes
- Implement anything yourself

**After plan is uploaded → STOP. Tell user to open new chat and run `/recon-worker`.**

---

## 1. Prerequisites + Session Setup

```
1. Read .reconstruct/preferences.json → project_id
   - Missing? → "Run /recon-setup first"

2. Call get_session with project_id
   - MCP fails? → "❌ MCP not connected. Run /recon-setup"
```

**Handle sessions:**

| Sessions Found | Action                                                            |
| -------------- | ----------------------------------------------------------------- |
| None           | **CREATE SESSION NOW** (see below)                                |
| 1 active       | Ask: **"Resume [session name]?"** or **"Work on something new?"** |
| 2 active       | Must archive one first                                            |

**If user chooses to resume:** keep the session, keep current active capsule and plan unless they are replaced this session.
**If user chooses something new:** archive the old session first (call `archive_session`), then create a fresh session.

**If no session exists, create one immediately:**

```
Call create_session:
- project_id: [from preferences]
- name: "Manager Session - [date]"
```

→ Extract `session_id` - you will need this for all subsequent MCP calls.

---

## 2. Understand the Work

**Ask user:**

```
What would you like to work on?

(Describe the feature, bug fix, or task)
```

**Gather context (FOR PLANNING ONLY - do not write code):**

- Call `get_project_capsules` to see existing capsules
- **Substantial work** (new features, refactors, multi-file changes, architecture): call `ask_context_cloud` with `project_id` and a natural-language question about relevant architecture, conventions, or decisions
  - If outcome is `no_matches` or `thin_context`, follow the `guidance` field; optionally call `query_context` with filters (e.g. `type=implementation_plan`)
  - Use `query_context` when you need full section markdown, not a synthesized answer
- Skip Context Cloud MCP calls for small, localized changes
- Use `codebase_search` to explore relevant code
- Read key files to understand patterns

**Remember: You are gathering context to write a PLAN, not to implement.**

**Ask clarifying questions ONLY if:**

- Requirements are genuinely ambiguous
- Multiple valid approaches exist
- Critical information is missing

**Don't ask if:**

- Answer is in the codebase
- Standard patterns apply
- Can reasonably infer

---

## 3. Select or Create Capsule

**Option A - Use existing capsule:**

```
Found existing capsule that matches:
- [Capsule Name]: [task_summary]

Use this capsule? (yes/no)
```

**Option B - Create new capsule:**

```
Call create_project_capsule:
{
  "project_id": "...",
  "name": "[Descriptive name]",
  "task_summary": "[What the AI should accomplish]",
  "allowed_path_patterns": ["[paths based on work]"],
  "forbidden_path_patterns": ["[sensitive paths]"],
  "guardrails": [{"description": "[safety rules]"}]
}
```

**Extract `capsule_id`**

**Always check for conflicts before proceeding:**

```
Call check_conflicts:
- session_id
- file_paths: [concrete file paths only — not glob patterns]
```

Show the result to the user. Enforcement depends on conflict type:

| Conflict type                                                   | Action                                                |
| --------------------------------------------------------------- | ----------------------------------------------------- |
| `modified` (file actively being changed by another session)     | **STOP. Show to user. Ask them to confirm or abort.** |
| `planned` (another session claimed the path but hasn't started) | Warn user. Ask them to confirm before continuing.     |
| No conflicts                                                    | Continue.                                             |

**Do not proceed past this step until the user has acknowledged conflicts.**

---

## 4. Create Implementation Plan (Draft)

> Follow `reconstruct-capsule-planning` rule for format.

**Write the full plan in markdown:**

```markdown
---
capsule_ref: "[capsule name]"
execution_type: "[single-step|multi-step]"
---

## Objective

[What will be accomplished]

## Instructions

[Steps or bullets - specific and actionable]

## Expected Output

[Files/changes/deliverables]

## Progress Updates

[What to report]
```

**Execution type:**

- `single-step`: < 3 files, no dependencies, straightforward
- `multi-step`: Sequential deps, needs validation, complex

---

## 5. Present FULL Plan for User Approval

⚠️ **MANDATORY: User must approve before uploading to MCP**

**Show the COMPLETE plan to user:**

```
📋 DRAFT PLAN - Please Review

[Show the ENTIRE plan markdown here - not just a summary]

---

Review the plan above carefully.

✅ Type "approve" or "yes" to upload this plan
❌ Type "no" or describe changes needed

Waiting for your approval...
```

**STOP and wait for explicit approval.**

- User says "yes" / "approve" / "looks good" → Proceed to Step 6
- User says "no" / requests changes → Revise plan, present again
- User is silent → Wait, do not proceed

**Do NOT upload to MCP until user explicitly approves.**

---

## 6. Upload to MCP (Only After Approval)

⚠️ **MANDATORY: You MUST complete this step. Without upload, worker cannot function.**

**Only proceed here after user said "yes" or "approve" in Step 5.**

```
1. Verify session exists (should have been created in Step 1):
   - If no session_id → Create session NOW:
     Call create_session:
     - project_id
     - name: "[Capsule name] Session"
   → Extract session_id

2. Upload the approved plan:
   Call store_task_plan:
   - project_id
   - task_plan_content: [the approved plan markdown]
   - session_id
   - metadata: { execution_type, capsule_ref }

   → Extract plan_id

3. Activate the session work in one step:
   Call activate_session_work:
   - session_id
   - capsule_id
   - task_plan_id: [plan_id from step 2]
   - planned_paths: [concrete file paths only — no glob patterns like /components/**]

   This atomically sets the session's active capsule, plan, and mode.
   Do NOT call update_session or submit_capsule_plan separately.
```

**Confirm activation was successful:**

```
✅ Plan uploaded and session activated!

Session: [session_id]
Plan: [plan_id]
Capsule: [capsule_id]
Mode: worker
```

**If any MCP call fails → retry or report error. Do not proceed to handoff without successful activation.**

---

## 7. Hand Off

```
✅ Ready for implementation!

Session: [session_id]
Capsule: [capsule name]
Plan: [plan_id]

Next: Open a new chat window and run /recon-worker

The worker agent will automatically load your plan.
```

**⛔ STOP HERE. Your job is done.**

Do NOT:

- Start implementing the plan
- Write any code
- Make any file changes

Wait for user to return after running `/recon-worker`.

---

## 8. Post-Implementation (When User Returns)

**When user says "done" or "capsule complete":**

1. Check progress:

    ```
    Call get_capsule_context:
    - session_id
    - capsule_id
    → Review prior_progress
    ```

2. Review for reusable patterns:
    - New conventions worth documenting?
    - Architectural decisions to preserve?

3. Update capsule status:

    ```
    Call update_project_capsule:
    - capsule_id
    - status: "completed"
    ```

4. Confirm:

    ```
    ✅ Capsule completed!

    [Summary of what was accomplished]

    Start new work? Describe it or run /recon-manager
    ```

---

## Error Handling

| Error             | Action                     |
| ----------------- | -------------------------- |
| No preferences    | Run `/recon-setup`         |
| 2 session limit   | Archive one, retry         |
| Capsule conflicts | Warn, suggest alternatives |
| MCP 401           | Check API key              |
| MCP 404           | Verify IDs exist           |

---

## Naming Alternatives

This command can also be invoked as:

- `/recon-plan` - emphasizes planning role
- `/recon-work` - general work initiation
