feat(mma): Implement logging/auditing for role hand-offs

This commit is contained in:
2026-02-25 20:16:56 -05:00
parent 25b904b404
commit 678fa89747
2 changed files with 34 additions and 0 deletions

View File

@@ -76,7 +76,22 @@ def get_role_documents(role: str) -> list[str]:
return ['conductor/workflow.md'] return ['conductor/workflow.md']
return [] 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: def execute_agent(role: str, prompt: str, docs: list[str]) -> str:
log_delegation(role, prompt)
model = get_model_for_role(role) model = get_model_for_role(role)
command_text = f"Use the mma-{role} skill. {prompt}" command_text = f"Use the mma-{role} skill. {prompt}"
for doc in docs: for doc in docs:

View File

@@ -96,3 +96,22 @@ def test_get_dependencies(tmp_path):
filepath.write_text(content) filepath.write_text(content)
dependencies = get_dependencies(filepath) dependencies = get_dependencies(filepath)
assert dependencies == ['os', 'sys', 'file_cache', 'mcp_client'] 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)