"""Entry point for `jac-coder-server` command.

Finds server.jac inside the installed jac_coder package and runs it with
`jac run`. Works both in dev (editable install) and after pip install.
"""

import os
import subprocess
import sys


def main() -> None:
    # __file__ is inside jac_coder/ — server.jac lives right next to it.
    pkg_dir = os.path.dirname(os.path.abspath(__file__))
    server_jac = os.path.join(pkg_dir, "server.jac")

    if not os.path.exists(server_jac):
        print(f"Error: server.jac not found at {server_jac}", file=sys.stderr)
        sys.exit(1)

    sys.exit(subprocess.call(["jac", "run", server_jac] + sys.argv[1:]))


if __name__ == "__main__":
    main()
