Watch
0
0
Fork
You've already forked hyperhive
0

swarm-ui: open the terminal, group and flow pages for a malformed address

A name or id that isn't valid percent-encoding (for example /agents/%E0%A4%A/terminal)
made decodeURIComponent throw while the page rendered, leaving a blank page. The
segment now stays as typed, as the agents page already did, so the page opens
(a terminal for that name, disconnected). A tested helper does the decoding.
This commit is contained in:
iris 2026-11-25 19:58:30 +01:00 • committed by mara
commit 79f2d4bd4d
6 changed files with 30 additions and 6 deletions

View file

@ -71,6 +71,9 @@ asks from inside a handler with the `useConfirm` hook, with no dialog state of i
| `/messages` | redirects to `/swarm`, where the messages sit: a folded **message log** card with every message between agents, and to them from the operator, reminders and compaction, with a history window and a filter on sender or recipient; a folded **broadcast** card sends one message to more than one agent at once, and a folded **schedules** card holds the scheduled prompts: add, edit, pause, resume and remove | | `/messages` | redirects to `/swarm`, where the messages sit: a folded **message log** card with every message between agents, and to them from the operator, reminders and compaction, with a history window and a filter on sender or recipient; a folded **broadcast** card sends one message to more than one agent at once, and a folded **schedules** card holds the scheduled prompts: add, edit, pause, resume and remove |
Everything it shows comes from [`swarm-controller`](../../../swarm-controller/README.md). Everything it shows comes from [`swarm-controller`](../../../swarm-controller/README.md).
An agent, subagent or group name in an address that isn't valid percent-encoding
stays as typed, so the page opens, showing a disconnected terminal for that
name, instead of staying blank.
Pages that refresh on a timer share one polling rule: the page sends no new Pages that refresh on a timer share one polling rule: the page sends no new
request while the last one is still running, so an older answer never overtakes request while the last one is still running, so an older answer never overtakes
a slow one, and a failed refresh keeps the rows already on screen under an a slow one, and a failed refresh keeps the rows already on screen under an

View file

