feat(update): integrate managed installs and recoverable in-app updates (#6168)
Add owner-aware Stable and Preview updates with explicit consent, verified release plans, protected process handoff and bounded service recovery. Keep configuration and conversations separate from program rollback. Include the compact About controls, Windows long-path support, native package recovery checks and optional macOS Dock lifecycle integration. Preserve documented guidance for installations owned by other managers. This code integration does not publish packages, enable signing or advance the public update channel. Co-authored-by: chengyongru <61816729+chengyongru@users.noreply.github.com>
This commit is contained in:
1 parent
76da55994b
commit
fbb61a373f
216 files changed
+27948
-1084
No files matched your search
+32
-28
@@ -21,27 +21,22 @@ import zipfile
|
||||
from email.parser import BytesParser
|
||||
from pathlib import Path, PurePosixPath
|
||||
|
||||
from nanobot.cli.tui_launcher import _verified_release_archive
|
||||
# Packaging must use the same archive checks as the installed launcher.
|
||||
from nanobot.cli.tui_launcher import (
|
||||
_verified_release_archive, # pyright: ignore[reportPrivateUsage]
|
||||
)
|
||||
from nanobot.releases import PLATFORMS
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
# Minimums verified against BOTH the Bun executable and its embedded OpenTUI library.
|
||||
# Linux binaries use glibc, not musl; macOS binaries require macOS 13.
|
||||
PLATFORMS = {
|
||||
"darwin-arm64": "macosx_13_0_arm64",
|
||||
"darwin-x64": "macosx_13_0_x86_64",
|
||||
"linux-arm64": "manylinux_2_17_aarch64",
|
||||
"linux-x64": "manylinux_2_17_x86_64",
|
||||
"win32-x64": "win_amd64",
|
||||
}
|
||||
|
||||
|
||||
def _digest(data: bytes) -> str:
|
||||
return "sha256=" + base64.urlsafe_b64encode(hashlib.sha256(data).digest()).rstrip(b"=").decode()
|
||||
|
||||
|
||||
def _source_files(raw: bytes) -> dict[str, bytes]:
|
||||
def source_files(raw: bytes) -> dict[str, bytes]:
|
||||
"""Compare archive contents without extracting any untrusted path to disk."""
|
||||
files = {}
|
||||
files: dict[str, bytes] = {}
|
||||
with tarfile.open(fileobj=io.BytesIO(raw), mode="r:gz") as archive:
|
||||
for member in archive:
|
||||
if member.isdir():
|
||||
@@ -73,10 +68,12 @@ def _verify_architecture(binary: bytes, target: str) -> None:
|
||||
raise ValueError(f"TUI executable architecture does not match {target}")
|
||||
|
||||
|
||||
def _base_files(wheel: Path, version: str) -> tuple[dict[str, bytes], dict[str, int], str]:
|
||||
def wheel_files(wheel: Path, version: str, *, platform: str = "any") -> tuple[dict[str, bytes], dict[str, int], str]:
|
||||
"""Verify identity and every RECORD entry for an intermediate or final wheel."""
|
||||
prefix = f"nanobot_ai-{version}"
|
||||
if wheel.name != f"{prefix}-py3-none-any.whl":
|
||||
raise ValueError(f"Expected the candidate's universal wheel ({version})")
|
||||
if wheel.name != f"{prefix}-py3-none-{platform}.whl":
|
||||
kind = "universal wheel" if platform == "any" else "platform wheel"
|
||||
raise ValueError(f"Expected the candidate's {kind} ({version})")
|
||||
info_dir = f"{prefix}.dist-info"
|
||||
with zipfile.ZipFile(wheel) as archive:
|
||||
names = archive.namelist()
|
||||
@@ -85,7 +82,7 @@ def _base_files(wheel: Path, version: str) -> tuple[dict[str, bytes], dict[str,
|
||||
for name in names:
|
||||
path = PurePosixPath(name)
|
||||
if (path.is_absolute() or ".." in path.parts or "\\" in name
|
||||
or name.startswith("nanobot/tui/bin/")
|
||||
or (platform == "any" and name.startswith("nanobot/tui/bin/"))
|
||||
or name.endswith(("/RECORD.jws", "/RECORD.p7s"))):
|
||||
raise ValueError(f"Unexpected base wheel entry: {name}")
|
||||
files = {name: archive.read(name) for name in names if not name.endswith("/")}
|
||||
@@ -93,8 +90,8 @@ def _base_files(wheel: Path, version: str) -> tuple[dict[str, bytes], dict[str,
|
||||
metadata = BytesParser().parsebytes(files[f"{info_dir}/METADATA"])
|
||||
wheel_metadata = BytesParser().parsebytes(files[f"{info_dir}/WHEEL"])
|
||||
if (metadata["Name"] != "nanobot-ai" or metadata["Version"] != version
|
||||
or wheel_metadata["Root-Is-Purelib"] != "true"
|
||||
or wheel_metadata.get_all("Tag") != ["py3-none-any"]):
|
||||
or wheel_metadata["Root-Is-Purelib"] != ("true" if platform == "any" else "false")
|
||||
or wheel_metadata.get_all("Tag") != [f"py3-none-{platform}"]):
|
||||
raise ValueError("Base wheel metadata does not match the candidate")
|
||||
record = f"{info_dir}/RECORD"
|
||||
rows = list(csv.reader(io.StringIO(files[record].decode())))
|
||||
@@ -107,15 +104,8 @@ def _base_files(wheel: Path, version: str) -> tuple[dict[str, bytes], dict[str,
|
||||
return files, modes, info_dir
|
||||
|
||||
|
||||
def build_wheel(wheel: Path, tui_dir: Path, out_dir: Path, target: str, *,
|
||||
root: Path = ROOT) -> Path:
|
||||
"""Fail closed on stale sources, damaged archives, or existing output files."""
|
||||
version = tomllib.loads((root / "pyproject.toml").read_text())["project"]["version"]
|
||||
tag = f"py3-none-{PLATFORMS[target]}"
|
||||
output = out_dir / f"nanobot_ai-{version}-{tag}.whl"
|
||||
if output.exists():
|
||||
raise FileExistsError(output)
|
||||
files, modes, info_dir = _base_files(wheel, version)
|
||||
def release_bundle(tui_dir: Path, target: str, *, root: Path = ROOT) -> dict[str, bytes]:
|
||||
"""Validate the archive, architecture and corresponding source once at its owner."""
|
||||
asset = f"nanobot-tui-{target}" + (".exe" if target.startswith("win32-") else "")
|
||||
archive = tui_dir / f"{asset}.zip"
|
||||
raw = archive.read_bytes()
|
||||
@@ -130,8 +120,22 @@ def build_wheel(wheel: Path, tui_dir: Path, out_dir: Path, target: str, *,
|
||||
source_packager = runpy.run_path(str(root / "tui/scripts/package-release.py"))
|
||||
source_packager["_validate_opentui_version"](root / "tui", notices)
|
||||
expected_source = source_packager["_source_archive"](root / "tui")
|
||||
if _source_files(bundle["nanobot-tui-source.tar.gz"]) != _source_files(expected_source):
|
||||
if source_files(bundle["nanobot-tui-source.tar.gz"]) != source_files(expected_source):
|
||||
raise ValueError("TUI archive source does not match this release checkout; rebuild it")
|
||||
return bundle
|
||||
|
||||
|
||||
def build_wheel(wheel: Path, tui_dir: Path, out_dir: Path, target: str, *,
|
||||
root: Path = ROOT) -> Path:
|
||||
"""Fail closed on stale sources, damaged archives, or existing output files."""
|
||||
version = tomllib.loads((root / "pyproject.toml").read_text())["project"]["version"]
|
||||
tag = f"py3-none-{PLATFORMS[target]}"
|
||||
output = out_dir / f"nanobot_ai-{version}-{tag}.whl"
|
||||
if output.exists():
|
||||
raise FileExistsError(output)
|
||||
files, modes, info_dir = wheel_files(wheel, version)
|
||||
asset = f"nanobot-tui-{target}" + (".exe" if target.startswith("win32-") else "")
|
||||
bundle = release_bundle(tui_dir, target, root=root)
|
||||
for name, content in bundle.items():
|
||||
path = f"nanobot/tui/bin/{name}"
|
||||
files[path] = content
|
||||
|
||||
Reference in new issue
Block a user