From 678fa8974779d751a801f9b52b31d328981a1c6a Mon Sep 17 00:00:00 2001 From: Ed_ Date: Wed, 25 Feb 2026 20:16:56 -0500 Subject: [PATCH] feat(mma): Implement logging/auditing for role hand-offs --- scripts/mma_exec.py | 15 +++++++++++++++ tests/test_mma_exec.py | 19 +++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/scripts/mma_exec.py b/scripts/mma_exec.py index 89badb4..ed93869 100644 --- a/scripts/mma_exec.py +++ b/scripts/mma_exec.py @@ -76,7 +76,22 @@ def get_role_documents(role: str) -> list[str]: return ['conductor/workflow.md'] return [] +LOG_FILE = 'logs/mma_delegation.log' + +def log_delegation(role, prompt): + import os + import datetime + os.makedirs(os.path.dirname(LOG_FILE), exist_ok=True) + timestamp = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') + with open(LOG_FILE, 'a') as f: + f.write("--------------------------------------------------\n") + f.write(f"TIMESTAMP: {timestamp}\n") + f.write(f"TIER: {role}\n") + f.write(f"PROMPT: {prompt}\n") + f.write("--------------------------------------------------\n") + def execute_agent(role: str, prompt: str, docs: list[str]) -> str: + log_delegation(role, prompt) model = get_model_for_role(role) command_text = f"Use the mma-{role} skill. {prompt}" for doc in docs: diff --git a/tests/test_mma_exec.py b/tests/test_mma_exec.py index 734fb2a..93101f4 100644 --- a/tests/test_mma_exec.py +++ b/tests/test_mma_exec.py @@ -96,3 +96,22 @@ def test_get_dependencies(tmp_path): filepath.write_text(content) dependencies = get_dependencies(filepath) assert dependencies == ['os', 'sys', 'file_cache', 'mcp_client'] + + +import re +def test_execute_agent_logging(tmp_path): + log_file = tmp_path / "mma_delegation.log" + with patch("scripts.mma_exec.LOG_FILE", str(log_file)), \ + patch("subprocess.run") as mock_run: + mock_process = MagicMock() + mock_process.stdout = "" + mock_process.returncode = 0 + mock_run.return_value = mock_process + test_role = "tier1" + test_prompt = "Plan the next phase" + execute_agent(test_role, test_prompt, []) + assert log_file.exists() + log_content = log_file.read_text() + assert test_role in log_content + assert test_prompt in log_content + assert re.search(r"\d{4}-\d{2}-\d{2}", log_content)