"""在内核进程里逐行走一遍 _seed_tools 的逻辑,打印每个文件走哪个分支。 不猜了 —— 把中间量全打出来。 """ import base64 import json import sys import time import urllib.request try: sys.stdout.reconfigure(encoding="utf-8", errors="replace") except Exception: pass URL = "http://127.0.0.1:15199" D = "/storage/emulated/0/Android/data/com.doubao.lynxclone/files/tools" probe_src = ''' import os, sys, json, traceback sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) TOOL = {"name": "probe_trace", "description": "x", "parameters": {"type": "object", "properties": {}}} def run(args): D = %r out = {} try: import doubao_entry as de import bundled_tool_sources as bts except Exception as e: return {"import_err": f"{type(e).__name__}: {e}"} out["has_src_hash"] = hasattr(de, "_src_hash") if not out["has_src_hash"]: return {"verdict": "内核里加载的是**旧** doubao_entry(没有 _src_hash)"} srcs = bts.sources() stamp_path = os.path.join(D, ".doubao-seed.json") try: seeded = json.load(open(stamp_path, encoding="utf-8")) except Exception: seeded = {} out["seeded_keys"] = list(seeded.keys())[:5] out["seeded_count"] = len(seeded) rows = [] for filename in de.BUNDLED_TOOL_FILES: source = srcs.get(filename) dest = os.path.join(D, filename) row = {"name": filename} row["src_present"] = bool(source) if not source: row["branch"] = "no-source" rows.append(row); continue new_hash = de._src_hash(source) row["new_hash"] = new_hash if os.path.exists(dest): current = open(dest, encoding="utf-8").read() cur_hash = de._src_hash(current) row["cur_hash"] = cur_hash row["same"] = (cur_hash == new_hash) row["seeded_for_it"] = seeded.get(filename) row["seeded_matches"] = (seeded.get(filename) == cur_hash) if cur_hash == new_hash: row["branch"] = "skip-same" elif seeded.get(filename) != cur_hash: row["branch"] = "skip-user-edited" else: row["branch"] = "OVERWRITE" else: row["branch"] = "CREATE" rows.append(row) out["rows"] = rows out["summary"] = {} for r in rows: out["summary"][r["branch"]] = out["summary"].get(r["branch"], 0) + 1 return out ''' % D b64 = base64.b64encode(probe_src.encode("utf-8")).decode() def call(path, payload=None, method="POST", timeout=120): data = json.dumps(payload, ensure_ascii=False).encode("utf-8") if payload is not None else None req = urllib.request.Request( URL + path, data=data, method=method, headers={"Content-Type": "application/json; charset=utf-8"}, ) with urllib.request.urlopen(req, timeout=timeout) as r: return json.loads(r.read().decode("utf-8")) w = ( "import base64,os;" "open(os.path.join('%s','probe_trace.py'),'wb').write(base64.b64decode('%s'));" "print('ok')" % (D, b64) ) call("/api/tools/run", {"name": "python_run", "args": {"code": w, "timeout": 30}}, timeout=90) time.sleep(1) call("/api/tools", None, "GET") r = call("/api/tools/run", {"name": "probe_trace", "args": {}}, timeout=120) res = (r or {}).get("result") or {} data = res if isinstance(res, dict) and "rows" in res else json.loads(res.get("stdout") or "{}") print("summary:", json.dumps(data.get("summary"), ensure_ascii=False)) print("has_src_hash:", data.get("has_src_hash")) print("seeded_count:", data.get("seeded_count"), "keys:", data.get("seeded_keys")) print() for row in (data.get("rows") or []): print(" ", row.get("name"), "->", row.get("branch"), "| same=", row.get("same"), "| seeded_matches=", row.get("seeded_matches"))