#!/bin/bash
# Shim: delegates to compiled find-browse binary, falls back to basic discovery.
# The compiled binary handles git root detection for workspace-local installs.
DIR="$(cd "$(dirname "$0")/.." && pwd)/dist"
if test -x "$DIR/find-browse"; then
  exec "$DIR/find-browse" "$@"
fi
# Fallback: basic discovery with priority chain
ROOT=$(git rev-parse --show-toplevel 2>/dev/null)
for MARKER in .codex .agents .claude; do
  if [ -n "$ROOT" ] && test -x "$ROOT/$MARKER/skills/gstack/browse/dist/browse"; then
    echo "$ROOT/$MARKER/skills/gstack/browse/dist/browse"
    exit 0
  fi
  if test -x "$HOME/$MARKER/skills/gstack/browse/dist/browse"; then
    echo "$HOME/$MARKER/skills/gstack/browse/dist/browse"
    exit 0
  fi
done
echo "ERROR: browse binary not found. Run: cd <skill-dir> && ./setup" >&2
exit 1
