Watch
0
0
Fork
You've already forked hyperhive
0

ruth is created from a ruth archetype that runs sonnet

This commit is contained in:
atlas 2026-11-11 01:54:01 +01:00
commit 5233259b3b
7 changed files with 236 additions and 115 deletions

View file

@ -34,6 +34,14 @@ export interface Prefill {
inference: InferenceDraft;
}
/** The listed archetype `ref` names, or `undefined` when the list has none. */
export function findArchetype(
list: Archetype[],
ref: { source: string; name: string },
): Archetype | undefined {
return list.find((a) => a.source === ref.source && a.name === ref.name);
}
/** The select's value for `a`; unique across sources. */
export function archetypeKey(a: Archetype): string {
return `${a.source}/${a.name}`;

View file

@ -23,9 +23,10 @@
// shared `ui/` form kit (`TextField`/`SelectField`/`Button`) rather than
// page-scoped input/button chrome — see that kit's own comments for why.
//
// Permissions: checkboxes from `GET /api/permissions`, on the default set plus
// `extraPermissions`; sent only when that differs from the default.
import { useEffect, useState } from "preact/hooks";
// Permissions: checkboxes from `GET /api/permissions`, on the default set or the
// picked archetype's; sent only when that differs from the default. A caller can
// open the form on an archetype with `initialArchetype`.
import { useEffect, useRef, useState } from "preact/hooks";
import { Link } from "wouter-preact";
import { ApiErrorPanel } from "@hive/shared/api-error-panel.js";
import { readApiError, type ProblemDetails } from "@hive/shared/api-error.js";
@ -52,13 +53,13 @@ import { SectionHeading } from "../ui/section-heading/SectionHeading.js";
import { useSubmit } from "../ui/submit/useSubmit.js";
import { MultiselectFilterOptions } from "../ui/multiselect-filter/MultiselectFilter.js";
import {
initialSelection,
requestInternet,
requestPermissions,
togglePermission,
} from "./CreateAgentPermissions.js";
import {
archetypeKey,
findArchetype,
prefill,
requestArchetype,
type ArchetypeList,
@ -103,12 +104,12 @@ interface PermissionCatalogue {
export function CreateAgentForm({
onClose,
initialName = "",
extraPermissions = [],
initialArchetype,
}: {
/** The name field's starting value, for a caller that suggests one. */
initialName?: string;
/** Permissions checked on top of the default set when the form opens. */
extraPermissions?: string[];
/** The archetype the form opens on, once the swarm lists it. */
initialArchetype?: { source: string; name: string };
/** Rendered as the form panel's own close button — this form always
* mounts inside a `plain` `Dialog` (see `AgentsPage`), which no longer
* floats its own. */
@ -181,7 +182,7 @@ export function CreateAgentForm({
}
const data = (await r.json()) as PermissionCatalogue;
setCatalogue(data);
setSelected(initialSelection(data.all, data.default, extraPermissions));
setSelected(data.default);
})().catch((e: unknown) => setCatalogueError({ detail: String(e) }));
}, []);
@ -211,6 +212,21 @@ export function CreateAgentForm({
setInference(p.inference);
}
// Opens on `initialArchetype` once the list and the permission catalogue are
// both in, and only once, so a later pick of "none" stays.
const seeded = useRef(false);
useEffect(() => {
if (seeded.current || !initialArchetype || !archetypes || !catalogue)
return;
seeded.current = true;
const found = findArchetype(archetypes.archetypes, initialArchetype);
if (found) pickArchetype(archetypeKey(found));
}, [archetypes, catalogue]);
const unlisted =
initialArchetype !== undefined &&
archetypes !== null &&
findArchetype(archetypes.archetypes, initialArchetype) === undefined;
const hiveOptions: SelectOption[] = (hives ?? []).map((h) => ({
value: h.name,
label: h.name,
@ -252,14 +268,6 @@ export function CreateAgentForm({
setName("");
setAgentsMd("");
pickArchetype("");
if (catalogue)
setSelected(
initialSelection(
catalogue.all,
catalogue.default,
extraPermissions,
),
);
},
// The text's own refusal shows beside its box, so go back to it.
onError: (problem) => {
@ -376,6 +384,14 @@ export function CreateAgentForm({
: "select a hive"
}
/>
{unlisted && initialArchetype && (
<Hint tone="warn" class="create-agent-field-error">
The swarm does not list the {initialArchetype.name} archetype
yet, so this creates a plain agent with the default
permissions. The list refreshes every 10 minutes; reopen the
form once it has {initialArchetype.name}.
</Hint>
)}
{archetypes && archetypes.archetypes.length > 0 && (
<>
<ArchetypePicker

View file

@ -23,22 +23,6 @@ export function requestPermissions(
return same ? undefined : selected;
}
/**
* The form's starting selection: `defaults` plus each of `extra` the
* catalogue lists (`all`), so a name the controller does not know is not
* sent.
*/
export function initialSelection(
all: string[],
defaults: string[],
extra: string[],
): string[] {
return [
...defaults,
...extra.filter((p) => all.includes(p) && !defaults.includes(p)),
];
}
/**
* The create request's internet field: `unrestricted_internet: true` while
* the box is ticked, nothing otherwise, as the server writes `false` for it.

View file

@ -1,15 +1,12 @@
// <SetupAssistant> - the start page's first-time helper: a paperclip with a
// speech bubble offering to set up an agent. It renders only while the swarm
// has no `ruth` (see `ruthIsMissing`), and a click opens the create-agent
// form with her name filled in and `manage_root_agent`, `logs` and
// `metrics` checked on top of the default permissions (`RUTH_EXTRA_PERMISSIONS`); the form already selects
// the only hive. No dismiss: once ruth exists it goes away.
// form with her name filled in and the `ruth` archetype picked (`RUTH_ARCHETYPE`),
// which fills in her permissions and model; the form already selects the only
// hive. No dismiss: once ruth exists it goes away.
import { useEffect, useState } from "preact/hooks";
import { Dialog } from "../ui/dialog/Dialog.js";
import {
RUTH_EXTRA_PERMISSIONS,
ruthIsMissing,
} from "../shell/ruth-missing.js";
import { RUTH_ARCHETYPE, ruthIsMissing } from "../shell/ruth-missing.js";
import { CreateAgentForm } from "./CreateAgentForm.js";
import "./SetupAssistant.css";
@ -76,7 +73,7 @@ export function SetupAssistant() {
>
<CreateAgentForm
initialName="ruth"
extraPermissions={RUTH_EXTRA_PERMISSIONS}
initialArchetype={RUTH_ARCHETYPE}
onClose={() => setOpen(false)}
/>
</Dialog>

View file

@ -26,10 +26,10 @@ export async function ruthIsMissing(fetchImpl: Fetch): Promise<boolean> {
}
}
/** What the setup assistant's create form checks on top of the default set:
* ruth recovers the other agents, which takes `manage_root_agent`, and reads
* the swarm's logs and metrics, which are off by default. swarm-controller
* refuses `logs` and `metrics` (409, naming the hive) for a hive that does
* not advertise `tolerant-permissions`; the form shows that error, and
* unticking them creates ruth without. */
export const RUTH_EXTRA_PERMISSIONS = ["manage_root_agent", "logs", "metrics"];
/** The archetype the setup assistant's create form starts on. Its `meta`
* gives ruth `manage_root_agent` (she recovers the other agents), `logs` and
* `metrics`, and the model. swarm-controller refuses `logs` and `metrics`
* (409, naming the hive) for a hive that does not advertise
* `tolerant-permissions`; the form shows that error, and unticking them
* creates ruth without. */
export const RUTH_ARCHETYPE = { source: "hyperhive", name: "ruth" };

View file

@ -3,7 +3,6 @@
import assert from "node:assert/strict";
import { test } from "node:test";
import {
initialSelection,
requestInternet,
requestPermissions,
togglePermission,
@ -32,20 +31,6 @@ test("a changed set is sent, an empty one included", () => {
]);
});
const all = [...defaults, "web_tools", "manage_root_agent"];
test("the starting selection is the default plus the known extras", () => {
assert.deepEqual(initialSelection(all, defaults, []), defaults);
assert.deepEqual(initialSelection(all, defaults, ["manage_root_agent"]), [
...defaults,
"manage_root_agent",
]);
assert.deepEqual(
initialSelection(all, defaults, ["meta", "fly_to_the_moon"]),
defaults,
);
});
test("the create box is unticked by default and sends nothing", () => {
assert.deepEqual(requestInternet(false), {});
});

View file

@ -1,15 +1,14 @@
// The setup assistant: its "is ruth missing" check and the permissions it
// creates her with. Run by `npm test`.
// The setup assistant: its "is ruth missing" check and the archetype it
// creates her from. Run by `npm test`.
import assert from "node:assert/strict";
import { test } from "node:test";
import { RUTH_ARCHETYPE, ruthIsMissing } from "../src/shell/ruth-missing.ts";
import {
RUTH_EXTRA_PERMISSIONS,
ruthIsMissing,
} from "../src/shell/ruth-missing.ts";
import {
initialSelection,
requestPermissions,
} from "../src/pages/CreateAgentPermissions.ts";
findArchetype,
prefill,
requestArchetype,
} from "../src/pages/CreateAgentArchetype.ts";
import { requestPermissions } from "../src/pages/CreateAgentPermissions.ts";
const answering =
(body, ok = true) =>
@ -58,27 +57,44 @@ test("anything but a clear answer is not missing", async () => {
);
});
// The assistant's create form sends `manage_root_agent`, `logs` and `metrics` with
// the default set, so a new ruth holds them from her first start; the default
// alone does not.
test("the assistant creates ruth with manage_root_agent, logs and metrics", () => {
const defaults = ["messaging", "meta", "inbox", "execution"];
const all = [
const defaults = ["messaging", "meta", "inbox", "execution"];
const listed = [
{ source: "hyperhive", name: "reviewer", description: "reviews" },
{
source: "hyperhive",
name: "ruth",
description: "manager",
permissions: [...defaults, "manage_root_agent", "logs", "metrics"],
inference: { model: "sonnet" },
},
];
// The assistant's form opens on the `ruth` archetype, so a new ruth is sent
// with the archetype's permissions and model; the default alone has no
// `manage_root_agent`.
test("the assistant creates ruth from the ruth archetype", () => {
const ruth = findArchetype(listed, RUTH_ARCHETYPE);
assert.equal(ruth?.name, "ruth");
const filled = prefill(ruth, defaults);
assert.deepEqual(requestPermissions(filled.permissions, defaults), [
...defaults,
"web_tools",
"manage_root_agent",
"logs",
"metrics",
];
assert.deepEqual(
requestPermissions(
initialSelection(all, defaults, RUTH_EXTRA_PERMISSIONS),
defaults,
),
[...defaults, "manage_root_agent", "logs", "metrics"],
);
]);
assert.equal(filled.inference.model, "sonnet");
assert.deepEqual(requestArchetype(ruth), {
source: "hyperhive",
name: "ruth",
});
});
test("a swarm that does not list the ruth archetype gives none to pick", () => {
assert.equal(findArchetype([listed[0]], RUTH_ARCHETYPE), undefined);
assert.equal(findArchetype([], RUTH_ARCHETYPE), undefined);
// Same name from another source is not hers.
assert.equal(
requestPermissions(initialSelection(all, defaults, []), defaults),
findArchetype([{ ...listed[1], source: "elsewhere" }], RUTH_ARCHETYPE),
undefined,
);
});