#!/bin/bash
# code-hands "TASK": run pi, a lean coding agent, on TASK in the current directory with the agent's own model.
# Installed by bootkey. Settings live in ~/.config/bootkey-hands (key, model, pi/models.json).
set -u
CFG=$HOME/.config/bootkey-hands
[ $# -gt 0 ] || { echo 'usage: code-hands "what to do, and how to check it"' >&2; exit 2; }
[ -r "$CFG/key" ] && [ -r "$CFG/model" ] || { echo "code-hands is not set up (missing $CFG)" >&2; exit 3; }
export OPENROUTER_API_KEY=$(cat "$CFG/key") PI_CODING_AGENT_DIR=$CFG/pi PI_OFFLINE=1
NODE=$(ls -d $HOME/.hermes/tools/node-*/bin | head -1)/node
LOG=$HOME/.hermes/logs/code-hands.log; mkdir -p "$(dirname "$LOG")"
TASK="$*"; t0=$(date +%s); echo "$(date -u +%FT%TZ) start dir=$PWD task_chars=${#TASK}" >> "$LOG"
timeout -k 10 "${HANDS_TIMEOUT:-900}" "$NODE" $HOME/hands/pi/node_modules/@mariozechner/pi-coding-agent/dist/cli.js \
  -p --no-session --provider openrouter --model "$(cat "$CFG/model")" --thinking medium "$*"
rc=$?
echo "$(date -u +%FT%TZ) end exit=$rc seconds=$(( $(date +%s) - t0 ))" >> "$LOG"
exit $rc
