qmd 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/bin/sh
  2. # Resolve symlinks so global installs (npm link / npm install -g) can find the
  3. # actual package directory instead of the global bin directory.
  4. SOURCE="$0"
  5. while [ -L "$SOURCE" ]; do
  6. SOURCE_DIR="$(cd -P "$(dirname "$SOURCE")" && pwd)"
  7. TARGET="$(readlink "$SOURCE")"
  8. case "$TARGET" in
  9. /*) SOURCE="$TARGET" ;;
  10. *) SOURCE="$SOURCE_DIR/$TARGET" ;;
  11. esac
  12. done
  13. # Detect the runtime used to install this package and use the matching one
  14. # to avoid native module ABI mismatches (e.g., better-sqlite3 compiled for bun vs node)
  15. DIR="$(cd -P "$(dirname "$SOURCE")/.." && pwd)"
  16. # Oivo installs the shared project index under /srv/.cache/qmd so spawned
  17. # agents, cron jobs, and shell calls all read the same database. The MCP preset
  18. # injects XDG_CACHE_HOME explicitly, but direct `qmd ...` calls do not; without
  19. # this default they silently create/read an empty ~/.cache/qmd/index.sqlite.
  20. if [ -z "${INDEX_PATH:-}" ] && [ -z "${XDG_CACHE_HOME:-}" ] && [ -d /srv/.cache/qmd ]; then
  21. export XDG_CACHE_HOME=/srv/.cache
  22. fi
  23. # Detect the package manager that installed dependencies by checking lockfiles.
  24. # $BUN_INSTALL is intentionally NOT checked — it only indicates that bun exists
  25. # on the system, not that it was used to install this package (see #361).
  26. #
  27. # package-lock.json takes priority: if it exists, npm installed the native
  28. # modules for Node. The repo ships bun.lock, so without this check, source
  29. # builds that use npm would be incorrectly routed to bun, causing ABI
  30. # mismatches with better-sqlite3 / sqlite-vec (see #381).
  31. if [ -f "$DIR/package-lock.json" ]; then
  32. exec node "$DIR/dist/cli/qmd.js" "$@"
  33. elif [ -f "$DIR/bun.lock" ] || [ -f "$DIR/bun.lockb" ]; then
  34. exec bun "$DIR/dist/cli/qmd.js" "$@"
  35. else
  36. exec node "$DIR/dist/cli/qmd.js" "$@"
  37. fi