Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 31 additions & 17 deletions docs/features/dashboard.md

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion docs/reference/operations/memory.md
Original file line number Diff line number Diff line change
Expand Up @@ -1564,11 +1564,12 @@ List facts on trial (written with memory.set proposed=true) with the graded runs
| `tags` | `list[str]` | *(computed)* | Only proposals carrying any of these tags; empty = no tag filter. |
| `only` | `Literal['', 'ready']` | `''` | `ready` keeps only proposals the policy thresholds would decide now (accept or reject); "" lists every proposal. |
| `limit` | `int` | `50` | At most this many proposals returned, newest first. |
| `count_only` | `bool` | `False` | A badge or a tab count needs the number, not the rows. |

| Output field | Type | Meaning |
| --- | --- | --- |
| `proposals` | `list[MemoryProposal]` | The proposals in scope, newest first, with graded counts and `ready`. |
| `total` | `int` | Proposals in scope before `only` and `limit`. |
| `total` | `int` | Proposals in scope before `only` and `limit` — on a listing, capped by the scan cap; on a `count_only` call, the full uncapped in-scope count. |
| `policy` | `ProposalPolicy` | The namespace's proposal policy: `mode` (manual / auto) and thresholds. |

## `memory.provenance`
Expand Down
4 changes: 3 additions & 1 deletion frontend/e2e/navigation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ test("the collapsed rail reads the review-queue and agents counts in the link na
await page.route("**/v1/conflicts.list", (r) => r.fulfill({ json: { rows: [], total: 3 } }));
await page.route("**/v1/agents.connected", (r) => r.fulfill({ json: { new_count: 2 } }));
await page.goto("/memories");
await expect(page.getByRole("link", { name: "Review queue, 3" })).toBeVisible();
// The rail shows the Review queue twice — its stable Memory entry and the admin entry
// when items wait — so the count is read from the first of them.
await expect(page.getByRole("link", { name: "Review queue, 3" }).first()).toBeVisible();
await expect(page.getByRole("link", { name: "Agents, 2" })).toBeVisible();
});

Expand Down
9 changes: 5 additions & 4 deletions frontend/e2e/route-budget.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ test.beforeAll(({ browser }, testInfo) => warmUp(browser, testInfo));

const LCP_BUDGET_MS = 2000;
const LONG_TASK_BUDGET_MS = 1500;
// Every route reads at most 12 times, the sidebar's Auto-resolved audit.list included
// (Settings, Conversations, Tasks, Review queue and Usage). The budget is that ceiling
// plus one read of headroom, so a second new read on any route fails here.
const CALL_BUDGET = 13;
// Every route reads at most 13 times, the sidebar's Auto-resolved audit.list and pending
// proposal count included (Settings, Conversations, Tasks, Review queue and Usage). The
// budget is that ceiling plus one read of headroom, so a second new read on any route
// fails here.
const CALL_BUDGET = 14;

