#!/usr/bin/env bash
set -euo pipefail

RUNTIME="${SPOON_AGENT_CONTAINER_RUNTIME:-}"
IMAGE="${SPOON_AGENT_LOCAL_JOB_IMAGE:-${SPOON_AGENT_JOB_IMAGE:-spoon-agent-job:latest}}"

if [[ -z "$RUNTIME" ]]; then
  if command -v podman >/dev/null 2>&1; then
    RUNTIME=podman
  elif command -v docker >/dev/null 2>&1; then
    RUNTIME=docker
  else
    printf 'smoke-agent-container: podman or docker is required.\n' >&2
    exit 1
  fi
fi

"$RUNTIME" run --rm "$IMAGE" bash -lc '
  set -euo pipefail
  node --version
  bun --version
  pnpm --version
  yarn --version
  npm --version
  git --version
  rg --version >/dev/null
  jq --version
  python3 --version
  opencode --version
  codex --version
  claude --version
'

# Manual per-runtime smoke (requires creds in your shell env):
#   docker build -f docker/agent-job.Dockerfile -t spoon-agent-job:latest .
#   docker run -d --name spoon-box-smoke --init spoon-agent-job:latest sleep infinity
#   docker exec -e OPENAI_API_KEY -w /workspace spoon-box-smoke \
#     opencode run --format json --model openai/gpt-5.5 -- 'print hello'
#   docker exec -e ANTHROPIC_API_KEY -w /workspace spoon-box-smoke \
#     claude -p 'print hello' --output-format stream-json --verbose --dangerously-skip-permissions
#   docker exec -e CODEX_HOME=/root/.codex -w /workspace spoon-box-smoke \
#     codex exec --json --dangerously-bypass-approvals-and-sandbox 'print hello'
#   docker rm -f spoon-box-smoke
