fix(bundles): ship the WhatsApp bridge in the sealed payload

Excluding scripts/ also dropped scripts/whatsapp-bridge, so Store and desktop builds parked WhatsApp. Archive that runtime tree back in after the exclude.
This commit is contained in:
xxxigm
2026-11-11 22:22:10 +07:00
committed by Austin Pickett
parent 08b61240ec
commit 79c00f3aa2

View File

@@ -16,18 +16,42 @@ if str(ROOT) not in sys.path:
sys.path.insert(0, str(ROOT))
# Snapshot dirs the sealed agent payload never reads. Tests, docs and CI
# definitions never ship; the frontend/desktop sources and build scripts are
# prebuilt by CI into staged products (AgentInputs.frontends) — a sealed
# payload never re-enters the source-build graph (is_bundled_payload routes
# updates to the channel updater), and linux_desktop_entry degrades to the
# themed icon when apps/desktop/assets is absent. Excluded here means:
# not packaged, not compiled, not baked. Frontend product staging
# (scripts/bundles/stage.py) needs its full tree and passes no exclusions.
# Snapshot dirs the sealed agent payload never reads, except
# SNAPSHOT_RUNTIME_TREES. Tests, docs and CI definitions never ship; the
# frontend/desktop sources and build scripts are prebuilt by CI into staged
# products (AgentInputs.frontends) — a sealed payload never re-enters the
# source-build graph (is_bundled_payload routes updates to the channel
# updater), and linux_desktop_entry degrades to the themed icon when
# apps/desktop/assets is absent. Excluded here means: not packaged, not
# compiled, not baked. Frontend product staging (scripts/bundles/stage.py)
# needs its full tree and passes no exclusions.
INERT_SNAPSHOT_DIRS = (
"tests", "tests-js", "website", "evals", ".github", "nix", "docker",
"apps", "ui-tui", "web", "scripts",
)
# The WhatsApp adapter reads scripts/whatsapp-bridge/bridge.js at runtime.
# The rest of scripts/ stays out; this tree is archived back in after the exclude.
SNAPSHOT_RUNTIME_TREES = ("scripts/whatsapp-bridge",)
def _runtime_trees_hidden_by(exclude: tuple[str, ...]) -> tuple[str, ...]:
hidden = []
for tree in SNAPSHOT_RUNTIME_TREES:
top = tree.split("/", 1)[0]
if top in exclude or tree in exclude:
hidden.append(tree)
return tuple(hidden)
def _write_git_archive(repo: Path, ref: str, archive: Path, paths: list[str]) -> None:
subprocess.run(
["git", "archive", "--format=tar", "--output", str(archive), ref, "--", *paths],
cwd=repo, check=True)
def _extract_archive(archive: Path, destination: Path) -> None:
with tarfile.open(archive) as source:
source.extractall(destination, filter="data")
def snapshot(repo: Path, ref: str, destination: Path, exclude: tuple[str, ...] = ()) -> None:
@@ -36,16 +60,17 @@ def snapshot(repo: Path, ref: str, destination: Path, exclude: tuple[str, ...] =
if repo == destination or repo.is_relative_to(destination):
raise ValueError("the snapshot destination must not contain the source checkout")
with tempfile.TemporaryDirectory(prefix="hermes-archive-") as temp:
archive = Path(temp) / "source.tar"
pathspecs = [f":(exclude){name}" for name in exclude]
subprocess.run(
["git", "archive", "--format=tar", "--output", str(archive), ref, "--", *pathspecs],
cwd=repo, check=True)
temp_dir = Path(temp)
archive = temp_dir / "source.tar"
_write_git_archive(repo, ref, archive, [f":(exclude){name}" for name in exclude])
if destination.exists():
shutil.rmtree(destination)
destination.mkdir(parents=True)
with tarfile.open(archive) as source:
source.extractall(destination, filter="data")
_extract_archive(archive, destination)
for index, tree in enumerate(_runtime_trees_hidden_by(exclude)):
runtime = temp_dir / f"runtime-{index}.tar"
_write_git_archive(repo, ref, runtime, [tree])
_extract_archive(runtime, destination)
def _payload_file(root: Path, relative: str) -> Path: