"""删掉 AgentsScreen 里那个被全屏界面取代的 AgentEditDialog。 ★ 带断言:首尾内容对不上就整个中止,一个字节都不写。 这个仓库里"按行号剪贴算错下标"的坑踩过(把整个文件追加过一遍), 所以任何批量删除都必须先断言。 用法: python scripts/migrate-drop-agent-dialog.py # 预演 python scripts/migrate-drop-agent-dialog.py --write """ import io import os import sys try: sys.stdout.reconfigure(encoding="utf-8", errors="replace") except Exception: pass HERE = os.path.dirname(os.path.abspath(__file__)) KT = os.path.join( HERE, "..", "android", "app", "src", "main", "java", "com", "doubao", "lynxclone", "ui", "AgentsScreen.kt", ) def main(): write = "--write" in sys.argv with io.open(KT, encoding="utf-8") as fh: lines = fh.read().split("\n") start = None for i, line in enumerate(lines): if line.startswith("private fun AgentEditDialog("): # 连它上面的 @Composable 一起删 start = i - 3 if i >= 3 and lines[i - 3].strip() == "@Composable" else i break if start is None: print("找不到 AgentEditDialog —— 可能已经删过了") return 1 # 结束:下一个顶层 private fun / @Composable 之前 end = None for j in range(start + 1, len(lines)): s = lines[j] if s.startswith("private fun ") or s.startswith("fun ") or s.startswith("internal fun "): end = j break if end is None: print("找不到下一个顶层函数,无法确定结束位置") return 1 print(f"将删除第 {start + 1} 行到第 {end} 行(共 {end - start} 行)") print(f" 起始:{lines[start].strip()[:70]}") print(f" 末行:{lines[end - 1].strip()[:70]}") print(f" 下一段:{lines[end].strip()[:70]}") # 断言:这段里必须有 AgentEditDialog 的特征 body = "\n".join(lines[start:end]) for must in ("AgentEditDialog", "AlertDialog", "onSave", "systemPrompt"): if must not in body: print(f"!! 断言失败:待删段落里没有 {must}") return 1 if not write: print("(预演模式,没有写文件。加 --write 才真写)") return 0 del lines[start:end] with io.open(KT, "w", encoding="utf-8", newline="") as fh: fh.write("\n".join(lines)) print(f"已写入,剩 {len(lines)} 行") return 0 if __name__ == "__main__": sys.exit(main())