diff --git a/CHANGELOG.md b/CHANGELOG.md index bce17c30e..0fc7f83a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ All notable changes to **omp-web** (`@kahme247/ompweb`) are documented in this f ### Added +- **Rename the cluster.** Settings → Hosts shows the cluster's name with a **Rename cluster** button; the sidebar group follows. The cluster is still created as "Cluster" when the first host joins, so rename it afterwards. `PATCH /api/hosts { poolId, label }` renames a pool without replacing the pool registry. - **Cluster members use this machine's omp configuration.** **Before upgrading:** every cluster member needs an ompweb host daemon at link protocol 10. Until a member's daemon is updated, sessions cannot start there (the start is refused and names the update), cluster placement skips it, a host below protocol 10 cannot join, and Settings → Hosts says it needs an update. Once its daemon is updated, every host already in the first pool receives this machine's configuration, secrets included (API keys, MCP environments and headers, tokens), automatically and without a confirmation having been shown, and its own omp configuration is replaced until it leaves the cluster; it is kept in `/omp-web/own-config/` on the member and put back on leaving. To avoid that for a host, remove it from the first pool (`PUT /api/hosts`, or editing `~/.omp/agent/omp-web/pools.json`) before updating its daemon. Update the web server first, then the members. A cluster session now runs with this machine's settings (`config.yml`, without the machine-specific keys), `models.yml`, MCP servers, skills, task agents, rules and context files, commands, prompts, hooks, extensions, custom tools, `secrets.yml`, `.env`, the agent environment variables of Settings → System, and the installed plugins, whichever member it runs on. A change made here, in Settings or on disk, reaches the members within about a minute and before every session start on a member. Every cluster session start carries this machine's version: a start that must run on one member is refused with the reason when its files cannot be applied, and new sessions are placed only on members with the current configuration and plugins; a session recovered after a daemon restart, or started by another ompweb server, runs on whatever is on the member's disk, and running sessions are not restarted. A mirrored directory becomes equal to this machine's. The member's backup holds only what the host had when it joined: a file it adds or edits afterwards is deleted at the next apply, not backed up. Settings that describe the machine itself stay the member's own as they were when the host joined (see the README). A host holds one ompweb server's configuration: a host already in another server's cluster cannot join (409 `host_in_other_cluster`), and a member that also runs sessions for another server runs them on this one's configuration. The configuration contains secrets, which are written to every member's disk, readable by the daemon's user only; the hooks, extensions, tools and plugins in it run on every member, and this machine can already start omp with full tool access there. Each file is limited to 5 MiB and the configuration to 50 MiB; a configuration over a limit, or one that cannot be read, is not mirrored at all, a cluster session start on a member is refused (409 `cluster_config_invalid`), placement skips every member, and Settings names the file. Each download has a 30 s limit including the body (a 5 MiB file needs roughly 1.4 Mbit/s). An apply is refused on a member where `~/.agents` is a symbolic link, and the mirrored directories and the backup must be on one filesystem. The reverse proxy must pass `/api/hosts/cluster-config/manifest` and `/api/hosts/cluster-config/file/` without its own authentication, at exactly these paths (unlike the broker's prefix). diff --git a/app/api/hosts/route.ts b/app/api/hosts/route.ts index e0736420c..64ad1d072 100644 --- a/app/api/hosts/route.ts +++ b/app/api/hosts/route.ts @@ -141,6 +141,7 @@ export async function POST(req: Request) { export async function PATCH(req: Request) { const body = await readBody(req); + if (body && body.poolId !== undefined) return renamePool(body); if (!body || typeof body.id !== "string" || !body.id) return fail("id is required", 400); const isLocal = body.id === "local"; if (isLocal && body.allowAgentStart !== undefined) return fail("This machine's agent-start setting cannot be changed", 400); @@ -162,6 +163,29 @@ export async function PATCH(req: Request) { } } +/** `{ poolId, label }`: renames one pool (the cluster) without replacing the registry the way PUT does. */ +function renamePool(body: Record) { + if (!hasOnlyKeys(body, ["poolId", "label"]) || typeof body.poolId !== "string") return fail("poolId and label are required", 400); + const label = parseLabel(body.label); + if (!label) return fail(`label must be a non-empty string of at most ${MAX_LABEL_LENGTH} characters`, 400); + let pools: HostPool[]; + try { + pools = loadPools(); + } catch { + return poolStorageFailure(); + } + const pool = pools.find((candidate) => candidate.id === body.poolId); + if (!pool) return fail("Unknown pool", 404); + pool.label = label; + try { + savePools(pools); + } catch { + return poolStorageFailure(); + } + notifyHostsChange(); + return Response.json({ pools }, { headers: noStore }); +} + export async function DELETE(req: Request) { const id = new URL(req.url).searchParams.get("id"); if (!id) return fail("id is required", 400); diff --git a/components/HostsConfig.tsx b/components/HostsConfig.tsx index cf887a34b..c72b7d458 100644 --- a/components/HostsConfig.tsx +++ b/components/HostsConfig.tsx @@ -16,7 +16,7 @@ import { useHostRows } from "@/hooks/useHostRows"; import { HOST_STATUS_COLOR, hostName, hostStatusText, isLocalRow, localInstallCommand } from "./host-status"; import { HostUpdates } from "./HostUpdates"; -type Dialogs = { kind: "add" } | { kind: "rename"; host: HostRow } | null; +type Dialogs = { kind: "add" } | { kind: "rename"; host: HostRow } | { kind: "renameCluster"; pool: HostPool } | null; const inputStyle = { width: "100%", padding: "7px 9px", border: "1px solid var(--border)", borderRadius: "var(--radius-control)", background: "var(--bg)", color: "var(--text)", font: "13px var(--font-mono)" } as const; const buttonStyle = { padding: "6px 14px", background: "none", border: "1px solid var(--border)", borderRadius: "var(--radius-control)", color: "var(--text-muted)", cursor: "pointer", fontSize: 13 } as const; @@ -51,12 +51,12 @@ export function CopyField({ label, value }: { label: string; value: string }) { ); } -/** Name form shared by "Add host" and "Rename"; adding ends in the one-time token view. */ +/** Name form shared by "Add host" and "Rename" (a host or the cluster); adding ends in the one-time token view. */ function HostDialog({ dialog, onClose }: { dialog: NonNullable; onClose: () => void }) { const { t } = useI18n(); const adding = dialog.kind === "add"; const local = dialog.kind === "rename" && dialog.host.id === "local"; - const [label, setLabel] = useState(dialog.kind === "rename" ? dialog.host.label : ""); + const [label, setLabel] = useState(dialog.kind === "rename" ? dialog.host.label : dialog.kind === "renameCluster" ? dialog.pool.label : ""); const [busy, setBusy] = useState(false); const hintId = useId(); const [created, setCreated] = useState<{ token: string; command: string } | null>(null); @@ -68,6 +68,9 @@ function HostDialog({ dialog, onClose }: { dialog: NonNullable; onClose if (dialog.kind === "add") { const data = await call("POST", "/api/hosts", { label }); setCreated({ token: String(data.token), command: String(data.command) }); + } else if (dialog.kind === "renameCluster") { + await call("PATCH", "/api/hosts", { poolId: dialog.pool.id, label }); + onClose(); } else { await call("PATCH", "/api/hosts", { id: dialog.host.id, label }); onClose(); @@ -79,7 +82,7 @@ function HostDialog({ dialog, onClose }: { dialog: NonNullable; onClose } }; - const title = created || adding ? t("hostsConfig.addTitle") : t("hostsConfig.renameTitle"); + const title = created || adding ? t("hostsConfig.addTitle") : dialog.kind === "renameCluster" ? t("hostsConfig.renameClusterTitle") : t("hostsConfig.renameTitle"); return ( // The token is shown once: only Done may close it, never Escape or an outside press. { if (!open && !created) onClose(); }}> @@ -305,7 +308,8 @@ export function HostsConfig() { const localBlock = poolsLoaded && localJoins && local ? joinBlock(local) : null; const localReason = !local || localBlock === null ? null : localBlock === "omp-old" ? t("hostsConfig.joinOmpOld", { name: hostName(t, local) }) : t("hostsConfig.joinLocalRestart"); - const linkedMembers = clusterOf(pools)?.members.some((member) => member.hostId !== LOCAL_HOST_ID) ?? false; + const cluster = clusterOf(pools); + const linkedMembers = cluster?.members.some((member) => member.hostId !== LOCAL_HOST_ID) ?? false; const share = async () => { if (!sharing) return; @@ -364,6 +368,14 @@ export function HostsConfig() {