Skip to content

The agent that grows with you

feat(dashboard): "Migrate to a single multiplexed gateway" on the System page

Tekniumdf95f378a6bd
diff --git a/hermes_cli/web_routers/actions.py b/hermes_cli/web_routers/actions.py
index c135e7219f8..7757b2366cc 100644
--- a/hermes_cli/web_routers/actions.py
+++ b/hermes_cli/web_routers/actions.py
@@ -143,6 +143,24 @@ async def restart_gateway(profile: Optional[str] = None):
return {"ok": True, "pid": proc.pid, "name": "gateway-restart"}
[email protected]("/api/gateway/migrate/plan")
+async def gateway_migrate_plan():
+ """Preflight for folding per-profile gateways into one multiplexer (same JSON as the CLI plan)."""
+ from hermes_cli.gateway_migrate import build_migration_plan
+ plan = await asyncio.to_thread(build_migration_plan)
+ return plan.to_dict()
+
+
[email protected]("/api/gateway/migrate")
+async def gateway_migrate():
+ """Run ``hermes gateway migrate --multiplex --yes`` detached; the CLI re-runs the preflight and
+ refuses (exit 1 into the action log) when blocked, so the UI should gate on the plan first."""
+ from hermes_cli.web_server_gateway import _spawn_hermes_action
+ with http_failure("Failed to spawn gateway migrate", 500, "Failed to start gateway migration"):
+ proc = _spawn_hermes_action(["gateway", "migrate", "--multiplex", "--yes"], "gateway-migrate")
+ return {"ok": True, "pid": proc.pid, "name": "gateway-migrate"}
+
+
@router.post("/api/gateway/drain")
async def gateway_drain(request: Request):
"""Begin or cancel an external (NAS-driven) gateway drain.
diff --git a/hermes_cli/web_server_gateway.py b/hermes_cli/web_server_gateway.py
index 9c9d442962c..e7763b8af95 100644
--- a/hermes_cli/web_server_gateway.py
+++ b/hermes_cli/web_server_gateway.py
@@ -262,6 +262,7 @@ _ACTION_LOG_FILES: Dict[str, str] = {
"gateway-restart": "gateway-restart.log",
"gateway-start": "gateway-start.log",
"gateway-stop": "gateway-stop.log",
+ "gateway-migrate": "gateway-migrate.log",
"hermes-update": "hermes-update.log",
**{name: f"action-{name}.log" for name in (
"doctor", "security-audit", "backup", "import", "checkpoints-prune", "skills-install",
diff --git a/web/src/lib/api.ts b/web/src/lib/api.ts
index bf38969ceb0..a5275a6ac49 100644
--- a/web/src/lib/api.ts
+++ b/web/src/lib/api.ts
@@ -956,6 +956,10 @@ export const api = {
// Gateway / update actions
restartGateway: () =>
fetchJSON<ActionResponse>("/api/gateway/restart", { method: "POST" }),
+ getGatewayMigratePlan: () =>
+ fetchJSON<GatewayMigratePlan>("/api/gateway/migrate/plan"),
+ migrateGatewayToMultiplex: () =>
+ fetchJSON<ActionResponse>("/api/gateway/migrate", { method: "POST" }),
updateHermes: () =>
fetchJSON<ActionResponse>("/api/hermes/update", { method: "POST" }),
checkHermesUpdate: (force = false) =>
@@ -1355,6 +1359,16 @@ export interface AuthMeResponse {
expires_at: number;
}
+/** Preflight for `hermes gateway migrate --multiplex` (mirrors the CLI plan JSON). */
+export interface GatewayMigratePlan {
+ already_multiplexed: boolean;
+ blockers: string[];
+ command: string;
+ eligible: boolean;
+ notices: string[];
+ profiles: { profile: string; pid: number | null; service: { kind: string; system: boolean } | null }[];
+}
+
export interface ActionResponse {
archive?: string;
name: string;
diff --git a/web/src/pages/SystemPage.tsx b/web/src/pages/SystemPage.tsx
index ff52c16ca9a..d70ec26203d 100644
--- a/web/src/pages/SystemPage.tsx
+++ b/web/src/pages/SystemPage.tsx
@@ -59,6 +59,7 @@ import type {
CuratorStatus,
PortalStatus,
DebugShareResponse,
+ GatewayMigratePlan,
} from "@/lib/api";
function formatBytes(n: number): string {
@@ -207,6 +208,7 @@ export default function SystemPage() {
const [activeAction, setActiveAction] = useState<string | null>(null);
const [consoleOpen, setConsoleOpen] = useState(false);
+ const [migratePlan, setMigratePlan] = useState<GatewayMigratePlan | null>(null);
// Add-credential form.
const [credProvider, setCredProvider] = useState("openrouter");
@@ -266,8 +268,9 @@ export default function SystemPage() {
// Cached (non-forced) check so the version row shows update status on
// load without a separate effect / a forced network round-trip.
api.checkHermesUpdate(false),
+ api.getGatewayMigratePlan(),
])
- .then(([s, st, m, p, c, h, cur, prt, upd]) => {
+ .then(([s, st, m, p, c, h, cur, prt, upd, mig]) => {
if (s.status === "fulfilled") setStatus(s.value);
if (st.status === "fulfilled") setStats(st.value);
if (m.status === "fulfilled") setMemory(m.value);
@@ -277,6 +280,7 @@ export default function SystemPage() {
if (cur.status === "fulfilled") setCurator(cur.value);
if (prt.status === "fulfilled") setPortal(prt.value);
if (upd.status === "fulfilled") setUpdateInfo(upd.value);
+ if (mig.status === "fulfilled") setMigratePlan(mig.value);
})
.finally(() => setLoading(false));
}, []);
@@ -305,6 +309,17 @@ export default function SystemPage() {
}
};
+ const migrateToMultiplex = async () => {
+ try {
+ await api.migrateGatewayToMultiplex();
+ setActiveAction("gateway-migrate");
+ showToast("Migrating to a single multiplexed gateway", "success");
+ setTimeout(loadAll, 5000);
+ } catch (e) {
+ showToast(`Gateway migration failed: ${e}`, "error");
+ }
+ };
+
// ── Curator ────────────────────────────────────────────────────────
const toggleCuratorPaused = async () => {
if (!curator) return;
@@ -1081,6 +1096,29 @@ export default function SystemPage() {
</Button>
</div>
</CardContent>
+ {migratePlan && !migratePlan.already_multiplexed && migratePlan.profiles.length > 1 && (
+ migratePlan.eligible || migratePlan.blockers.length > 0
+ ) && (
+ <CardContent className="flex flex-col gap-2 border-t border-border py-4 text-sm">
+ <div className="flex items-center justify-between gap-3">
+ <span className="text-muted-foreground">
+ Your profiles each run their own gateway. One multiplexed gateway serves every profile from a single process.
+ </span>
+ <Button
+ size="sm"
+ className="uppercase"
+ onClick={migrateToMultiplex}
+ disabled={!migratePlan.eligible}
+ title={migratePlan.eligible ? undefined : "Fix the blockers below first"}
+ >
+ Migrate to a single multiplexed gateway
+ </Button>
+ </div>
+ {migratePlan.blockers.map((b) => (
+ <div key={b} className="text-warning">• {b}</div>
+ ))}
+ </CardContent>
+ )}
</Card>
</section>