import subprocess
import sys

def run_diag(role: str, prompt: str) -> str:
 print(f"--- Running Diag for {role} ---")
 cmd = [sys.executable, "scripts/mma_exec.py", "--role", role, prompt]
 try:
  result = subprocess.run(cmd, capture_output=True, text=True, encoding='utf-8')
  print("STDOUT:")
  print(result.stdout)
  print("STDERR:")
  print(result.stderr)
  return result.stdout
 except Exception as e:
  print(f"FAILED: {e}")
  return str(e)

if __name__ == "__main__":
# Test 1: Simple read
 print("TEST 1: read_file")
 run_diag("tier3-worker", "Read the file 'pyproject.toml' and tell me the version of the project. ONLY the version string.")
 print("\nTEST 2: run_shell_command")
 run_diag("tier3-worker", "Use run_shell_command to execute 'echo HELLO_SUBAGENT' and return the output. ONLY the output.")