const ROUTES: Array<[string, string]> = [
["Memories", "/memories"],
Expand Down
7 changes: 6 additions & 1 deletion frontend/e2e/shell-layout.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ for (const width of [1400, 375]) {
const current = page.locator(
"main [aria-current='page'], main [role='tab'][aria-selected='true'], main [aria-label='Show the documents of']",
);
const tab = (await current.count()) > 0 ? (await current.first().textContent())?.trim() : undefined;
// A tab that carries a count reads "Conflicts (2)"; the document title names the
// tab without the count, so the expected title strips it.
const tab =
(await current.count()) > 0
? (await current.first().textContent())?.trim().replace(/\s*\(\d+\)$/, "")
: undefined;
await expect(page).toHaveTitle(tab && tab !== h1 ? `${tab} · ${h1} · Loom` : `${h1} · Loom`);
// Click UI draws an icon, a badge and an ellipsis as a <div>: none sits in a <p>.
const blocksInText = await page.evaluate(() =>
Expand Down
10 changes: 8 additions & 2 deletions frontend/src/App.boot.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,10 @@ describe("a link's namespace", () => {
expect(calls.some((c) => c.body?.namespace === "group-b-shared")).toBe(false);
expect(
calls.filter((c) => c.path.startsWith("memory.")).map((c) => ({ path: c.path, namespace: c.body?.namespace })),
).toEqual([{ path: "memory.auto_retirements", namespace: NS }]);
).toEqual([
{ path: "memory.proposals", namespace: NS },
{ path: "memory.auto_retirements", namespace: NS },
]);
expect(localStorage.getItem("loom_namespace_v1")).toBe(NS);
expect(savedDefault()).toBe(false);
// Continue: the page the link asked for, on the namespace the picker shows.
Expand Down Expand Up @@ -642,7 +645,10 @@ describe("a link's namespace", () => {
expect(calls.some((c) => c.body?.namespace === "joined")).toBe(false);
expect(
calls.filter((c) => c.path.startsWith("memory.")).map((c) => ({ path: c.path, namespace: c.body?.namespace })),
).toEqual([{ path: "memory.auto_retirements", namespace: NS }]);
).toEqual([
{ path: "memory.proposals", namespace: NS },
{ path: "memory.auto_retirements", namespace: NS },
]);
});

it("when the membership read fails, a reload still opens the saved pick: the server answers its reads", async () => {
Expand Down
21 changes: 16 additions & 5 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ import { Sidebar } from "./layout/Sidebar";
import { Header } from "./layout/Header";
import { MobileNav } from "./layout/MobileNav";
import { ToastViewport, toast, toastError } from "./components/Toast";
import { ConfirmViewport } from "./components/ConfirmDialog";
import { PendingRequestBanner } from "./components/PendingRequestBanner";
import {
assistantAddress,
assistantPopstate,
Expand Down Expand Up @@ -116,6 +114,13 @@ const ProfileSectionDialog = lazy(() =>
);
const TokenGate = lazy(() => import("./flows/TokenGate").then((m) => ({ default: m.TokenGate })));
const LinkTokenConfirm = lazy(() => import("./flows/TokenGate").then((m) => ({ default: m.LinkTokenConfirm })));
// The confirm dialog and the pending-request banner open on demand, not at boot, so their
// chunks load on the first open, not with the shell (keeps the index chunk inside its
// bundle budget).
const ConfirmViewport = lazy(() => import("./components/ConfirmDialog").then((m) => ({ default: m.ConfirmViewport })));
const PendingRequestBanner = lazy(() =>
import("./components/PendingRequestBanner").then((m) => ({ default: m.PendingRequestBanner })),
);
// The expired-session card's chunk is fetched as the app loads, from the build that served
// it: it shows on a long-lived tab, the one most likely to predate a deploy, and a chunk
// first asked for then would be gone and its stale-chunk reload would lose the page.
Expand Down Expand Up @@ -580,7 +585,9 @@ export default function App() {
<TokenGate onLogin={() => location.reload()} reason={gateReason} ssoAsked={ssoAsked} />
</Suspense>
<ToastViewport />
<ConfirmViewport />
<Suspense fallback={null}>
<ConfirmViewport />
</Suspense>
</>
);
}
Expand Down Expand Up @@ -634,7 +641,9 @@ export default function App() {
<Suspense fallback={null}>
<ProblemsBanner />
</Suspense>
<PendingRequestBanner />
<Suspense fallback={null}>
<PendingRequestBanner />
</Suspense>
{/* Keyed by view so each navigation replays the fade-in, and the no-access
page is a page of its own: leaving it mounts the view afresh, never under
the hidden old page. `h-full`
Expand Down Expand Up @@ -699,7 +708,9 @@ export default function App() {
) : null
}
/>
<ConfirmViewport />
<Suspense fallback={null}>
<ConfirmViewport />
</Suspense>
</div>
);
}
Expand Down
28 changes: 27 additions & 1 deletion frontend/src/api/review.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { afterEach, describe, expect, it, vi } from "vitest";
import { collapseMemoryDuplicates, consolidateMemories, listMemoryDuplicates, listProposals } from "./review";
import {
collapseMemoryDuplicates,
consolidateMemories,
countPendingProposals,
listMemoryDuplicates,
listProposals,
} from "./review";

afterEach(() => {
vi.unstubAllGlobals();
Expand Down Expand Up @@ -30,3 +36,23 @@ describe("review requests", () => {
expect(sent.get("memory.proposals")).toMatchObject({ ...scope, limit: 100 });
});
});

describe("the pending-proposal count", () => {
it("asks for a bounded server-side count (count_only, one row's worth of shape), not a page of bodies", async () => {
const fetchMock = vi.fn(async (_url: string, _init?: RequestInit) => Response.json({ total: 7 }));
vi.stubGlobal("fetch", fetchMock);
const n = await countPendingProposals(scope);
expect(n).toBe(7);
const [url, init] = fetchMock.mock.calls[0];
expect(url).toBe("/v1/memory.proposals");
expect(JSON.parse(String(init?.body))).toMatchObject({ ...scope, limit: 1, count_only: true });
});

it("answers null — unknown, never a false zero — when the answer carries no number", async () => {
vi.stubGlobal(
"fetch",
vi.fn(async () => Response.json({})),
);
expect(await countPendingProposals(scope)).toBeNull();
});
});
14 changes: 14 additions & 0 deletions frontend/src/api/review.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,20 @@ export async function listProposals(
);
}

/** The pending proposals of the namespace — one bounded server-side `count()`
* (`count_only`), no row bodies and no scan cap, so the number matches the whole
* authorized queue, not the first page. Accepted and rejected proposals are not
* pending and never counted. `null` when the answer carries no number: unknown,
* never a false zero. */
export async function countPendingProposals(id: Scope, opts: RequestOpts = {}): Promise<number | null> {
const r = await post<{ total?: number | null }>(
"/v1/memory.proposals",
{ org: id.org, namespace: id.namespace, limit: 1, count_only: true },
opts.signal,
);
return typeof r.total === "number" ? r.total : null;
}

export async function decideProposals(
id: Scope,
keys: string[],
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/callBudget.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ const BUDGET: Record<string, { render: () => JSX.Element; view: View; allow: Rec
// The task inbox bell asks for counts once per two minutes.
allow: {
"/v1/conflicts.list": 1,
// One bounded count (count_only, no rows): pending proposals in the Review queue's badge.
"/v1/memory.proposals": 1,
// Fifty retirement records: whether the Review queue's Auto-resolved tab has anything.
"/v1/memory.auto_retirements": 1,
"/v1/cost.budget_status": 1,
Expand Down
16 changes: 12 additions & 4 deletions frontend/src/layout/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@ const AddDocumentDialog = lazy(() =>
);
const loadHeaderSearch = () => import("../components/HeaderSearch");
const HeaderSearch = lazy(() => loadHeaderSearch().then((m) => ({ default: m.HeaderSearch })));
import { PendingApprovalsBell } from "../components/PendingApprovalsBell";
import { TaskInboxBell } from "../components/TaskInboxBell";
// The bells poll on an interval and open their lists on click, so their chunks load with
// the header's paint, not into the boot chunk (keeps the index chunk inside its budget).
const PendingApprovalsBell = lazy(() =>
import("../components/PendingApprovalsBell").then((m) => ({ default: m.PendingApprovalsBell })),
);
const TaskInboxBell = lazy(() => import("../components/TaskInboxBell").then((m) => ({ default: m.TaskInboxBell })));
import { IconButton } from "../components/IconButton";
import { Unavailable } from "../components/ui";
import { Tip } from "../components/ui/Tooltip";
Expand Down Expand Up @@ -182,10 +186,14 @@ export function Header() {

{/* Pending-approvals bell: surfaces grant requests on
namespaces the user is admin of. Counts updated every 30s. */}
<PendingApprovalsBell />
<Suspense fallback={null}>
<PendingApprovalsBell />
</Suspense>
{/* Task inbox bell: review items and blocked tasks in
this namespace's inboxes. One task.counts call per two minutes. */}
<TaskInboxBell />
<Suspense fallback={null}>
<TaskInboxBell />
</Suspense>

{whoami && (
<Menu
Expand Down
20 changes: 12 additions & 8 deletions frontend/src/layout/MobileMore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { canWrite, needsRole, useNamespaceRole } from "../lib/namespaceRole";
import { openNewDialog } from "../lib/newDialogs";
import type { MyNamespaceEntry, WhoAmI } from "../api";
import { useStore, viewHref, type AdminBadges } from "../lib/state";
import { adminItems, NavBadge, RAIL_GROUPS, SETTINGS_ITEM, type NavItem } from "./Sidebar";
import { adminItems, NavBadge, railGroups, SETTINGS_ITEM, type NavItem } from "./Sidebar";
import { ACTIVE, PRIMARY_IDS } from "./mobileTabs";

// The sheet is generated from the sidebar's own nav arrays rather than a second hand-written
Expand All @@ -23,12 +23,14 @@ export function mobileMoreItems(
namespace: string,
badges: AdminBadges | null,
): Array<{ group: string; items: NavItem[] }> {
// The sheet shows the rail's own groups; the two primary tabs are left out of theirs,
// and Settings closes the list. An unlabelled rail group (Profile) joins the first
// labelled one on the phone rather than heading a one-item group of its own.
// The sheet shows the rail's own groups — including the Review queue entry the rail
// adds for a caller who may view review work, so the phone exposes the same entry;
// the two primary tabs are left out of theirs, and Settings closes the list. An
// unlabelled rail group (Profile) joins the first labelled one on the phone rather
// than heading a one-item group of its own.
const groups: Array<{ group: string; items: NavItem[] }> = [];
let carry: NavItem[] = [];
for (const g of RAIL_GROUPS) {
for (const g of railGroups(whoami, mine, namespace, badges)) {
const items = [...carry, ...g.items.filter((m) => !PRIMARY_IDS.includes(m.id))];
if (!g.label) {
carry = items;
Expand All @@ -48,7 +50,7 @@ export function mobileMoreItems(
* out), then every route the sidebar has, in its groups. */
export default function MoreSheet({ onClose }: { onClose: () => void }) {
const view = useStore((s) => s.view);
const setView = useStore((s) => s.setView);
const navigate = useStore((s) => s.navigate);
const whoami = useStore((s) => s.whoami);
const myNamespaces = useStore((s) => s.myNamespaces);
const namespace = useStore((s) => s.identity?.namespace ?? "");
Expand Down Expand Up @@ -109,17 +111,19 @@ export default function MoreSheet({ onClose }: { onClose: () => void }) {
<div className="grid grid-cols-3 gap-2">
{g.items.map((m) => {
const active = view === m.id || (m.id === "setup" && view === "connected-accounts");
const href = m.query ? `${viewHref(m.id)}?${new URLSearchParams(m.query).toString()}` : viewHref(m.id);
return (
<a
key={m.id}
href={viewHref(m.id)}
href={href}
onClick={(e) => {
if (e.metaKey || e.ctrlKey || e.shiftKey || e.button !== 0) return;
e.preventDefault();
setView(m.id);
navigate(m.id, m.query ? { query: m.query } : {});
onClose();
}}
aria-current={active ? "page" : undefined}
aria-label={m.badgeLabel ? `${m.label}, ${m.badgeLabel}` : undefined}
className={`flex flex-col items-center justify-center gap-1.5 py-3 rounded-sm transition-colors no-underline hover:no-underline text-text ${
active ? `${ACTIVE} font-medium` : "bg-surface-2 hover:bg-surface-3"
}`}
Expand Down
Loading
Loading