Files
hermes-agent/scripts/bundles/stage.py
BearHuddleston 3944af0ea3
Some checks failed
Deploy Site / deploy-vercel (push) Has been cancelled
Deploy Site / deploy-docs (push) Has been cancelled
auto-fix lint issues & formatting / Generate eslint --fix patch (push) Has been cancelled
auto-fix lint issues & formatting / Apply patch (push) Has been cancelled
Skills Index Freshness Check / check-freshness (push) Has been cancelled
Skills Index Freshness Check / check-catalog-cors (push) Has been cancelled
Docs Search Monitor / probe (push) Has been cancelled
fix(bundles): build the Webapp in source desktop bundles too
`pnpm run dist:bundled` stages its payload through scripts/bundles/stage.py,
not the prepared desktop builder. Its automatic route compiled only the TUI
and dashboard, so a payload stamped `bundled` shipped no Webapp and
`hermes webapp` stopped at "This desktop app ships no Webapp renderer".

Install the Desktop workspace in the frontend snapshot, compile the Webapp
there and pass it to stage_native. The native staging child takes its
products as flags and only knew --tui/--web, so it also learns --webapp;
without that, handing it the Webapp exits 2 on an unrecognized argument.

The regression test runs stage.main through the real stage_native argv into
native.main and asserts the planted payload: red on the PR head (no
dist-webapp), red with stage.py alone changed (argparse exit 2).

Reported by @kvnloo on #154325, whose b294b532 changed stage.py the same way.

Co-authored-by: Kevin Rajan <7121943+kvnloo@users.noreply.github.com>
2026-11-12 14:16:57 -06:00

62 lines
2.7 KiB
Python

"""Select complete frontend products and stage the runnable native agent."""
from __future__ import annotations
import argparse
import os
import shutil
import subprocess
import sys
import tempfile
from pathlib import Path
ROOT = Path(__file__).resolve().parents[2]
if str(ROOT) not in sys.path:
sys.path.insert(0, str(ROOT))
from scripts.bundles.native import stage_native
def main(argv=None) -> int:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--out", required=True)
parser.add_argument("--ref", default="HEAD")
parser.add_argument("--cache", type=Path, help="persistent uv build cache")
parser.add_argument("--tui", type=Path)
parser.add_argument("--web", type=Path)
args = parser.parse_args(argv)
if bool(args.tui) != bool(args.web):
parser.error("supply both --tui and --web products, or neither to build them")
out = Path(args.out).resolve()
out.mkdir(parents=True, exist_ok=True)
(out / "manifest.json").unlink(missing_ok=True)
if args.tui is not None:
args.frontends = {"tui": args.tui.resolve(), "web": args.web.resolve()}
return stage_native(args)
node = shutil.which("node")
if node is None:
raise FileNotFoundError("Node is required to build frontend products")
with tempfile.TemporaryDirectory(prefix="hermes-products-") as temp:
products = Path(temp)
source = products / "source"
from scripts.bundles.payload import snapshot
from scripts.build.icon_environment import prepare_icon_environment
snapshot(ROOT, args.ref, source)
# The staging interpreter need not be a Hermes runtime; render icons on one.
icon_python = prepare_icon_environment(source, products / "icon-environment", args.cache)
env = {**os.environ, "HERMES_PYTHON": str(icon_python)}
commands = [
["scripts/build/node-deps.mjs", "--source", str(source), "--workspace", "ui-tui", "--workspace", "web",
"--workspace", "apps/desktop"],
["scripts/generate-icons.mjs", "--source", str(source), "--out", str(products / "icons")],
["scripts/build/tui.mjs", "--source", str(source), "--out", str(products / "tui")],
["scripts/build/web.mjs", "--source", str(source), "--icons", str(products / "icons"), "--out", str(products / "web")],
["scripts/build/webapp.mjs", "--source", str(source), "--out", str(products / "webapp")],
]
for command in commands:
subprocess.run([node, *command], cwd=ROOT, env=env, check=True)
args.frontends = {name: products / name for name in ("tui", "web", "webapp")}
return stage_native(args)
if __name__ == "__main__":
raise SystemExit(main())