feat(mma): Integrate Tier 4 QA analysis across all providers and conductor

This commit is contained in:
2026-02-26 20:29:34 -05:00
parent 80a10f4d12
commit fb3da4de36
5 changed files with 122 additions and 19 deletions

View File

@@ -21,6 +21,7 @@ import difflib
import threading
import requests
from pathlib import Path
from typing import Optional, Callable
import os
import project_manager
import file_cache
@@ -522,10 +523,10 @@ def _gemini_tool_declaration():
return types.Tool(function_declarations=declarations) if declarations else None
def _run_script(script: str, base_dir: str) -> str:
def _run_script(script: str, base_dir: str, qa_callback: Optional[Callable[[str], str]] = None) -> str:
if confirm_and_run_callback is None:
return "ERROR: no confirmation handler registered"
result = confirm_and_run_callback(script, base_dir)
result = confirm_and_run_callback(script, base_dir, qa_callback)
if result is None:
output = "USER REJECTED: command was not executed"
else:
@@ -669,7 +670,8 @@ def _get_gemini_history_list(chat):
def _send_gemini(md_content: str, user_message: str, base_dir: str,
file_items: list[dict] | None = None,
discussion_history: str = "",
pre_tool_callback = None) -> str:
pre_tool_callback = None,
qa_callback: Optional[Callable[[str], str]] = None) -> str:
global _gemini_chat, _gemini_cache, _gemini_cache_md_hash, _gemini_cache_created_at
try:
@@ -848,7 +850,7 @@ def _send_gemini(md_content: str, user_message: str, base_dir: str,
elif name == TOOL_NAME:
scr = args.get("script", "")
_append_comms("OUT", "tool_call", {"name": TOOL_NAME, "script": scr})
out = _run_script(scr, base_dir)
out = _run_script(scr, base_dir, qa_callback)
else: out = f"ERROR: unknown tool '{name}'"
if i == len(calls) - 1:
@@ -880,7 +882,8 @@ def _send_gemini(md_content: str, user_message: str, base_dir: str,
def _send_gemini_cli(md_content: str, user_message: str, base_dir: str,
file_items: list[dict] | None = None,
discussion_history: str = "",
pre_tool_callback = None) -> str:
pre_tool_callback = None,
qa_callback: Optional[Callable[[str], str]] = None) -> str:
global _gemini_cli_adapter
try:
if _gemini_cli_adapter is None:
@@ -984,7 +987,7 @@ def _send_gemini_cli(md_content: str, user_message: str, base_dir: str,
elif name == TOOL_NAME:
scr = args.get("script", "")
_append_comms("OUT", "tool_call", {"name": TOOL_NAME, "id": call_id, "script": scr})
out = _run_script(scr, base_dir)
out = _run_script(scr, base_dir, qa_callback)
else:
out = f"ERROR: unknown tool '{name}'"
@@ -1277,7 +1280,7 @@ def _repair_anthropic_history(history: list[dict]):
})
def _send_anthropic(md_content: str, user_message: str, base_dir: str, file_items: list[dict] | None = None, discussion_history: str = "", pre_tool_callback = None) -> str:
def _send_anthropic(md_content: str, user_message: str, base_dir: str, file_items: list[dict] | None = None, discussion_history: str = "", pre_tool_callback = None, qa_callback: Optional[Callable[[str], str]] = None) -> str:
try:
_ensure_anthropic_client()
mcp_client.configure(file_items or [], [base_dir])
@@ -1441,7 +1444,7 @@ def _send_anthropic(md_content: str, user_message: str, base_dir: str, file_item
"id": b_id,
"script": script,
})
output = _run_script(script, base_dir)
output = _run_script(script, base_dir, qa_callback)
_append_comms("IN", "tool_result", {
"name": TOOL_NAME,
"id": b_id,
@@ -1520,7 +1523,8 @@ def _send_deepseek(md_content: str, user_message: str, base_dir: str,
file_items: list[dict] | None = None,
discussion_history: str = "",
stream: bool = False,
pre_tool_callback = None) -> str:
pre_tool_callback = None,
qa_callback: Optional[Callable[[str], str]] = None) -> str:
"""
Sends a message to the DeepSeek API, handling tool calls and history.
Supports streaming responses.
@@ -1713,7 +1717,7 @@ def _send_deepseek(md_content: str, user_message: str, base_dir: str,
elif tool_name == TOOL_NAME:
script = tool_args.get("script", "")
_append_comms("OUT", "tool_call", {"name": TOOL_NAME, "id": tool_id, "script": script})
tool_output = _run_script(script, base_dir)
tool_output = _run_script(script, base_dir, qa_callback)
else:
tool_output = f"ERROR: unknown tool '{tool_name}'"
@@ -1811,6 +1815,7 @@ def send(
discussion_history: str = "",
stream: bool = False,
pre_tool_callback = None,
qa_callback: Optional[Callable[[str], str]] = None,
) -> str:
"""
Send a message to the active provider.
@@ -1825,16 +1830,17 @@ def send(
conversation message instead of caching it)
stream : Whether to use streaming (supported by DeepSeek)
pre_tool_callback : Optional callback (payload: str) -> bool called before tool execution
qa_callback : Optional callback (stderr: str) -> str called for Tier 4 error analysis
"""
with _send_lock:
if _provider == "gemini":
return _send_gemini(md_content, user_message, base_dir, file_items, discussion_history, pre_tool_callback)
return _send_gemini(md_content, user_message, base_dir, file_items, discussion_history, pre_tool_callback, qa_callback)
elif _provider == "gemini_cli":
return _send_gemini_cli(md_content, user_message, base_dir, file_items, discussion_history, pre_tool_callback)
return _send_gemini_cli(md_content, user_message, base_dir, file_items, discussion_history, pre_tool_callback, qa_callback)
elif _provider == "anthropic":
return _send_anthropic(md_content, user_message, base_dir, file_items, discussion_history, pre_tool_callback)
return _send_anthropic(md_content, user_message, base_dir, file_items, discussion_history, pre_tool_callback, qa_callback)
elif _provider == "deepseek":
return _send_deepseek(md_content, user_message, base_dir, file_items, discussion_history, stream=stream, pre_tool_callback=pre_tool_callback)
return _send_deepseek(md_content, user_message, base_dir, file_items, discussion_history, stream=stream, pre_tool_callback=pre_tool_callback, qa_callback=qa_callback)
raise ValueError(f"unknown provider: {_provider}")
def get_history_bleed_stats(md_content: str | None = None) -> dict: