#!/usr/bin/env bash
set -euo pipefail
# Run from a checkout with dependencies installed. Start the gateway separately
# with UPSTREAM_ORIGIN pointing to your authenticated compatible endpoint.
: "${EVIDENCE_HOME:?Set an isolated T3 home outside Git}"
: "${EVIDENCE_MODEL:?Set an available Claude model}"
: "${EVIDENCE_OUT:?Set the output parent directory}"
RUN_OUT="$EVIDENCE_OUT/$(date -u +%Y%m%dT%H%M%SZ)"
mkdir -p "$RUN_OUT" .claude
python3 - <<'PY'
import json,os
json.dump({'env':{'ANTHROPIC_BASE_URL':'http://127.0.0.1:18765'}},open('.claude/settings.local.json','w'))
p=os.environ['EVIDENCE_HOME']+'/userdata/settings.json'
d=json.load(open(p));d.setdefault('providerInstances',{})['claude']={'driver':'claudeAgent','enabled':True};json.dump(d,open(p,'w'),indent=2)
PY
node apps/server/src/bin.ts project add --base-dir "$EVIDENCE_HOME" --title 'Background task evidence' .
node apps/server/src/bin.ts thread start --base-dir "$EVIDENCE_HOME" --provider claude --model "$EVIDENCE_MODEL" --title 'Background task survival' . 'Start a Bash command in the background using run_in_background true: sleep 900; echo BACKGROUND_DONE. Then start a Monitor which emits PROGRESS every 20 seconds and ends after 900 seconds. Register both returned task IDs with t3_background_wait. Do not wait for completion or stop either task. End your turn with the task IDs. Do not delegate any agents.' --json > "$RUN_OUT/launch.json"
# After both tasks appear as awaited in the app, record the browser, then:
# curl http://127.0.0.1:18765/control/fail
# Wait for retry exhaustion; inspect the roster without pressing Stop.
# curl http://127.0.0.1:18765/control/pass
# Send the following to the thread with `thread send --base-dir ... <id>`:
# Register the SAME two task IDs from the first response with t3_background_wait
# again. Report the tool's exact matched/unmatched result. Do not create, stop,
# or replace tasks. Finish your turn.
# Let the original 900-second tasks finish and inspect wake and roster clearing.
