Datasets:
File size: 4,714 Bytes
44dc2da | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | #!/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",
"<repository-url>",
"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!")
|