"""查 notes 工具到底写到哪、能不能写。 ★ 背景:用户要求"notes 用户要能查看"。 notes.py 里的路径是 `工具文件/../data/notes` —— **相对工具自己算的**。 安卓上工具在 `/storage/emulated/0/Android/data/<包名>/files/tools/`, 于是笔记会落到 `.../files/data/notes`(**App 外部私有目录**, 用户自己用文件管理器看不到,卸载还会被清掉)。 先确认它到底写没写成功、写哪儿了。 """ import json import sys import urllib.error import urllib.request try: sys.stdout.reconfigure(encoding="utf-8", errors="replace") except Exception: pass URL = "http://127.0.0.1:15199" def call(path, payload=None, method="POST", timeout=90): 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"}, ) try: with urllib.request.urlopen(req, timeout=timeout) as r: return json.loads(r.read().decode("utf-8")) except urllib.error.HTTPError as e: return json.loads(e.read().decode("utf-8", "replace")) print("=== 1. 存一条笔记 ===") r = call("/api/tools/run", { "name": "notes", "args": {"action": "save", "title": "测试笔记", "content": "用户能查看吗?"}, }) print(" ", json.dumps(r, ensure_ascii=False)[:300]) print("\n=== 2. 列出来 ===") r = call("/api/tools/run", {"name": "notes", "args": {"action": "list"}}) print(" ", json.dumps(r, ensure_ascii=False)[:400]) print("\n=== 3. 问内核:NOTES_DIR 究竟解析到哪个绝对路径 ===") probe = r''' import os, sys, json sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) TOOL = {"name": "probe_notes", "description": "x", "parameters": {"type": "object", "properties": {}}} def run(args): import notes out = { "NOTES_DIR_raw": notes.NOTES_DIR, "NOTES_DIR_abs": os.path.abspath(notes.NOTES_DIR), "exists": os.path.isdir(os.path.abspath(notes.NOTES_DIR)), "writable": os.access(os.path.abspath(notes.NOTES_DIR), os.W_OK), "tool_file": notes.__file__, } try: items = os.listdir(out["NOTES_DIR_abs"]) out["files"] = items[:10] out["count"] = len(items) except Exception as e: out["listdir_error"] = f"{type(e).__name__}: {e}" return out ''' import base64 D = "/storage/emulated/0/Android/data/com.doubao.lynxclone/files/tools" b64 = base64.b64encode(probe.encode("utf-8")).decode() w = ("import base64,os;" "open(os.path.join('%s','probe_notes.py'),'wb').write(base64.b64decode('%s'));" "print('ok')" % (D, b64)) call("/api/tools/run", {"name": "python_run", "args": {"code": w, "timeout": 30}}) import time time.sleep(1) call("/api/tools", None, "GET") r = call("/api/tools/run", {"name": "probe_notes", "args": {}}) print(" ", json.dumps((r or {}).get("result"), ensure_ascii=False, indent=1)[:900])