#!/usr/bin/python3
"""
SSHPilot Agent Launcher Script

This script is installed to /app/bin/sshpilot-agent and runs on the host
system to provide proper PTY handling for local shells in Flatpak.
"""

import glob
import sys

# Add sshpilot module to Python path. Covers Flatpak (/app), distro installs
# and Debian, which installs to dist-packages -- including the unversioned
# /usr/lib/python3/dist-packages that Meson picks there.
for base_path in ['/app', '/usr', '/usr/local']:
    for pkg_dir in ['site-packages', 'dist-packages']:
        for path in sorted(glob.glob(f'{base_path}/lib/python3*/{pkg_dir}')):
            sys.path.insert(0, path)

try:
    from sshpilot.sshpilot_agent import main
except ImportError as e:
    print(f"Error: Could not import sshpilot agent module: {e}", file=sys.stderr)
    print(f"Python path: {sys.path}", file=sys.stderr)
    sys.exit(1)

if __name__ == '__main__':
    sys.exit(main())

