#!/bin/bash
export LC_ALL=C.UTF-8
python3 - <<'PY'
import sqlite3, re, json
c = sqlite3.connect('/tmp/n8n_exec.db')

for eid in (191, 190, 189):
    raw = c.execute("""select d.data from execution_entity e join execution_data d
                       on d.executionId=e.id where e.id=?""", (eid,)).fetchone()
    if not raw: continue
    text = raw[0] if isinstance(raw[0], str) else str(raw[0])
    print(f"\n===== exec {eid} =====")
    print("  occurrences of 'SariDataSheet':", text.count('SariDataSheet'))
    print("  'اطلاعات کافی در پایگاه دانش':", text.count('اطلاعات کافی در پایگاه دانش'))
    print("  'tool' nodes mentioned:", len(re.findall(r'ai_tool|toolVectorStore|retrieve-as-tool', text)))
    # show a window around the first SariDataSheet hit
    idx = text.find('SariDataSheet')
    if idx > 0:
        print("  ...", text[max(0,idx-200):idx+300].replace('\\n',' ')[:480])
PY
