#!/bin/sh
set -eu

primary_workspace=${AGENTRUN_WORKSPACE_PATH:-}

case "$primary_workspace" in
  /*) ;;
  *)
    printf '%s\n' '{"ok":false,"failureKind":"tool-unavailable","message":"runner did not provide an absolute primary workspace path","source":"primary-workspace","valuesPrinted":false}' >&2
    exit 2
    ;;
esac

shared_tran="$primary_workspace/scripts/tran"
shared_cli="$primary_workspace/scripts/ssh-cli.ts"

if [ ! -x "$shared_tran" ] || [ ! -f "$shared_cli" ]; then
  printf '%s\n' '{"ok":false,"failureKind":"tool-unavailable","message":"primary UniDesk workspace does not provide executable scripts/tran","source":"primary-workspace","valuesPrinted":false}' >&2
  exit 2
fi

UNIDESK_TRAN_REPO_ROOT="$primary_workspace"
export UNIDESK_TRAN_REPO_ROOT
exec "$shared_tran" "$@"
