59 lines
2.1 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
# ─── run_one.sh ──────────────────────────────────────────────────────────────
# Run pi with the sequence-diagram skill on a single task.
# Usage: ./scripts/run_one.sh <task_prompt> <output_file> [ssh_target] [ssh_port]
#
# If ssh_target is provided, runs remotely via SSH into the pi container.
# Otherwise runs pi locally.
# ─────────────────────────────────────────────────────────────────────────────
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
TASK_PROMPT="$1"
OUTPUT_FILE="$2"
SSH_TARGET="${3:-}"
SSH_PORT="${4:-2222}"
TIMEOUT="${TASK_TIMEOUT:-180}"
SKILL_FILE="${PROJECT_DIR}/skill/SKILL.md"
if [[ ! -f "$SKILL_FILE" ]]; then
echo "ERROR: skill/SKILL.md not found" >&2
exit 1
fi
SKILL_CONTENT=$(cat "$SKILL_FILE")
# Build the full prompt: skill instructions + task
FULL_PROMPT="## Skill Instructions
${SKILL_CONTENT}
## Task
${TASK_PROMPT}"
if [[ -n "$SSH_TARGET" ]]; then
# ─── Remote: SSH into pi container ───────────────────────────────────
PAYLOAD=$(jq -n --arg prompt "$FULL_PROMPT" '{"prompt": $prompt}')
ssh -p "$SSH_PORT" \
-o StrictHostKeyChecking=no \
-o ConnectTimeout=10 \
-o BatchMode=yes \
"$SSH_TARGET" \
"run-task --stdin --mode print --thinking off --timeout $TIMEOUT" \
<<< "$PAYLOAD" > "$OUTPUT_FILE" 2>/dev/null
else
# ─── Local: run pi directly ──────────────────────────────────────────
timeout "${TIMEOUT}s" pi \
--mode print \
--no-session \
--no-extensions \
--thinking none \
-p "$FULL_PROMPT" > "$OUTPUT_FILE" 2>/dev/null || true
fi