feat(mma): Implement Context Amnesia bridge via subprocess
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import argparse
|
import argparse
|
||||||
|
import subprocess
|
||||||
|
|
||||||
def get_role_documents(role: str) -> list[str]:
|
def get_role_documents(role: str) -> list[str]:
|
||||||
if role == 'tier1':
|
if role == 'tier1':
|
||||||
@@ -9,6 +10,15 @@ def get_role_documents(role: str) -> list[str]:
|
|||||||
return ['conductor/workflow.md']
|
return ['conductor/workflow.md']
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
def execute_agent(role: str, prompt: str, docs: list[str]) -> str:
|
||||||
|
command_text = f"Activate the mma-{role} skill. {prompt}"
|
||||||
|
for doc in docs:
|
||||||
|
command_text += f" @{doc}"
|
||||||
|
|
||||||
|
cmd = ["gemini", command_text]
|
||||||
|
process = subprocess.run(cmd, capture_output=True, text=True)
|
||||||
|
return process.stdout
|
||||||
|
|
||||||
def create_parser():
|
def create_parser():
|
||||||
parser = argparse.ArgumentParser(description="MMA Execution Script")
|
parser = argparse.ArgumentParser(description="MMA Execution Script")
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
@@ -27,11 +37,11 @@ def create_parser():
|
|||||||
def main():
|
def main():
|
||||||
parser = create_parser()
|
parser = create_parser()
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
print(f"Role: {args.role}")
|
|
||||||
print(f"Prompt: {args.prompt}")
|
|
||||||
|
|
||||||
docs = get_role_documents(args.role)
|
docs = get_role_documents(args.role)
|
||||||
print(f"Selected Documents: {docs}")
|
print(f"Executing role: {args.role} with docs: {docs}")
|
||||||
|
result = execute_agent(args.role, args.prompt, docs)
|
||||||
|
print(result)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import pytest
|
import pytest
|
||||||
from scripts.mma_exec import create_parser, get_role_documents
|
from unittest.mock import patch, MagicMock
|
||||||
|
from scripts.mma_exec import create_parser, get_role_documents, execute_agent
|
||||||
|
|
||||||
def test_parser_role_choices():
|
def test_parser_role_choices():
|
||||||
"""Test that the parser accepts valid roles and the prompt argument."""
|
"""Test that the parser accepts valid roles and the prompt argument."""
|
||||||
@@ -37,3 +38,34 @@ def test_get_role_documents():
|
|||||||
assert get_role_documents('tier2') == ['conductor/tech-stack.md', 'conductor/workflow.md']
|
assert get_role_documents('tier2') == ['conductor/tech-stack.md', 'conductor/workflow.md']
|
||||||
assert get_role_documents('tier3') == ['conductor/workflow.md']
|
assert get_role_documents('tier3') == ['conductor/workflow.md']
|
||||||
assert get_role_documents('tier4') == []
|
assert get_role_documents('tier4') == []
|
||||||
|
|
||||||
|
def test_execute_agent():
|
||||||
|
"""
|
||||||
|
Test that execute_agent calls subprocess.run with the correct gemini CLI arguments
|
||||||
|
for context amnesia.
|
||||||
|
"""
|
||||||
|
role = "tier3"
|
||||||
|
prompt = "Write a unit test."
|
||||||
|
docs = ["file1.py", "docs/spec.md"]
|
||||||
|
|
||||||
|
expected_gemini_arg = "Activate the mma-tier3 skill. Write a unit test. @file1.py @docs/spec.md"
|
||||||
|
mock_stdout = "Mocked AI Response"
|
||||||
|
|
||||||
|
with patch("subprocess.run") as mock_run:
|
||||||
|
mock_process = MagicMock()
|
||||||
|
mock_process.stdout = mock_stdout
|
||||||
|
mock_process.returncode = 0
|
||||||
|
mock_run.return_value = mock_process
|
||||||
|
|
||||||
|
result = execute_agent(role, prompt, docs)
|
||||||
|
|
||||||
|
mock_run.assert_called_once()
|
||||||
|
args, kwargs = mock_run.call_args
|
||||||
|
cmd_list = args[0]
|
||||||
|
|
||||||
|
assert cmd_list[0] == "gemini"
|
||||||
|
assert cmd_list[1] == expected_gemini_arg
|
||||||
|
assert kwargs.get("capture_output") is True
|
||||||
|
assert kwargs.get("text") is True
|
||||||
|
|
||||||
|
assert result == mock_stdout
|
||||||
Reference in New Issue
Block a user