feat(perf): Add get_ui_performance AI tool

This commit is contained in:
2026-02-23 14:46:52 -05:00
parent 932194d6fa
commit 9ec5ff309a
3 changed files with 59 additions and 11 deletions

View File

@@ -45,6 +45,9 @@ _allowed_paths: set[Path] = set()
_base_dirs: set[Path] = set()
_primary_base_dir: Path | None = None
# Injected by gui.py - returns a dict of performance metrics
perf_monitor_callback = None
def configure(file_items: list[dict], extra_base_dirs: list[str] | None = None):
"""
@@ -300,11 +303,27 @@ def fetch_url(url: str) -> str:
return full_text
except Exception as e:
return f"ERROR fetching URL '{url}': {e}"
def get_ui_performance() -> str:
"""Returns current UI performance metrics (FPS, Frame Time, CPU, Input Lag)."""
if perf_monitor_callback is None:
return "ERROR: Performance monitor callback not registered."
try:
metrics = perf_monitor_callback()
# Clean up the dict string for the AI
metric_str = str(metrics)
for char in "{}'":
metric_str = metric_str.replace(char, "")
return f"UI Performance Snapshot:\n{metric_str}"
except Exception as e:
return f"ERROR: Failed to retrieve UI performance: {str(e)}"
# ------------------------------------------------------------------ tool dispatch
TOOL_NAMES = {"read_file", "list_directory", "search_files", "get_file_summary", "web_search", "fetch_url"}
TOOL_NAMES = {"read_file", "list_directory", "search_files", "get_file_summary", "web_search", "fetch_url", "get_ui_performance"}
def dispatch(tool_name: str, tool_input: dict) -> str:
@@ -323,6 +342,8 @@ def dispatch(tool_name: str, tool_input: dict) -> str:
return web_search(tool_input.get("query", ""))
if tool_name == "fetch_url":
return fetch_url(tool_input.get("url", ""))
if tool_name == "get_ui_performance":
return get_ui_performance()
return f"ERROR: unknown MCP tool '{tool_name}'"
@@ -420,17 +441,11 @@ MCP_TOOL_SPECS = [
}
},
{
"name": "fetch_url",
"description": "Fetch a webpage and extract its text content, removing HTML tags and scripts. Useful for reading documentation or articles found via web_search.",
"name": "get_ui_performance",
"description": "Get a snapshot of the current UI performance metrics, including FPS, Frame Time (ms), CPU usage (%), and Input Lag (ms). Use this to diagnose UI slowness or verify that your changes haven't degraded the user experience.",
"parameters": {
"type": "object",
"properties": {
"url": {
"type": "string",
"description": "The URL to fetch."
}
},
"required": ["url"]
"properties": {}
}
},
}
]