#!/usr/bin/env bash
# 以服务账号 agentsvc 运行 AgentServer 自带的 Claude Code（官方二进制，版本与 Agent SDK 一致）。
# 用途：登录（agent-claude 后输入 /login）、查看登录状态（agent-claude auth status）、
#       插件管理（agent-claude plugin ...，后台"技能与插件"页面也会调用同样的命令）
set -euo pipefail
BIN=$(sudo find /srv/agent-server/app/server/node_modules/.pnpm -path '*claude-agent-sdk-linux-*/claude' -type f 2>/dev/null | head -1)
if [ -z "$BIN" ]; then
  echo "找不到 AgentServer 自带的 Claude Code，请先运行 deploy/deploy.sh" >&2
  exit 1
fi
exec sudo -u agentsvc -H sh -c 'cd "$HOME" && exec "$0" "$@"' "$BIN" "$@"
