A new swarm service, `swarm-claude-login`, in its own container on the host
that sets `deploy.claude-login.enable` (defaulted on by `allSwarmServices`
where the host has the minter's store leaf, like the review classifier).
- swarm-ui: an agent card showing "login needed" gets a "log in" button.
Its dialog starts the login, shows the URL claude printed, and takes the
pasted code.
- swarm-controller: `POST/DELETE /api/agents/{name}/claude-login` and
`POST /api/agents/{name}/claude-login/code`, behind the swarm UI's
authelia-gated `/api/`, relay the steps to the minter as requests on
`$SWARM.claude-login.request`.
- swarm-claude-login: runs `claude auth login` over piped stdio with HOME
and CLAUDE_CONFIG_DIR in a per-login scratch dir, scrapes the first
https URL, writes the code to stdin, and stores the `.credentials.json`
at `swarm/agents/<agent>/claude-credentials` with a KV v2 write, a new
version over any earlier one. The scratch dir goes on every exit path; a
login waits 15 minutes for its code.
- hive-agent: while parked in `wait_for_login`, reads that leaf every 30 s
under the agent's own cert and installs it only when its KV version is
newer than the one recorded in `<harness>/claude-credentials-version`.
An equal or older version is never put back, because claude rotates the
refresh token and the stored copy is stale after the first refresh.
- swarm-secret-client: `claude_login` paths and `SecretStore::read_versioned`.
- Credentials: a `claude-login` store leaf minted by glue-bao-tls, a
`swarm-claude-login` policy (create/update on
`swarm/agents/+/claude-credentials`, read on its own queue client
secret), an authelia machine client, and a `--claude-login-client`
grant in the queue's auth-callout responder. The unit runs as a static
system user.
The hive's own web-UI login is unchanged.
Refs #5268
129 lines
4.7 KiB
TypeScript
129 lines
4.7 KiB
TypeScript
// <AgentCard> — one card per roster agent (mara: "main view: name,
|
|
// status, message, wanted" / "message as second line" / "more like
|
|
// card per agent") — the FilterableView `view === "cards"` alternative
|
|
// to the original `Table`, not its replacement (see `AgentsPage`'s own
|
|
// comment). Clicking a card opens a detail panel repeating this same
|
|
// info plus what doesn't fit here (hive, config-PR link, matrix
|
|
// link-account) — mara: "the info from main list should be included in
|
|
// the agent view" too, not just the leftovers.
|
|
//
|
|
// Built on the shared `Card` primitive (`ui/card/`) for the clickable/
|
|
// selectable-container mechanics — the `stopPropagation` wrapper around
|
|
// `WantedMenu` below keeps its own clicks (mouse or keyboard-synthesized,
|
|
// `WantedMenu` hosts real `<button>`s) from also firing `Card`'s
|
|
// `onClick` and opening the detail panel.
|
|
import { useState } from "preact/hooks";
|
|
import { Badge } from "@hive/shared/badge.js";
|
|
import type { ProblemDetails } from "@hive/shared/api-error.js";
|
|
import { Card } from "../../ui/card/Card.js";
|
|
import { RelativeTime } from "../../ui/relative-time/RelativeTime.js";
|
|
import { AgentIcon } from "../AgentIcon.js";
|
|
import { ClaudeLoginDialog } from "../claude-login/ClaudeLoginDialog.js";
|
|
import { FRESHNESS, showsLoginNeeded, type AgentRow } from "../AgentTypes.js";
|
|
import { WantedMenu } from "./WantedMenu.js";
|
|
import "./AgentCard.css";
|
|
|
|
export function AgentCard({
|
|
row,
|
|
pending,
|
|
error,
|
|
selected,
|
|
onSelectUp,
|
|
onSelectOffline,
|
|
onSelectPaused,
|
|
onOpenDetail,
|
|
}: {
|
|
row: AgentRow;
|
|
pending: boolean;
|
|
error: ProblemDetails | undefined;
|
|
/** This row is the one currently shown in the detail panel — a
|
|
* highlight only (the panel itself is the source of truth), so a
|
|
* page-refresh landing on a still-valid selection reads as obviously
|
|
* "that one" rather than a silent selection nothing marks. */
|
|
selected: boolean;
|
|
onSelectUp: (row: AgentRow) => void;
|
|
onSelectOffline: (row: AgentRow) => void;
|
|
onSelectPaused: (row: AgentRow) => void;
|
|
onOpenDetail: (row: AgentRow) => void;
|
|
}) {
|
|
const { tone, label } = FRESHNESS[row.freshness];
|
|
const [loggingIn, setLoggingIn] = useState(false);
|
|
return (
|
|
<Card selected={selected} onClick={() => onOpenDetail(row)}>
|
|
<div class="ui-agent-card-row">
|
|
<AgentIcon name={row.name} />
|
|
<div class="ui-agent-card-body">
|
|
<div class="ui-agent-card-line1">
|
|
<span class="ui-agent-card-name">{row.name}</span>
|
|
<Badge
|
|
tone={tone}
|
|
title={
|
|
row.freshness === "unknown"
|
|
? "reported by its hive but not registered in swarm-level identity — needs migration"
|
|
: undefined
|
|
}
|
|
value={
|
|
<>
|
|
{label}
|
|
{row.last_seen_unix !== null ? (
|
|
<>
|
|
{" "}
|
|
(<RelativeTime epochMs={row.last_seen_unix * 1000} />)
|
|
</>
|
|
) : null}
|
|
</>
|
|
}
|
|
/>
|
|
{showsLoginNeeded(row) ? (
|
|
<span
|
|
class="ui-agent-card-login"
|
|
onClick={(e) => e.stopPropagation()}
|
|
>
|
|
<Badge
|
|
tone="warning"
|
|
value="login needed"
|
|
title="the agent's claude has no session; its turns wait until it is logged in"
|
|
/>
|
|
<Badge
|
|
variant="quiet"
|
|
value="log in"
|
|
title={`log ${row.name} in to claude from here`}
|
|
onClick={() => setLoggingIn(true)}
|
|
/>
|
|
{loggingIn ? (
|
|
<ClaudeLoginDialog
|
|
agent={row.name}
|
|
onClose={() => setLoggingIn(false)}
|
|
/>
|
|
) : null}
|
|
</span>
|
|
) : null}
|
|
<span
|
|
class="ui-agent-card-wanted"
|
|
onClick={(e) => e.stopPropagation()}
|
|
>
|
|
<WantedMenu
|
|
row={row}
|
|
pending={pending}
|
|
showDestroy={false}
|
|
onSelectUp={onSelectUp}
|
|
onSelectOffline={onSelectOffline}
|
|
onSelectPaused={onSelectPaused}
|
|
/>
|
|
{error ? (
|
|
<Badge
|
|
tone="negative"
|
|
value="failed"
|
|
title={error.detail ?? "the declaration failed"}
|
|
/>
|
|
) : null}
|
|
</span>
|
|
</div>
|
|
<div class="ui-agent-card-message">
|
|
{row.snapshot?.status_text ?? "—"}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</Card>
|
|
);
|
|
}
|