#!/usr/bin/env python3
import sys
import os

# Add the src directory to the Python path
sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'src'))

from alloy import parser

def test_clean_syntax():
    # Test the new clean agent syntax
    test_code = '''
tool web_search takes query returns search_results {
    search_results = "mock search results for: " + query
}

tool read_files takes file_path returns file_content {
    file_content = "mock file content from: " + file_path
}

command Analyze means "analyze the provided data and return insights"

claude = agent "gpt-4o-mini"
researcher = agent "gpt-4o-mini" with tools web_search, read_files

analysis, error = claude Analyze "user data"
'''

    try:
        ast = parser.parse(test_code)
        print('Parser test successful!')
        print('AST:', ast)
        
        interpreter = alloy_interpreter.Interpreter()
        interpreter.interpret(ast)
        print('Interpreter test successful!')
        
        # Check if agents were defined
        try:
            claude_info = interpreter.global_env.get_agent('claude')
            print(f'Claude agent: {claude_info}')
            
            researcher_info = interpreter.global_env.get_agent('researcher')
            print(f'Researcher agent: {researcher_info}')
        except Exception as e:
            print(f'Agent lookup error: {e}')
            
    except Exception as e:
        print(f'Error: {e}')
        import traceback
        traceback.print_exc()

if __name__ == "__main__":
    test_clean_syntax()