#!/usr/bin/env sh
# msd_run — standalone launcher so workflow bash blocks can invoke the MSD tools
# in a fresh shell. Claude Code (and similar runtimes) runs each fenced bash block
# in a separate process, so an inline msd_run() function defined in an earlier
# block is undefined in later ones (issue #381). This executable is shipped beside
# msd-tools.cjs in msd-core/bin/ and exposed on PATH via the npm "bin" field and
# the per-file preamble's CLAUDE_ENV_FILE export, so later blocks resolve it.
# It resolves its own real location (following symlinks) and delegates to msd-tools.cjs.
set -e
src="$0"
while [ -h "$src" ]; do
  dir="$(cd -P "$(dirname "$src")" && pwd)"
  src="$(readlink "$src")"
  case "$src" in
    /*) ;;
    *) src="$dir/$src" ;;
  esac
done
dir="$(cd -P "$(dirname "$src")" && pwd)"
exec node "$dir/msd-tools.cjs" "$@"
