#!/usr/bin/env python3 """Enforce the three-audience documentation contract.""" from __future__ import annotations import re import sys from pathlib import Path from urllib.parse import unquote def fail(message: str) -> None: print(f"ERROR: {message}", file=sys.stderr) raise SystemExit(1) repo = Path(__file__).resolve().parents[1] expected_readmes = {"README.md", "README.zh-CN.md", "README.agent.md"} actual_readmes = {path.name for path in repo.glob("README*.md")} if actual_readmes != expected_readmes: fail( "repository must contain exactly the English human, Chinese human, " f"and Agent README files; found {sorted(actual_readmes)}" ) english = (repo / "README.md").read_text(encoding="utf-8") chinese = (repo / "README.zh-CN.md").read_text(encoding="utf-8") agent = (repo / "README.agent.md").read_text(encoding="utf-8") for label, text in ( ("English human README", english), ("Chinese human README", chinese), ("Agent README", agent), ): if "Agent Phone Use" not in text: fail(f"{label} is missing the product name") for label, text in (("English human README", english), ("Chinese human README", chinese)): if len(text.splitlines()) > 90: fail(f"{label} is too long for the phone-only setup contract") if "```" in text: fail(f"{label} must not make a human copy commands") for forbidden in ( "powershell", "winget", "adb", "mdns", "endpoint", "serial", "mutex", "launcher.log", "-selfcheck", ".ps1", ): if forbidden in text.lower(): fail(f"{label} exposes a computer-side implementation detail: {forbidden}") if len(re.findall(r"\b[\w'-]+\b", english)) > 250: fail("English human README exceeds the 250-word quick-read budget") if len(re.findall(r"[\u4e00-\u9fff]", chinese)) > 450: fail("Chinese human README exceeds the 450-character quick-read budget") for required in ( "developer options", "wireless debugging", "six-digit", "trusted", "agent", "enter it only on the phone", "windows 10/11", "android 11+", "iphone/ipad", "macos/linux", "connect android phone", ): if required not in english.lower(): fail(f"English human README is missing: {required}") for required in ( "开发者选项", "无线调试", "六位", "可信", "Agent", "只在手机上输入", "Windows 10/11", "Android 11", "iPhone/iPad", "macOS/Linux", "连接 Android 手机", ): if required not in chinese: fail(f"Chinese human README is missing: {required}") for required in ( "APU_PAIRING_CODE", "git clone", "", "skill\\agent-phone-use\\SKILL.md", "install.ps1", "publication_scan.py", "pair-android-wireless.ps1", "install-shortcut.ps1", "start-agent-phone-use.ps1", "start-hidden.vbs", "-ToolsOnly", "-SelfCheck", "_adb-tls-pairing._tcp", "_adb-tls-connect._tcp", "new Codex task", "iPhone/iPad", "macOS/Linux", "Connect Android Phone.lnk", "连接 Android 手机.lnk", ): if required not in agent: fail(f"Agent README is missing method or contract token: {required}") for forbidden in ( "$android-wireless-control", "skill/android-wireless-control", "skill\\android-wireless-control", "Android Wireless Control.lnk", "Agent Phone Use.lnk", ): if forbidden in english or forbidden in chinese or forbidden in agent: fail(f"public documentation still exposes the old product identity: {forbidden}") for vendor in ("xiaomi", "redmi"): if vendor in english.lower() or vendor in chinese.lower(): fail(f"human quick-start must not present a manufacturer-specific default: {vendor}") markdown_link = re.compile(r"\[[^\]]+\]\(([^)]+)\)") for markdown_file in (repo / "README.md", repo / "README.zh-CN.md", repo / "README.agent.md"): text = markdown_file.read_text(encoding="utf-8") if "TODO" in text or "[TODO" in text: fail(f"unfinished TODO in {markdown_file.name}") for raw_target in markdown_link.findall(text): target = raw_target.strip("<>") if re.match(r"^(?:https?://|mailto:|#)", target): continue path_text = unquote(target.split("#", 1)[0]) if path_text and not (markdown_file.parent / path_text).resolve().exists(): fail(f"broken relative link in {markdown_file.name}: {target}") print("Documentation contract is valid!")