#!/bin/sh
# Scope 442 (D-38): `agents77 run --heavy -- <command>` — the shim on PATH. Runs agents77.mjs beside
# it with `node`, or with the AGENTS77 app's own runtime when there is no node.
here=$(dirname "$(readlink -f "$0" 2>/dev/null || realpath "$0" 2>/dev/null || echo "$0")")
script="$here/agents77.mjs"
if command -v node >/dev/null 2>&1; then
  exec node "$script" "$@"
fi
for app in "$here/../../MacOS/AGENTS77" "$here/../../agents77" "$here/../../AGENTS77"; do
  if [ -x "$app" ]; then
    ELECTRON_RUN_AS_NODE=1 exec "$app" "$script" "$@"
  fi
done
# Nothing to run the queue with: run the command itself (everything after --).
while [ "$#" -gt 0 ] && [ "$1" != "--" ]; do shift; done
[ "$#" -gt 0 ] && shift
exec "$@"
