### The "Escalation & Handoff" Protocol

This protocol is a two-part process: first, you instruct the local agent to generate a "Damage Report," and second, you use that report to brief the Orchestrator.

### Part 1: The "Damage Report" Meta-Prompt (For the Local IDE Agent)

This is the reusable prompt you'll use to command the failing local agent to summarize its own failure. It's designed to be a direct, no-nonsense command.

> **Prompt for Local IDE Agent: Generate an Escalation Handoff Report**
>
> **Objective:**
> You are to cease your current task and generate a detailed "Escalation Handoff Report." I, the user, have determined that your current approach is not solving the problem, and I need to escalate this issue to a senior AI Orchestrator for a new strategy.
>
> Your task is to provide a concise, factual summary of the situation to give the Orchestrator immediate context.
>
> **Instructions:**
> First, ensure you have undone any recent, uncommitted code changes related to this failed attempt. Then, generate a report in Markdown with the following sections:
>
> 1.  **Original Goal:**
>     *   State the original task or GitHub Issue I asked you to work on. (e.g., "Implement the 'RAG from Folder' feature.")
>
> 2.  **Observed Failure / Error:**
>     *   Provide the full, exact error message, traceback, or a clear description of the incorrect behavior you were producing.
>     *   (e.g., `AttributeError: 'NoneType' object has no attribute 'search'`, or "The UI button is created but does not respond to clicks.")
>
> 3.  **Your (Failed) Approach:**
>     *   Briefly summarize the implementation strategy you were attempting.
>     *   (e.g., "I was trying to add a new method to `hotkey_manager.py` that directly calls the `chromadb` library.")
>
> 4.  **Key Files Involved:**
>     *   Based on your attempt, create a bulleted list of the primary files you created or modified. This will be the list of files I need to provide to the Orchestrator.
>     *   (e.g.,
>         *   `src/hotkey_manager.py`
>         *   `src/ui/settings_window.py`
>         *   `src/rag_manager.py` (New File))
>
> 5.  **Your Best-Guess Diagnosis:**
>     *   In one or two sentences, state your best hypothesis for *why* your approach failed.
>     *   (e.g., "I believe the issue is a race condition, as the `chromadb` instance may not be fully initialized before the first query is attempted.")
>
> **Your Deliverable:**
> Provide only the complete Markdown report. Do not attempt to solve the problem further.

---

### Part 2: The "SOS" Prompt (For the AI Orchestrator)

Once the local agent has generated the "Escalation Handoff Report," you will use this second prompt to bring the Orchestrator up to speed.

> **Prompt for AI Orchestrator: Debugging Escalation & Strategic Reroute**
>
> **Objective:**
> We have encountered a critical bug during implementation that the local in-IDE agent was unable to solve. I have escalated the issue to you for a strategic review and a new plan of attack.
>
> Your task is to analyze the situation, diagnose the root cause, and provide a new, corrected "Plan-and-Solve" implementation plan.
>
> ---
>
> **Part 1: The Escalation Handoff Report**
> This report was generated by the local agent that failed the task. It contains the ground truth of the problem.
>
> ```markdown
> [[ PASTE THE ENTIRE MARKDOWN REPORT FROM THE LOCAL AI HERE ]]
> ```
>
> ---
>
> **Part 2: The Relevant Code**
> Here are the full contents of the files identified in the report.
>
> ```python
> # File: src/hotkey_manager.py
> [[ PASTE FULL CONTENT OF hotkey_manager.py HERE ]]
> ```
> ```python
> # File: src/ui/settings_window.py
> [[ PASTE FULL CONTENT OF settings_window.py HERE ]]
> ```
>
> *... (continue pasting the content of all files listed in the report) ...*
>
> ---
>
> **Part 3: Your Directive**
>
> 1.  **Analyze the Failure:** Based on the report and the provided code, give me a concise, one-paragraph diagnosis of the true root cause of the problem. Your high-level perspective may identify an architectural flaw the local agent missed.
> 2.  **Formulate a New Plan:** Generate a complete, corrected "Plan-and-Solve" implementation plan to fix the bug and achieve the original goal. This plan should detail the exact code changes needed in the provided files.

---

### Why This Protocol is So Effective:

*   **It Formalizes Failure:** It gives you a structured way to handle a common problem. Instead of getting frustrated, you're initiating a clear, logical protocol.
*   **Empowers the Local Agent:** It gives the failing agent one final, useful task: documenting its own failure. This is often more valuable than letting it try the same wrong thing again.
*   **Maximizes the Orchestrator's Strength:** The Orchestrator is a strategist. This protocol feeds it exactly what a strategist needs: a clear goal, a report of what failed, and the raw data (the code). It can then do what it does best: see the bigger picture and devise a better plan.

You've now designed a complete, end-to-end "Takomi" workflow, covering everything from project genesis to mid-project debugging escalations. This is an incredibly sophisticated and powerful way to work with multiple AI agents.