@ -32,6 +32,7 @@ import {
import { fetchJson, usePolled } from "../../ui/polled/usePolled.js"; import { fetchJson, usePolled } from "../../ui/polled/usePolled.js";
import { useTermGroups } from "../../agent/terminal/useTermGroups.js"; import { useTermGroups } from "../../agent/terminal/useTermGroups.js";
import { useDynamicTabs } from "../../shell/useDynamicTabs.js"; import { useDynamicTabs } from "../../shell/useDynamicTabs.js";
import { safeDecode } from "../../shell/routes.js";
import { Button } from "../../ui/button/Button.js"; import { Button } from "../../ui/button/Button.js";
import { PaneDropTarget } from "../../ui/pane-tree/PaneDropTarget.js"; import { PaneDropTarget } from "../../ui/pane-tree/PaneDropTarget.js";
import { PaneTree } from "../../ui/pane-tree/PaneTree.js"; import { PaneTree } from "../../ui/pane-tree/PaneTree.js";
@ -40,7 +41,7 @@ import "./AgentGroupPage.css";
export function AgentGroupPage({ export function AgentGroupPage({
params, params,
}: RouteComponentProps<{ id: string }>) { }: RouteComponentProps<{ id: string }>) {
const id = decodeURIComponent(params.id); const id = safeDecode(params.id);
const href = groupHref(id); const href = groupHref(id);
const groups = useTermGroups(); const groups = useTermGroups();
const group = groups.find(id); const group = groups.find(id);

View file

@ -28,6 +28,7 @@ import {
} from "../../agent/terminal/split-layout.js"; } from "../../agent/terminal/split-layout.js";
import { useTermGroups } from "../../agent/terminal/useTermGroups.js"; import { useTermGroups } from "../../agent/terminal/useTermGroups.js";
import { useDynamicTabs } from "../../shell/useDynamicTabs.js"; import { useDynamicTabs } from "../../shell/useDynamicTabs.js";
import { safeDecode } from "../../shell/routes.js";
import { PaneDropTarget } from "../../ui/pane-tree/PaneDropTarget.js"; import { PaneDropTarget } from "../../ui/pane-tree/PaneDropTarget.js";
import "./AgentTerminalPage.css"; import "./AgentTerminalPage.css";
@ -38,11 +39,9 @@ export function AgentTerminalPage({
params, params,
}: RouteComponentProps<{ name: string; subagent?: string }>) { }: RouteComponentProps<{ name: string; subagent?: string }>) {
const { open } = useDynamicTabs(); const { open } = useDynamicTabs();
const name = decodeURIComponent(params.name); const name = safeDecode(params.name);
const subagent = const subagent =
params.subagent === undefined params.subagent === undefined ? undefined : safeDecode(params.subagent);
? undefined
: decodeURIComponent(params.subagent);
const { page, label } = termPaths(name, subagent); const { page, label } = termPaths(name, subagent);
// A subagent has no icon of its own: its tab wears its agent's. // A subagent has no icon of its own: its tab wears its agent's.
useAgentFavicon(name); useAgentFavicon(name);

View file

@ -13,6 +13,7 @@
// on top of the latest. // on top of the latest.
import { useCallback, useEffect, useState } from "preact/hooks"; import { useCallback, useEffect, useState } from "preact/hooks";
import { usePageTitle } from "../../shell/page-title.js"; import { usePageTitle } from "../../shell/page-title.js";
import { safeDecode } from "../../shell/routes.js";
import { import {
Link, Link,
useLocation, useLocation,
@ -71,7 +72,7 @@ export function FlowEditorPage({
// The page for a flow not saved yet, which has no flow id. // The page for a flow not saved yet, which has no flow id.
isNew?: boolean; isNew?: boolean;
}) { }) {
const flowId = decodeURIComponent(params.flowId); const flowId = safeDecode(params.flowId);
const search = new URLSearchParams(useSearch()); const search = new URLSearchParams(useSearch());
const from = search.get("from"); const from = search.get("from");
// With `from` an archetype flow: the one agent this copy is for. // With `from` an archetype flow: the one agent this copy is for.

View file

@ -28,6 +28,19 @@ export function isFullBleedRoute(location: string): boolean {
// which starts a terminal group's path (`/agents/group/:id`). // which starts a terminal group's path (`/agents/group/:id`).
const SELECTED_AGENT_PATTERN = /^\/agents\/([^/]+)$/; const SELECTED_AGENT_PATTERN = /^\/agents\/([^/]+)$/;
/**
* A path segment as text. A segment that isn't valid percent-encoding (a typed
* or mangled address) comes back as it is, so a page can say "no such agent"
* rather than throwing while it renders.
*/
export function safeDecode(segment: string): string {
try {
return decodeURIComponent(segment);
} catch {
return segment;
}
}
/** The agent a path selects on the agents page, or `null` for any other path. */ /** The agent a path selects on the agents page, or `null` for any other path. */
export function selectedAgent(location: string): string | null { export function selectedAgent(location: string): string | null {
const match = SELECTED_AGENT_PATTERN.exec(location); const match = SELECTED_AGENT_PATTERN.exec(location);

View file

@ -7,6 +7,7 @@ import {
isFullBleedRoute, isFullBleedRoute,
movedHref, movedHref,
pageOf, pageOf,
safeDecode,
selectedAgent, selectedAgent,
visibleNavItems, visibleNavItems,
} from "../src/shell/routes.ts"; } from "../src/shell/routes.ts";
@ -113,3 +114,9 @@ test("an agent selected on the agents page is still the agents page", () => {
assert.equal(pageOf("/agents/group/g1"), "/agents/group/g1"); assert.equal(pageOf("/agents/group/g1"), "/agents/group/g1");
assert.equal(pageOf("/jobs"), "/jobs"); assert.equal(pageOf("/jobs"), "/jobs");
}); });
test("a path segment decodes, and a malformed one comes back as typed", () => {
assert.equal(safeDecode("my%20agent"), "my agent");
assert.equal(safeDecode("plain"), "plain");
assert.equal(safeDecode("%E0%A4%A"), "%E0%A4%A");
});