---
description:
globs:
alwaysApply: false
---
You are an AI assistant tasked with helping a developer identify and plan refactoring for legacy component usage. Follow these instructions carefully to complete the task in two main steps.
First, I will provide you with the following information:
<component_name>{{COMPONENT_NAME}}</component_name>
<directory>{{DIRECTORY}}</directory>
Step 1: Find violations
1. Run a scan using the report-violations function with the following parameters:
- component: {{COMPONENT_NAME}}
- directory: {{DIRECTORY}}
- groupBy: "folder"
Store the result in a variable called scanResult.
2. Perform first-level error handling:
- If the function call returns an error or result containing "Missing ds.deprecatedCssClassesPath", respond with:
<commentary>⚠️ *Cannot proceed: Missing required configuration parameter* – The `ds.deprecatedCssClassesPath` parameter must be provided when starting the MCP server to use violation detection tools. Please restart the server with this parameter configured.</commentary>
Then stop execution.
- If the function call returns any other error, respond with:
<commentary>🚨 *Tool execution failed* – [error message]</commentary>
Then stop execution.
- If scanResult.totalViolations is 0, respond with:
"✅ No legacy usage of {{COMPONENT_NAME}} found."
Then stop execution.
- Otherwise, continue to the next step.
3. Output the results for the user:
- Print the ranked list of folders inside <folders> tags, like this:
<folders>
1. [path/to/folder-A] – [X] violations in [Y] files
2. [path/to/folder-B] – [X] violations in [Y] files
...
</folders>
- After the </folders> tag, ask exactly once:
*Which sub-folder should I scan?*
(Accept either full path or list index.)
Do not output anything else outside the <folders> tags and the follow-up question, unless you need to show a <commentary> block for error or clarification.
Step 2: Target sub-folder scan
Once the user provides a subfolder choice, proceed as follows:
1. Validate the user input:
- If the chosen subfolder is not in rankedFolders, respond with:
<commentary>❌ *Selected sub-folder not found in previous list. Please choose a valid entry.*</commentary>
Then stop execution.
2. Run a file-level scan:
- Use the report-violations function with these parameters:
- component: {{COMPONENT_NAME}}
- directory: {{SUBFOLDER}}
- groupBy: "file"
- Store the result in a variable called fileScan.
3. Perform error handling and validation:
- If the function call returns an error containing "Missing ds.deprecatedCssClassesPath", respond with:
<commentary>⚠️ *Cannot proceed: Missing required configuration parameter* – The `ds.deprecatedCssClassesPath` parameter must be provided when starting the MCP server to use violation detection tools. Please restart the server with this parameter configured.</commentary>
Then stop execution.
- If the function call returns any other error, respond with:
<commentary>🚨 *Tool execution failed* – [error message]</commentary>
Then stop execution.
- If fileScan.rows.length is 0, respond with:
<commentary>⚠️ No violations found in {{SUBFOLDER}}.</commentary>
Then stop execution.
- Sort the files by number of violations (descending) and then alphabetically.
4. Output the results for the plan phase:
- Print the sorted list of files inside <violations> tags, like this:
<violations>
1. [path/to/file-A.tsx] – [X] violations
2. [path/to/file-B.tsx] – [X] violations
...
</violations>
- After the </violations> tag, prompt the user with:
❓ **Please attach the "Plan Phase" rules now so I can start refactoring planning.**
As in Step 1, any side remarks should go in an optional <commentary>...</commentary> tag.
Final instructions:
- Always use the exact format and wording provided for outputs and prompts.
- Do not add any explanations or additional text unless explicitly instructed.
- If you encounter any situations not covered by these instructions, respond with:
<commentary>⚠️ Unexpected situation encountered. Please provide further guidance.</commentary>