#!/bin/bash
# keepalive+launcher: ng-l1-kimik3-ptc (openrouter/moonshotai/kimi-k3) на lab1 — ИЗОЛИРОВАННЫЙ HOME (инцидент 17)
export PATH=/root/.local/bin:$PATH
source /root/.env_openrouter
D=/root/pcruns/ng_l1_kimik3
[ -z "$OPENROUTER_API_KEY" ] && echo "$(date -Iseconds) FATAL no key" >> $D/launcher.log && exit 1
mkdir -p $D/home/.pentestcode && cd $D
cp -r /root/.pentestcode/pentestcode.jsonc /root/.pentestcode/skills $D/home/.pentestcode/ 2>/dev/null
export HOME=$D/home
for i in 1 2 3 4 5 6 7 8; do
  echo "$(date -Iseconds) round $i start" >> $D/launcher.log
  if [ $i -eq 1 ]; then
    pentestcode run -i --dir $D -m openrouter/moonshotai/kimi-k3 --auto --title "ng-l1-kimik3-ptc" "$(cat /root/pcruns/prompt_ng1.txt)" 2>&1 | tee run.log
  else
    echo "=== KEEPALIVE RESTART $i ===" >> run.log
    pentestcode run -i --dir $D -m openrouter/moonshotai/kimi-k3 --auto -c "Continue the engagement. Keep going until all 5 objectives are proven." 2>&1 | tee -a run.log
  fi
  echo "$(date -Iseconds) round $i exit=$?" >> $D/launcher.log
  sleep 5
done
