diff --git a/bin/navi-code b/bin/navi-code index f4dc66d..23f2d08 100755 --- a/bin/navi-code +++ b/bin/navi-code @@ -1,30 +1,32 @@ #!/usr/bin/env bash -""" -Wrapper script for launching the Navi Code terminal client from anywhere. +# Wrapper script for launching the Navi Code terminal client from anywhere. +# +# Usage: +# 1. Clone the navi repository. +# 2. Create a venv and install the package: +# python -m venv .venv +# .venv/bin/pip install -e ".[dev]" +# 3. Symlink this script onto your PATH: +# ln -s /path/to/navi/bin/navi-code ~/.local/bin/navi-code +# 4. cd into any project and run: +# navi-code +# +# The wrapper locates the project root from the script's own location (resolving +# symlinks so it works when called via a PATH symlink), runs the client with the +# repo's venv python, and puts the repo root on PYTHONPATH so the `clients` +# package is importable from any cwd WITHOUT cd-ing (cd would change the cwd the +# client captures and sends to the backend, breaking per-project path resolution). -Usage: - 1. Clone the navi repository. - 2. Create a venv and install the package: - python -m venv .venv - .venv/bin/pip install -e . - 3. Symlink this script onto your PATH: - ln -s /path/to/navi/bin/navi-code ~/.local/bin/navi-code - 4. cd into any project and run: - navi-code - -The wrapper locates the project root from the script's own location, activates -the local venv if present, and forwards all arguments to the `navi-code` entry -point. The client captures the shell's current working directory and sends it to -the backend so Navi resolves relative paths against your project directory. -""" - -SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +# Resolve symlinks so the wrapper finds PROJECT_ROOT correctly even when +# invoked via a symlink on PATH (e.g. ~/.local/bin/navi-code -> .../bin/navi-code). +SCRIPT_DIR="$(cd "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")" && pwd)" PROJECT_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)" VENV_DIR="${NAVI_CODE_VENV:-${PROJECT_ROOT}/.venv}" -if [[ -d "${VENV_DIR}" && -f "${VENV_DIR}/bin/navi-code" ]]; then - exec "${VENV_DIR}/bin/navi-code" "$@" +if [[ -f "${VENV_DIR}/bin/python" ]]; then + export PYTHONPATH="${PROJECT_ROOT}${PYTHONPATH:+:${PYTHONPATH}}" + exec "${VENV_DIR}/bin/python" -m clients.terminal.cli "$@" fi # Fallback: run the entry point directly if the package is installed elsewhere. -exec python -m clients.terminal.cli "$@" +exec python -m clients.terminal.cli "$@" \ No newline at end of file