#!/bin/zsh
# 4a dry-run 완료 감지 → fresh manifest 에서 acceptance 추출.
export PGPASSWORD=theroad_dev_2026
CKDIR="/Users/manta/Documents/Projects/TheRoad-I1/projects/a7f80ab9-e97b-420c-a380-3beccb0bcfe5/checkpoints/episodes/286f3ba4-5738-49b7-a7e4-ce0295fd4352/outdoor_site_layout"
for i in $(seq 1 240); do
  st=$(psql -h localhost -U theroad -d theroad -t -c "SELECT status FROM step_run WHERE step_id='outdoor_site_layout' ORDER BY updated_at DESC LIMIT 1;" | tr -d ' \n')
  if [ "$st" != "running" ]; then echo "STEP DONE status=$st after ${i} polls"; break; fi
  sleep 30
done
echo "=== newest manifest ==="
MF=$(ls -t "$CKDIR"/manifest_*.json 2>/dev/null | head -1)
echo "$MF"
python3 - "$MF" <<'PY'
import json, sys
d=json.load(open(sys.argv[1]))
data=d.get('data',{})
diag=data.get('diagnostics',{})
print("updated_at:", d.get('updated_at'))
print("single_shot_seed_lane_enabled:", diag.get('single_shot_seed_lane_enabled'))
print("seed_group_count:", diag.get('seed_group_count'))
print("outdoor_location_count:", diag.get('outdoor_location_count'))
ic=diag.get('shared_model_image_calls',{})
print("image_calls predicted/actual:", ic.get('predicted_call_count'), "/", ic.get('actual_call_count'))
cs=diag.get('shared_model_candidate_signals') or []
jd=diag.get('shared_model_judge_decisions') or []
ad=diag.get('shared_model_attach_decisions') or []
print("candidate_signals:", len(cs), "| judge_decisions:", len(jd), "| attach_decisions:", len(ad))
spm=diag.get('seed_prefilter_meta') or {}
print("seed_prefilter_meta count:", len(spm))
def dump(label, seq, keys):
    print(f"\n=== {label} ({len(seq)}) ===")
    for e in seq:
        if isinstance(e,dict):
            print({k:e.get(k) for k in keys if k in e})
        else:
            print(e)
# seed_prefilter_meta: si:shi → meta
print("\n=== seed_prefilter_meta (all) ===")
for k in sorted(spm.keys()):
    v=spm[k]
    print(k, "->", {kk:v.get(kk) for kk in ('why_candidate','location_source','figure_count','framing_scale') if isinstance(v,dict)})
dump("candidate_signals", cs, ('location_id','scene_index','shot_key','seed_lane','is_single_shot','member_keys'))
dump("judge_decisions", jd, ('location_id','scene_index','shot_key','decision_type','needs','confidence','attach','deny_reason','seed_lane','location_source'))
dump("attach_decisions", ad, ('location_id','scene_index','shot_key','attached','reason'))
PY
echo "=== S15/S19 grep in manifest raw ==="
grep -oE '"scene_index": *(15|19)' "$MF" | sort | uniq -c
