#!/usr/bin/env bash
set -eu
: "${MODEL:?Set MODEL to the authenticated OpenCode model used for both runs}"
checkout=$1
scratch=$2
mkdir -p "$scratch/sample/project" "$scratch/sample/outside"
if ! git -C "$scratch/sample/project" rev-parse --git-dir >/dev/null 2>&1; then
  git init -q "$scratch/sample/project"
  git -C "$scratch/sample/project" -c user.name=Example -c user.email=example@example.com commit -q --allow-empty -m 'Initial sample'
fi
printf '%s\n' 'Outside note: permission check succeeded.' > "$scratch/sample/outside/notes.txt"
cd "$checkout"
node apps/server/src/bin.ts thread start --base-dir .t3 --provider opencode --model "$MODEL" --title 'Full access subagent check' "$scratch/sample/project" "Use the task tool to launch a @general subagent with description \"Run requested shell commands\". Instruct the child to run cat $scratch/sample/outside/notes.txt and git -C $scratch/sample/project log --oneline. The child must execute both commands, not just describe them. Report their exact outputs. Do not run the commands in the parent." --json
