feat(mma): Optimize sub-agent research with get_code_outline and get_git_diff
This commit is contained in:
@@ -281,6 +281,31 @@ def get_code_outline(path: str) -> str:
|
||||
return f"ERROR generating outline for '{path}': {e}"
|
||||
|
||||
|
||||
def get_git_diff(path: str, base_rev: str = "HEAD", head_rev: str = "") -> str:
|
||||
"""
|
||||
Returns the git diff for a file or directory.
|
||||
base_rev: The base revision (default: HEAD)
|
||||
head_rev: The head revision (optional)
|
||||
"""
|
||||
import subprocess
|
||||
p, err = _resolve_and_check(path)
|
||||
if err:
|
||||
return err
|
||||
|
||||
cmd = ["git", "diff", base_rev]
|
||||
if head_rev:
|
||||
cmd.append(head_rev)
|
||||
cmd.extend(["--", str(p)])
|
||||
|
||||
try:
|
||||
result = subprocess.run(cmd, capture_output=True, text=True, check=True, encoding="utf-8")
|
||||
return result.stdout if result.stdout else "(no changes)"
|
||||
except subprocess.CalledProcessError as e:
|
||||
return f"ERROR running git diff: {e.stderr}"
|
||||
except Exception as e:
|
||||
return f"ERROR: {e}"
|
||||
|
||||
|
||||
|
||||
# ------------------------------------------------------------------ web tools
|
||||
|
||||
@@ -407,7 +432,7 @@ def get_ui_performance() -> str:
|
||||
# ------------------------------------------------------------------ tool dispatch
|
||||
|
||||
|
||||
TOOL_NAMES = {"read_file", "list_directory", "search_files", "get_file_summary", "get_python_skeleton", "get_code_outline", "web_search", "fetch_url", "get_ui_performance"}
|
||||
TOOL_NAMES = {"read_file", "list_directory", "search_files", "get_file_summary", "get_python_skeleton", "get_code_outline", "get_git_diff", "web_search", "fetch_url", "get_ui_performance"}
|
||||
|
||||
|
||||
def dispatch(tool_name: str, tool_input: dict) -> str:
|
||||
@@ -426,6 +451,12 @@ def dispatch(tool_name: str, tool_input: dict) -> str:
|
||||
return get_python_skeleton(tool_input.get("path", ""))
|
||||
if tool_name == "get_code_outline":
|
||||
return get_code_outline(tool_input.get("path", ""))
|
||||
if tool_name == "get_git_diff":
|
||||
return get_git_diff(
|
||||
tool_input.get("path", ""),
|
||||
tool_input.get("base_rev", "HEAD"),
|
||||
tool_input.get("head_rev", "")
|
||||
)
|
||||
if tool_name == "web_search":
|
||||
return web_search(tool_input.get("query", ""))
|
||||
if tool_name == "fetch_url":
|
||||
@@ -551,6 +582,31 @@ MCP_TOOL_SPECS = [
|
||||
"required": ["path"],
|
||||
},
|
||||
},
|
||||
{
|
||||
"name": "get_git_diff",
|
||||
"description": (
|
||||
"Returns the git diff for a file or directory. "
|
||||
"Use this to review changes efficiently without reading entire files."
|
||||
),
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"path": {
|
||||
"type": "string",
|
||||
"description": "Path to the file or directory.",
|
||||
},
|
||||
"base_rev": {
|
||||
"type": "string",
|
||||
"description": "Base revision (e.g. 'HEAD', 'HEAD~1', or a commit hash). Defaults to 'HEAD'.",
|
||||
},
|
||||
"head_rev": {
|
||||
"type": "string",
|
||||
"description": "Head revision (optional).",
|
||||
}
|
||||
},
|
||||
"required": ["path"],
|
||||
},
|
||||
},
|
||||
{
|
||||
"name": "web_search",
|
||||
"description": "Search the web using DuckDuckGo. Returns the top 5 search results with titles, URLs, and snippets. Chain this with fetch_url to read specific pages.",
|
||||
|
||||
Reference in New Issue
Block a user