import sqlite3, json
con=sqlite3.connect("/var/lib/friend/friend.db")
con.row_factory=sqlite3.Row
cid="b55ae6a3-6c4e-4105-bfc4-56a97f3bad15"
print("USE", cid)
rows=list(con.execute("select sequence, node_type, content from chain_nodes where chain_id=? order by sequence desc limit 80", (cid,)))
print("rows", len(rows), "latest", rows[0]["sequence"] if rows else None)
for r in rows:
    raw=r["content"]
    name=""
    path=""
    preview=""
    extra=""
    try:
        c=json.loads(raw) if isinstance(raw,(str,bytes)) else raw
        if isinstance(c,str):
            try: c=json.loads(c)
            except Exception:
                pass
        if isinstance(c, dict):
            args=c.get("args") or c.get("arguments") or {}
            if not isinstance(args, dict):
                args={}
            name=str(c.get("name") or c.get("tool_name") or "")
            path=str(args.get("file_path") or c.get("file_path") or "")
            files=c.get("files")
            text=c.get("content") or c.get("text") or ""
            if isinstance(text, str):
                preview=text[:50].replace("\n"," ")
            if files:
                extra=" files="+json.dumps(files, ensure_ascii=False)[:180]
    except Exception as e:
        preview="ERR "+str(e)
    nt=r["node_type"]
    if nt in ("tool_call","transmission","tool_result") or path or extra:
        print("seq=%s type=%s tool=%r path=%r %s%s" % (r["sequence"], nt, name, path, preview, extra))
