Files
hanzoai_agent/control-plane/scripts/sync-admin-ui.sh
zeekay 6aa36a8a36 feat(admin): embedded admin SPA mounted at /_/agents/
Adds the admin chrome surface alongside the existing 79k LOC product
UI. Two embedded FS:
  - web/client/dist  → product UI (deck.gl, react-flow, xterm) at '/'
  - admin/dist       → admin chrome (orgs, keys, billing) at '/_/agents/'

Files:
  admin/embed.go            - //go:embed all:dist + http.Handler
  admin/dist/.gitkeep       - keeps the dir tracked before sync
  scripts/sync-admin-ui.sh  - copies bun-built bundle from
                              ~/work/hanzo/gui/apps/admin-agent/dist
                              into admin/dist before binary build
  .gitignore                - ignore agentd binary, tmp/, .DS_Store

internal/server/server.go: mount admin.Handler() at /_/agents/* when
admin.IsBuilt() (i.e. sync-admin-ui.sh has run). Only conditional —
local dev without the synced bundle keeps building.

Same shape ~/work/hanzo/tasks uses (ui/embed.go + scripts/sync-admin-ui.sh).
2026-04-27 18:56:01 -07:00

61 lines
2.4 KiB
Bash
Executable File

#!/usr/bin/env bash
# sync-admin-ui.sh — sync the admin-agent @hanzo/gui v7 bundle into admin/dist.
#
# The Agents admin SPA is built externally in the @hanzo/gui workspace
# at ~/work/hanzo/gui/apps/admin-agent (Vite + @hanzo/gui v7). This
# script copies the built bundle into admin/dist/ where //go:embed
# picks it up at compile time of cmd/agentd. Reproducible, idempotent,
# CI-friendly.
#
# Two UI surfaces in this repo:
# - product UI → web/client/dist (79k LOC of deck.gl/react-flow/xterm)
# - admin chrome → admin/dist (this script's target)
# The Go binary embeds both and mounts them on different prefixes.
#
# Usage:
# scripts/sync-admin-ui.sh # uses ../../gui/apps/admin-agent
# ADMIN_AGENT_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 binary 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-agent" 2>/dev/null && pwd || echo "")"
SRC="${ADMIN_AGENT_DIR:-${DEFAULT_SRC}}"
DST="${REPO_ROOT}/admin/dist"
if [[ -z "${SRC}" || ! -d "${SRC}/dist" ]]; then
echo "error: admin-agent dist not found." >&2
echo " expected: ${SRC:-<unset>}/dist" >&2
echo " build it first: cd \"${SRC:-../../gui/apps/admin-agent}\" && bun run build" >&2
echo " or set ADMIN_AGENT_DIR=/abs/path/to/admin-agent" >&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 -a --delete "${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