#!/usr/bin/python3
import os, sys, json, subprocess
args = sys.argv[1:]
if args and args[0] == 'exec':
    config = []
    for i, arg in enumerate(args[:-1]):
        if arg in ('-c', '--config'):
            config += [arg, args[i+1]]
    check = subprocess.run(['/usr/local/bin/codex', *config, 'mcp', 'list', '--json'], capture_output=True, text=True)
    with open(os.environ['EVIDENCE_TRACE'], 'a') as f:
        f.write('Actual exec config arguments: ' + json.dumps(config) + '\n')
        if check.returncode:
            f.write('Same config, real codex mcp list: ' + check.stderr.strip() + '\n')
        else:
            servers=json.loads(check.stdout)
            f.write('Same config, real codex mcp list (target only): ' + json.dumps([x for x in servers if x['name']=='t3-code']) + '\n')
os.execv('/usr/local/bin/codex', ['/usr/local/bin/codex', *args])
