Files
bot/scripts/sync-admin-ui.sh
zeekay f105ffff17 fix: make the published package installable and the CLI actually run
The public repo could not be installed or run, and the two defects share a
cause: a rename left constants pointing at names that do not exist.

Install: @hanzo/iam was pinned to github:hanzo-js/iam#main, a private repo, so
pnpm install failed with ERR_PNPM_FETCH_404 for anyone without access to it —
including CI, which passes no token, so the image install could not have
resolved it either. The package is published, so depend on it from npm. That
leaves no dependency needing credentials, so the Dockerfile's GIT_TOKEN plumbing
goes too; it wrote the token into .npmrc and took it on a build arg, which
docker history keeps.

The SDK names its server-side types Config/AuthResult/JwtClaims, so alias them
to the Iam* names the gateway wrapper exposes. Config is what validateToken and
IamClient accept; IAMConfig is the browser entrypoint's config and does not
belong here.

CLI: package.json declares hanzo-bot.mjs as its bin, but ENTRY_WRAPPER_PAIRS
listed bot.mjs twice and hanzo-bot.mjs never, so isMainModule() saw no pair,
entry.ts skipped its body, and every invocation exited 0 with no output — a
gateway that starts, registers nothing and stops. Derive the pairs from the
bin wrappers and the entry files hanzo-bot.mjs imports, as a cross product, so
a row cannot be duplicated or dropped.

Version: resolveBinaryVersion() skips any package.json whose name is not
CORE_PACKAGE_NAME, which read "bot" while the package ships as @hanzo/bot, so
the package.json path resolved nothing and the version came from build-info.json
alone — absent from a bundle-only build, which then reported 0.0.0.

Both new tests fail when their defect is reintroduced: they assert against the
bins package.json declares and against the real package.json, rather than
restating the value under test.

Also from hanzobot/core: cloud-node detection behind one helper, node-host
reusing startPlaygroundRegistration instead of a second hand-rolled copy, the
playground node API on /v1, and the install smoke tests naming the package
@hanzo/bot rather than the bin name.
2026-07-15 23:25:40 -07:00

65 lines
2.5 KiB
Bash
Executable File

#!/usr/bin/env bash
# sync-admin-ui.sh — sync the admin-bot @hanzo/gui v7 bundle into
# dist/control-ui/ where the Node bot's static handler picks it up.
#
# The bot SPA is built externally in the @hanzo/gui workspace at
# ~/work/hanzo/gui/apps/admin-bot (Vite + @hanzo/gui v7). This script
# copies the built bundle into dist/control-ui/ — matching the path
# the existing Node static handler in src/gateway/control-ui.ts already
# resolves. Reproducible, idempotent, CI-friendly.
#
# Bot is the Node-runtime exception to the Hanzo Go binary contract
# (see ~/work/hanzo/HANZO_BINARY.md). There is no //go:embed step;
# Node serves the SPA directly from dist/control-ui/ at /_/bot/.
#
# Usage:
# scripts/sync-admin-ui.sh # uses ../gui/apps/admin-bot
# ADMIN_BOT_DIR=/path scripts/sync-admin-ui.sh
#
# Exits non-zero if the source dist/ is missing or empty so CI fails
# loud instead of shipping a release with a stale or empty SPA.
set -euo pipefail
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
DEFAULT_SRC="$(cd "${REPO_ROOT}/../gui/apps/admin-bot" 2>/dev/null && pwd || echo "")"
SRC="${ADMIN_BOT_DIR:-${DEFAULT_SRC}}"
DST="${REPO_ROOT}/dist/control-ui"
if [[ -z "${SRC}" || ! -d "${SRC}/dist" ]]; then
echo "error: admin-bot dist not found." >&2
echo " expected: ${SRC:-<unset>}/dist" >&2
echo " build it first: cd \"${SRC:-../gui/apps/admin-bot}\" && bun run build" >&2
echo " or set ADMIN_BOT_DIR=/abs/path/to/admin-bot" >&2
exit 1
fi
if ! ls "${SRC}/dist"/index.html "${SRC}/dist"/assets/*.js >/dev/null 2>&1; then
echo "error: ${SRC}/dist is missing index.html or assets/*.js" >&2
exit 1
fi
mkdir -p "${DST}"
# rsync isn't available on the ARC build runner; emulate
# `rsync -a --delete` with `rm -rf` + `cp -a`.
rm -rf "${DST}"
mkdir -p "${DST}"
cp -a "${SRC}/dist/." "${DST}/"
# Stamp the sync so binaries can be traced back to a build.
{
echo "# auto-generated by scripts/sync-admin-ui.sh — do not edit"
echo "source=${SRC}"
echo "synced_at=$(date -u +%Y-%m-%dT%H:%M:%SZ)"
if command -v git >/dev/null 2>&1 && git -C "${SRC}" rev-parse --short HEAD >/dev/null 2>&1; then
echo "source_commit=$(git -C "${SRC}" rev-parse --short HEAD)"
fi
if command -v git >/dev/null 2>&1 && git -C "${SRC}" status --porcelain >/dev/null 2>&1; then
if [[ -n "$(git -C "${SRC}" status --porcelain || true)" ]]; then
echo "source_dirty=true"
fi
fi
} > "${DST}/.sync-stamp"
echo "synced ${SRC}/dist -> ${DST}"
ls -lh "${DST}/index.html" "${DST}"/assets/*.js "${DST}"/assets/*.css 2>/dev/null || true