Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

feat(inbox): filter to issues with no agents working (#9260)

Tim01bbe18e68b8
diff --git a/packages/core/api/archived-inbox.test.ts b/packages/core/api/archived-inbox.test.ts
index 29ad14f51d..913ee2fe5d 100644
--- a/packages/core/api/archived-inbox.test.ts
+++ b/packages/core/api/archived-inbox.test.ts
@@ -1,7 +1,7 @@
// @vitest-environment node
import { afterEach, describe, expect, it, vi } from "vitest";
import { ApiClient } from "./client";
-import { EMPTY_INBOX_FILTERS } from "../inbox/filter-store";
+import { EMPTY_INBOX_FILTERS, type InboxFilters } from "../inbox/filter-store";
afterEach(() => vi.unstubAllGlobals());
@@ -12,12 +12,15 @@ function respond(body: unknown) {
}
describe("archived inbox API", () => {
- it("sends cursor, lookup and every filter dimension and maps the page", async () => {
+ it("sends cursor, lookup and every archive filter dimension and maps the page", async () => {
const fetch = respond({ items: [], next_cursor: null, has_more: false });
const api = new ApiClient("https://api.example.test");
- await expect(api.listArchivedInboxPage({
- statuses: ["in_review"], priorities: ["high"], actors: ["system"], unreadOnly: true,
- }, { cursor: "cursor-value", groupId: "group" })).resolves.toEqual({ items: [], nextCursor: null, hasMore: false });
+ // The archive has no idle dimension; a selection carried in from the
+ // active inbox must not reach the server.
+ const filters: InboxFilters = {
+ statuses: ["in_review"], priorities: ["high"], actors: ["system"], unreadOnly: true, idleOnly: true,
+ };
+ await expect(api.listArchivedInboxPage(filters, { cursor: "cursor-value", groupId: "group" })).resolves.toEqual({ items: [], nextCursor: null, hasMore: false });
const url = new URL(fetch.mock.calls[0]![0]);
expect(url.pathname).toBe("/api/inbox/archived/page");
expect(Object.fromEntries(url.searchParams)).toEqual({
diff --git a/packages/core/api/client.ts b/packages/core/api/client.ts
index caafd2e8e8..01c906868d 100644
--- a/packages/core/api/client.ts
+++ b/packages/core/api/client.ts
@@ -2,7 +2,7 @@ import type { ZodType } from "zod";
import type { IssueWakeup, IssueWakeupInput, IssueWakeupSummaryRow, PausedWakeup, SystemWakeup, WakeupRun, WorkspaceSystemWakeup } from "../types/issue-wakeup";
import type { WorkspaceWakeupPage, WorkspaceWakeupFilters } from "../types/issue-wakeup";
import { WorkspaceWakeupPageSchema, IssueWakeupSchema, IssueWakeupSummaryRowSchema, PausedWakeupSchema, SystemWakeupSchema, WakeupRunSchema, WorkspaceSystemWakeupSchema } from "./schemas";
-import type { InboxFilters } from "../inbox/filter-store";
+import type { ArchivedInboxFilters } from "../inbox/filter-store";
import type { ArchivedInboxPage, ArchivedInboxFacets } from "../types/inbox";
import { configStore } from "../config";
import type {
@@ -2888,7 +2888,7 @@ export class ApiClient {
});
}
- private archivedInboxParams(filters: InboxFilters): URLSearchParams {
+ private archivedInboxParams(filters: ArchivedInboxFilters): URLSearchParams {
const params = new URLSearchParams();
if (filters.statuses.length) params.set("statuses", [...filters.statuses].sort().join(","));
if (filters.priorities.length) params.set("priorities", [...filters.priorities].sort().join(","));
@@ -2897,7 +2897,7 @@ export class ApiClient {
return params;
}
- async listArchivedInboxPage(filters: InboxFilters, options: {
+ async listArchivedInboxPage(filters: ArchivedInboxFilters, options: {
cursor?: string | null; groupId?: string; signal?: AbortSignal;
} = {}): Promise<ArchivedInboxPage> {
const params = this.archivedInboxParams(filters);
@@ -2912,7 +2912,7 @@ export class ApiClient {
return page;
}
- async getArchivedInboxFacets(filters: InboxFilters, signal?: AbortSignal): Promise<ArchivedInboxFacets> {
+ async getArchivedInboxFacets(filters: ArchivedInboxFilters, signal?: AbortSignal): Promise<ArchivedInboxFacets> {
const raw = await this.fetch<unknown>(`/api/inbox/archived/facets?${this.archivedInboxParams(filters)}`, { signal });
const facets = parseWithFallback<ArchivedInboxFacets | null>(raw, ArchivedInboxFacetsSchema, null, {
endpoint: "GET /api/inbox/archived/facets",
diff --git a/packages/core/inbox/filter-store.test.ts b/packages/core/inbox/filter-store.test.ts
index 0013fa9562..d44b66d4e5 100644
--- a/packages/core/inbox/filter-store.test.ts
+++ b/packages/core/inbox/filter-store.test.ts
@@ -177,7 +177,7 @@ describe("unread filtering", () => {
const read = item("read", "todo", "high", { read: true });
expect(
- filterInboxItems([opened, read], filters, "issue-opened").map(
+ filterInboxItems([opened, read], filters, { pinnedUnreadKey: "issue-opened" }).map(
(candidate) => candidate.id,
),
).toEqual(["opened"]);
@@ -185,7 +185,65 @@ describe("unread filtering", () => {
// Pinning only crosses the unread dimension: an explicit issue filter
// still removes the open row, and the page clears its selection.
expect(
- filterInboxItems([opened], { ...filters, statuses: ["done"] }, "issue-opened"),
+ filterInboxItems([opened], { ...filters, statuses: ["done"] }, { pinnedUnreadKey: "issue-opened" }),
+ ).toEqual([]);
+ });
+});
+
+describe("idle filtering", () => {
+ it("keeps only issues no agent is active on and counts as one filter", () => {
+ const rows = [
+ item("busy", "todo", "high", { issue_id: "issue-busy" }),
+ item("idle", "todo", "high", { issue_id: "issue-idle" }),
+ // Idle is a property of an issue; a row without one has none to report.
+ item("no-issue", null, null),
+ ];
+ const filters = { ...EMPTY_INBOX_FILTERS, idleOnly: true };
+
+ expect(
+ filterInboxItems(rows, filters, { activeIssueIds: new Set(["issue-busy"]) }).map(
+ (candidate) => candidate.id,
+ ),
+ ).toEqual(["idle"]);
+ expect(inboxFilterCount(filters)).toBe(1);
+ });
+});
+
+describe("pinned row with idle filtering", () => {
+ it("keeps the open notification after an agent starts on its issue", () => {
+ const filters = { ...EMPTY_INBOX_FILTERS, idleOnly: true };
+ const opened = item("opened", "todo", "high", { issue_id: "issue-opened" });
+ const other = item("other", "todo", "high", { issue_id: "issue-other" });
+ const activeIssueIds = new Set(["issue-opened", "issue-other"]);
+
+ expect(
+ filterInboxItems([opened, other], filters, {
+ activeIssueIds,
+ pinnedIdleKey: "issue-opened",
+ }).map((candidate) => candidate.id),
+ ).toEqual(["opened"]);
+
+ // Each pin crosses only its own dimension.
+ expect(
+ filterInboxItems([opened], filters, {
+ activeIssueIds,
+ pinnedUnreadKey: "issue-opened",
+ }),
+ ).toEqual([]);
+ expect(
+ filterInboxItems(
+ [{ ...opened, read: true }],
+ { ...filters, idleOnly: false, unreadOnly: true },
+ { pinnedIdleKey: "issue-opened" },
+ ),
+ ).toEqual([]);
+
+ // The pin still never crosses an explicit issue filter.
+ expect(
+ filterInboxItems([opened], { ...filters, statuses: ["done"] }, {
+ activeIssueIds,
+ pinnedIdleKey: "issue-opened",
+ }),
).toEqual([]);
});
});
diff --git a/packages/core/inbox/filter-store.ts b/packages/core/inbox/filter-store.ts
index 145df956fd..1444a933ea 100644
--- a/packages/core/inbox/filter-store.ts
+++ b/packages/core/inbox/filter-store.ts
@@ -7,8 +7,16 @@ export interface InboxFilters {
/** Actor keys — see `inboxActorKey`. */
readonly actors: readonly string[];
readonly unreadOnly: boolean;
+ /** Only issues no agent is running or queued on. Active inbox only. */
+ readonly idleOnly: boolean;
}
+/**
+ * The dimensions the server-filtered archive understands. It has no idle
+ * dimension, so `idleOnly` never reaches its endpoints or query keys.
+ */
+export type ArchivedInboxFilters = Omit<InboxFilters, "idleOnly">;
+
/**
* Stable identity for "who this notification came from", used as the value of
* the `actors` dimension.
@@ -43,6 +51,7 @@ export const EMPTY_INBOX_FILTERS: InboxFilters = Object.freeze({
priorities: Object.freeze([]),
actors: Object.freeze([]),
unreadOnly: false,
+ idleOnly: false,
});
/** True when nothing is selected in any dimension. */
@@ -56,6 +65,7 @@ interface InboxFilterState {
togglePriorityFilter: (wsId: string, priority: IssuePriority) => void;
toggleActorFilter: (wsId: string, actor: string) => void;
toggleUnreadOnly: (wsId: string) => void;
+ toggleIdleOnly: (wsId: string) => void;
clearPriorityFilters: (wsId: string) => void;
clearFilters: (wsId: string) => void;
}
@@ -114,6 +124,16 @@ export const useInboxFilterStore = create<InboxFilterState>()((set) => ({
},
};
}),
+ toggleIdleOnly: (wsId) =>
+ set((state) => {
+ const current = state.filtersByWorkspace[wsId] ?? EMPTY_INBOX_FILTERS;
+ return {
+ filtersByWorkspace: {
+ ...state.filtersByWorkspace,
+ [wsId]: { ...current, idleOnly: !current.idleOnly },
+ },
+ };
+ }),
clearPriorityFilters: (wsId) =>
set((state) => {
const current = state.filtersByWorkspace[wsId];
@@ -177,6 +197,33 @@ export function inboxFiltersForPrioritySupport(
return { ...filters, priorities: [] };
}
+const EMPTY_ISSUE_IDS: ReadonlySet<string> = new Set();
+
+/** Page state `filterInboxItems` needs beyond the selected filters. */
+export interface InboxFilterContext {
+ /** Issues an agent is running or queued on. Read only by `idleOnly`. */
+ readonly activeIssueIds?: ReadonlySet<string>;
+ /**
+ * Group key (`issue_id ?? id`) of the open notification, pinned against the
+ * unread dimension only. Set by the page after opening marks the row read.
+ */
+ readonly pinnedUnreadKey?: string | null;
+ /**
+ * Group key of the open notification, pinned against the idle dimension
+ * only. Set by the page once the row was opened while idle.
+ */
+ readonly pinnedIdleKey?: string | null;
+}
+
+/**
+ * The archive is filtered server-side and the backend has no idle dimension,
+ * so a selection kept from the active inbox stays dormant there instead of
+ * narrowing whichever archived pages happen to be loaded.
+ */
+export function inboxFiltersForArchive(filters: InboxFilters): InboxFilters {
+ return filters.idleOnly ? { ...filters, idleOnly: false } : filters;
+}
+
/**
* OR within a dimension, AND between dimensions.
*
@@ -194,17 +241,29 @@ export function inboxFiltersForPrioritySupport(
* endpoint, which applies that newest-per-issue rule in SQL — so "only unread"
* and the number next to Inbox still cannot disagree.
*
- * `pinnedKey` is the notification whose detail is open. Opening an unread
- * notification marks it read, which would otherwise remove the row the user
- * just clicked from under the detail pane. The pinned row therefore survives
- * the unread dimension only; the status, priority, and actor dimensions still
- * apply, because changing one of those is an explicit request to filter the
- * notification itself out.
+ * `idleOnly` asks about the issue, like status and priority, so a row without
+ * one never matches. `activeIssueIds` are the issues an agent is running or
+ * queued on; the caller derives them from the agent task snapshot.
+ *
+ * `pinnedUnreadKey` / `pinnedIdleKey` name the notification whose detail is
+ * open. Opening an unread
+ * notification marks it read, and replying from the detail can start an
+ * agent on its issue; either would otherwise remove the row the user is
+ * working in from under the detail pane. The pinned row therefore survives
+ * the unread and idle dimensions only, and each pin only crosses its own
+ * dimension: a row pinned for unread is still removed when the idle filter
+ * is turned on over a busy issue, and vice versa. The status, priority, and
+ * actor dimensions always apply, because changing one of those is an
+ * explicit request to filter the notification itself out.
*/
export function filterInboxItems(
items: InboxItem[],
filters: InboxFilters,
- pinnedKey?: string | null,
+ {
+ activeIssueIds = EMPTY_ISSUE_IDS,
+ pinnedUnreadKey = null,
+ pinnedIdleKey = null,
+ }: InboxFilterContext = {},
): InboxItem[] {
if (isEmptyInboxFilters(filters)) return items;
@@ -220,11 +279,16 @@ export function filterInboxItems(
(item.issue_priority != null && priorities.has(item.issue_priority))) &&
(actors.size === 0 || (actor != null && actors.has(actor)));
if (!matchesOtherDimensions) return false;
- return (
+ const key = item.issue_id ?? item.id;
+ const matchesUnread =
!filters.unreadOnly ||
item.read !== true ||
- (pinnedKey != null && (item.issue_id ?? item.id) === pinnedKey)
- );
+ (pinnedUnreadKey != null && key === pinnedUnreadKey);
+ const matchesIdle =
+ !filters.idleOnly ||
+ (item.issue_id != null && !activeIssueIds.has(item.issue_id)) ||
+ (pinnedIdleKey != null && key === pinnedIdleKey);
+ return matchesUnread && matchesIdle;
});
}
@@ -233,6 +297,7 @@ export function inboxFilterCount(filters: InboxFilters): number {
filters.statuses.length +
filters.priorities.length +
filters.actors.length +
- (filters.unreadOnly ? 1 : 0)
+ (filters.unreadOnly ? 1 : 0) +
+ (filters.idleOnly ? 1 : 0)
);
}
diff --git a/packages/core/inbox/queries.test.ts b/packages/core/inbox/queries.test.ts
index 8b968211c4..4ce1406666 100644
--- a/packages/core/inbox/queries.test.ts
+++ b/packages/core/inbox/queries.test.ts
@@ -1,6 +1,9 @@
import { describe, expect, it } from "vitest";
import type { InboxItem, InboxWorkspaceUnread } from "../types";
+import { EMPTY_INBOX_FILTERS, type InboxFilters } from "./filter-store";
import {
+ archivedInboxFacetsOptions,
+ archivedInboxPagesOptions,
deduplicateArchivedInboxItems,
deduplicateInboxItems,
hasOtherWorkspaceUnread,
@@ -137,6 +140,19 @@ describe("deduplicateArchivedInboxItems", () => {
});
});
+describe("archived inbox options", () => {
+ it("keeps an idle selection out of archive query keys", () => {
+ const idle: InboxFilters = { ...EMPTY_INBOX_FILTERS, idleOnly: true };
+
+ expect(archivedInboxPagesOptions("ws", idle).queryKey).toEqual(
+ archivedInboxPagesOptions("ws", EMPTY_INBOX_FILTERS).queryKey,
+ );
+ expect(archivedInboxFacetsOptions("ws", idle).queryKey).toEqual(
+ archivedInboxFacetsOptions("ws", EMPTY_INBOX_FILTERS).queryKey,
+ );
+ });
+});
+
describe("hasOtherWorkspaceUnread", () => {
const summary = (entries: InboxWorkspaceUnread[]) => entries;
diff --git a/packages/core/inbox/queries.ts b/packages/core/inbox/queries.ts
index e62ee33780..8f58a74fe4 100644
--- a/packages/core/inbox/queries.ts
+++ b/packages/core/inbox/queries.ts
@@ -1,6 +1,6 @@
import type { InfiniteData, QueryClient } from "@tanstack/react-query";
import type { ArchivedInboxPage } from "../types/inbox";
-import { EMPTY_INBOX_FILTERS, type InboxFilters } from "./filter-store";
+import { EMPTY_INBOX_FILTERS, type ArchivedInboxFilters } from "./filter-store";
import { infiniteQueryOptions, queryOptions, useQuery } from "@tanstack/react-query";
import { api } from "../api";
import type { InboxItem, InboxWorkspaceUnread } from "../types";
@@ -36,12 +36,14 @@ export function archivedInboxListOptions(wsId: string) {
});
}
-function normalizedInboxFilters(filters: InboxFilters): InboxFilters {
+// Lists the archived dimensions explicitly, so an `idleOnly` carried in from
+// the active inbox never changes the key or refetches the archive.
+function normalizedInboxFilters(filters: ArchivedInboxFilters): ArchivedInboxFilters {
return { statuses: [...filters.statuses].sort(), priorities: [...filters.priorities].sort(),
actors: [...filters.actors].sort(), unreadOnly: filters.unreadOnly };
}
-export function archivedInboxPagesOptions(wsId: string, filters: InboxFilters) {
+export function archivedInboxPagesOptions(wsId: string, filters: ArchivedInboxFilters) {
return infiniteQueryOptions({
queryKey: [...inboxKeys.pages(wsId), normalizedInboxFilters(filters)],
initialPageParam: null as string | null,
@@ -51,7 +53,7 @@ export function archivedInboxPagesOptions(wsId: string, filters: InboxFilters) {
});
}
-export function archivedInboxLookupOptions(wsId: string, groupId: string, filters: InboxFilters = EMPTY_INBOX_FILTERS) {
+export function archivedInboxLookupOptions(wsId: string, groupId: string, filters: ArchivedInboxFilters = EMPTY_INBOX_FILTERS) {
return queryOptions({
queryKey: [...inboxKeys.lookup(wsId), groupId, normalizedInboxFilters(filters)],
queryFn: ({ signal }) => api.listArchivedInboxPage(filters, { groupId, signal }),
@@ -60,7 +62,7 @@ export function archivedInboxLookupOptions(wsId: string, groupId: string, filter
});
}
-export function archivedInboxFacetsOptions(wsId: string, filters: InboxFilters) {
+export function archivedInboxFacetsOptions(wsId: string, filters: ArchivedInboxFilters) {
return queryOptions({
queryKey: [...inboxKeys.facets(wsId), normalizedInboxFilters(filters)],
queryFn: ({ signal }) => api.getArchivedInboxFacets(filters, signal),
diff --git a/packages/views/inbox/components/inbox-filter-menu.test.tsx b/packages/views/inbox/components/inbox-filter-menu.test.tsx
index aadaf79bb3..64c2da82a5 100644
--- a/packages/views/inbox/components/inbox-filter-menu.test.tsx
+++ b/packages/views/inbox/components/inbox-filter-menu.test.tsx
@@ -89,17 +89,20 @@ function renderMenu({
items = ITEMS,
priorityFilterSupport = "supported",
archived = false,
+ activeIssueIds,
getArchivedInboxFacets = vi.fn(async () => ({ statuses: {}, priorities: {}, actors: {}, unreadCount: 0 })),
statusEntries = BUILT_IN_STATUS_ORDER.map(statusEntry),
}: {
items?: InboxItem[];
priorityFilterSupport?: InboxPriorityFilterSupport;
archived?: boolean;
+ activeIssueIds?: ReadonlySet<string>;
getArchivedInboxFacets?: ReturnType<typeof vi.fn>;
statusEntries?: IssueStatusEntry[];
} = {}) {
setApiInstance({
getArchivedInboxFacets,
+ getAgentTaskSnapshot: async () => [],
listIssueStatuses: async () => ({
statuses: statusEntries,
categories: [],
@@ -115,6 +118,7 @@ function renderMenu({
wsId="ws-1"
items={items}
priorityFilterSupport={priorityFilterSupport}
+ activeIssueIds={activeIssueIds}
archived={archived}
/>
</QueryClientProvider>,
@@ -285,6 +289,31 @@ describe("InboxFilterMenu", () => {
);
});
+ it("toggles no agents working and counts the idle rows behind it", async () => {
+ renderMenu({ activeIssueIds: new Set(["issue-todo-high"]) });
+
+ fireEvent.click(screen.getByRole("button", { name: "Filter inbox" }));
+ fireEvent.click(
+ await screen.findByRole("menuitemcheckbox", {
+ name: /No agents working.*1 notification/,
+ }),
+ );
+
+ expect(
+ useInboxFilterStore.getState().filtersByWorkspace["ws-1"]?.idleOnly,
+ ).toBe(true);
+ });
+
+ it("hides no agents working in the archive and ignores a carried-over selection", async () => {
+ useInboxFilterStore.getState().toggleIdleOnly("ws-1");
+ renderMenu({ archived: true });
+
+ // Not counted on the trigger, and not offered in the menu.
+ fireEvent.click(screen.getByRole("button", { name: "Filter inbox" }));
+ await screen.findByRole("menuitemcheckbox", { name: /Unread only/ });
+ expect(screen.queryByRole("menuitemcheckbox", { name: /No agents working/ })).toBeNull();
+ });
+
it("hides priority and clears its filter for a legacy response", async () => {
useInboxFilterStore.getState().togglePriorityFilter("ws-1", "high");
renderMenu({
diff --git a/packages/views/inbox/components/inbox-filter-menu.tsx b/packages/views/inbox/components/inbox-filter-menu.tsx
index f63c4c10b8..1b3b770016 100644
--- a/packages/views/inbox/components/inbox-filter-menu.tsx
+++ b/packages/views/inbox/components/inbox-filter-menu.tsx
@@ -1,12 +1,13 @@
"use client";
import { useEffect, useMemo, useState } from "react";
-import { CircleDot, Filter, Mail, RotateCcw, SignalHigh, UserRound } from "lucide-react";
+import { BotOff, CircleDot, Filter, Mail, RotateCcw, SignalHigh, UserRound } from "lucide-react";
import { PRIORITY_DISPLAY_ORDER } from "@multica/core/issues/config";
import {
filterInboxItems,
inboxActorKey,
inboxActorKeyParts,
+ inboxFiltersForArchive,
inboxFiltersForPrioritySupport,
inboxFilterCount,
type InboxPriorityFilterSupport,
@@ -67,16 +68,21 @@ function actorCounts(items: InboxItem[]): Map<string, number> {
return counts;
}
+const EMPTY_ISSUE_IDS: ReadonlySet<string> = new Set();
+
/** Faceted filters for the deduplicated list currently on screen. */
export function InboxFilterMenu({
wsId,
items,
priorityFilterSupport,
+ activeIssueIds = EMPTY_ISSUE_IDS,
archived = false,
}: {
wsId: string;
items: InboxItem[];
priorityFilterSupport: InboxPriorityFilterSupport;
+ /** Issues an agent is running or queued on. */
+ activeIssueIds?: ReadonlySet<string>;
archived?: boolean;
}) {
const { t } = useT("inbox");
@@ -93,6 +99,7 @@ export function InboxFilterMenu({
const toggleUnreadOnly = useInboxFilterStore(
(state) => state.toggleUnreadOnly,
);
+ const toggleIdleOnly = useInboxFilterStore((state) => state.toggleIdleOnly);
const { getActorName, getActorInitials, getActorAvatarUrl } = useActorName();
const clearFilters = useInboxFilterStore((state) => state.clearFilters);
const clearPriorityFilters = useInboxFilterStore(
@@ -111,10 +118,10 @@ export function InboxFilterMenu({
[items, facets, filters.statuses],
);
const statusOptions = useStatusOptions(wsId, inboxStatusKeys);
- const effectiveFilters = useMemo(
- () => inboxFiltersForPrioritySupport(filters, priorityFilterSupport),
- [filters, priorityFilterSupport],
- );
+ const effectiveFilters = useMemo(() => {
+ const supported = inboxFiltersForPrioritySupport(filters, priorityFilterSupport);
+ return archived ? inboxFiltersForArchive(supported) : supported;
+ }, [filters, priorityFilterSupport, archived]);
const activeCount = inboxFilterCount(effectiveFilters);
const priorityFilteringSupported = priorityFilterSupport === "supported";
@@ -140,23 +147,31 @@ export function InboxFilterMenu({
// ignoring its own, so each number says how many rows selecting that value
// can actually reveal.
const statusFacetItems = useMemo(
- () => filterInboxItems(items, { ...effectiveFilters, statuses: [] }),
- [items, effectiveFilters],
+ () => filterInboxItems(items, { ...effectiveFilters, statuses: [] }, { activeIssueIds }),
+ [items, effectiveFilters, activeIssueIds],
);
const priorityFacetItems = useMemo(
- () => filterInboxItems(items, { ...effectiveFilters, priorities: [] }),
- [items, effectiveFilters],
+ () => filterInboxItems(items, { ...effectiveFilters, priorities: [] }, { activeIssueIds }),
+ [items, effectiveFilters, activeIssueIds],
);
const actorFacetItems = useMemo(
- () => filterInboxItems(items, { ...effectiveFilters, actors: [] }),
- [items, effectiveFilters],
+ () => filterInboxItems(items, { ...effectiveFilters, actors: [] }, { activeIssueIds }),
+ [items, effectiveFilters, activeIssueIds],
);
const localUnreadCount = useMemo(
() =>
- filterInboxItems(items, { ...effectiveFilters, unreadOnly: false }).filter(
- (item) => item.read !== true,
- ).length,
- [items, effectiveFilters],
+ filterInboxItems(
+ items,
+ { ...effectiveFilters, unreadOnly: false },
+ { activeIssueIds },
+ ).filter((item) => item.read !== true).length,
+ [items, effectiveFilters, activeIssueIds],
+ );
+ const idleCount = useMemo(
+ () =>
+ filterInboxItems(items, { ...effectiveFilters, idleOnly: true }, { activeIssueIds })
+ .length,
+ [items, effectiveFilters, activeIssueIds],
);
const localStatuses = useMemo(
() => statusCounts(statusFacetItems),
@@ -236,6 +251,21 @@ export function InboxFilterMenu({
</span>
)}
</DropdownMenuCheckboxItem>
+ {/* The archive is filtered server-side, which has no idle dimension. */}
+ {!archived && (
+ <DropdownMenuCheckboxItem
+ checked={effectiveFilters.idleOnly}
+ onCheckedChange={() => toggleIdleOnly(wsId)}
+ >
+ <BotOff className="size-3.5" />
+ <span className="flex-1">{t(($) => $.filters.no_agents_working)}</span>
+ {idleCount > 0 && (
+ <span className="text-caption text-muted-foreground">
+ {t(($) => $.filters.notification_count, { count: idleCount })}
+ </span>
+ )}
+ </DropdownMenuCheckboxItem>
+ )}
<DropdownMenuSeparator />
{actorOptions.length > 0 && (
diff --git a/packages/views/inbox/components/inbox-page.test.tsx b/packages/views/inbox/components/inbox-page.test.tsx
index 1321e13713..ab2d939bce 100644
--- a/packages/views/inbox/components/inbox-page.test.tsx
+++ b/packages/views/inbox/components/inbox-page.test.tsx
@@ -2,7 +2,7 @@ import { act, fireEvent, render, screen } from "@testing-library/react";
import { describe, expect, it, vi } from "vitest";
import { toast } from "sonner";
import { ApiError } from "@multica/core/api";
-import type { InboxItem } from "@multica/core/types";
+import type { AgentTask, InboxItem } from "@multica/core/types";
import { useInboxFilterStore } from "@multica/core/inbox/filter-store";
import { InboxPage } from "./inbox-page";
@@ -17,20 +17,24 @@ vi.mock("react-resizable-panels", () => ({
// The page runs two queries — the active list and the archived one. They are
// told apart by the queryKey their options carry, so each test can stock the
// two lists independently.
-const listData: { active: InboxItem[]; archived: InboxItem[]; lookup?: InboxItem[] } = {
+const listData: { active: InboxItem[]; archived: InboxItem[]; lookup?: InboxItem[]; tasks: AgentTask[] } = {
active: [],
archived: [],
+ tasks: [],
};
const queryCalls: Array<{ queryKey: readonly unknown[]; enabled?: boolean }> = [];
const lookupState = { isLoading: false, isError: false, refetch: vi.fn() };
const queryClient = vi.hoisted(() => ({ setQueryData: vi.fn() }));
vi.mock("@tanstack/react-query", () => ({
+ queryOptions: (options: unknown) => options,
useQueryClient: () => queryClient,
useQuery: (options: { queryKey: readonly unknown[]; enabled?: boolean }) => {
queryCalls.push(options);
return ({
- data: options.queryKey.includes("archived") ? { items: listData.lookup ?? listData.archived, hasMore: false, nextCursor: null } : listData.active,
+ data: options.queryKey.includes("archived")
+ ? { items: listData.lookup ?? listData.archived, hasMore: false, nextCursor: null }
+ : options.queryKey.includes("agent-task-snapshot") ? listData.tasks : listData.active,
isLoading: false,
isError: false,
refetch: vi.fn(),
@@ -273,6 +277,7 @@ function reset() {
listData.active = [];
listData.archived = [];
listData.lookup = undefined;
+ listData.tasks = [];
lookupState.isLoading = false;
lookupState.isError = false;
lookupState.refetch.mockClear();
@@ -297,6 +302,55 @@ function reset() {
}
describe("InboxPage", () => {
+ it.each([false, true])("enabling idle hides an already busy row with unread pin=%s", (unreadOnly) => {
+ reset();
+ layout.width = DESKTOP;
+ listData.active = [item({ id: "busy-row", issue_id: "busy-issue", read: !unreadOnly })];
+ listData.tasks = [{ id: "task-a", agent_id: "agent-1", issue_id: "busy-issue", status: "running" }] as AgentTask[];
+ if (unreadOnly) useInboxFilterStore.getState().toggleUnreadOnly("workspace-1");
+ markReadMutate.mockImplementation(() => {
+ listData.active = listData.active.map((current) => ({ ...current, read: true }));
+ });
+ const { rerender } = render(<InboxPage />);
+ fireEvent.click(screen.getByTestId("row"));
+ rerender(<InboxPage />);
+ expect(screen.getByTestId("row")).toHaveTextContent("busy-row");
+
+ act(() => useInboxFilterStore.getState().toggleIdleOnly("workspace-1"));
+
+ expect(screen.queryByTestId("row")).toBeNull();
+ });
+
+ it("enabling unread hides a read row pinned by idle", () => {
+ reset();
+ layout.width = DESKTOP;
+ listData.active = [item({ id: "read-row", issue_id: "idle-issue", read: true })];
+ useInboxFilterStore.getState().toggleIdleOnly("workspace-1");
+ render(<InboxPage />);
+ fireEvent.click(screen.getByTestId("row"));
+
+ act(() => useInboxFilterStore.getState().toggleUnreadOnly("workspace-1"));
+
+ expect(screen.queryByTestId("row")).toBeNull();
+ });
+
+ it("re-enabling idle evaluates current activity after disabling it", () => {
+ reset();
+ layout.width = DESKTOP;
+ listData.active = [item({ id: "was-idle", issue_id: "issue-a", read: true })];
+ useInboxFilterStore.getState().toggleIdleOnly("workspace-1");
+ const { rerender } = render(<InboxPage />);
+ fireEvent.click(screen.getByTestId("row"));
+ act(() => useInboxFilterStore.getState().toggleIdleOnly("workspace-1"));
+ listData.tasks = [{ id: "task-a", agent_id: "agent-1", issue_id: "issue-a", status: "running" }] as AgentTask[];
+ rerender(<InboxPage />);
+ expect(screen.getByTestId("row")).toHaveTextContent("was-idle");
+
+ act(() => useInboxFilterStore.getState().toggleIdleOnly("workspace-1"));
+
+ expect(screen.queryByTestId("row")).toBeNull();
+ });
+
it("keeps the list subordinate to the detail pane on desktop", () => {
reset();
layout.width = DESKTOP;
@@ -386,6 +440,29 @@ describe("InboxPage", () => {
expect(screen.getByTestId("row")).toHaveTextContent("from-alice");
});
+ it("hides issues an agent is running or queued on while the idle filter is on", () => {
+ reset();
+ listData.active = [
+ item({ id: "running", issue_id: "issue-1" }),
+ item({ id: "queued", issue_id: "issue-2" }),
+ item({ id: "finished", issue_id: "issue-3" }),
+ item({ id: "untouched", issue_id: "issue-4" }),
+ ];
+ listData.tasks = [
+ { id: "task-1", agent_id: "agent-1", issue_id: "issue-1", status: "running" },
+ { id: "task-2", agent_id: "agent-1", issue_id: "issue-2", status: "queued" },
+ { id: "task-3", agent_id: "agent-1", issue_id: "issue-3", status: "completed" },
+ ] as AgentTask[];
+ useInboxFilterStore.getState().toggleIdleOnly("workspace-1");
+
+ render(<InboxPage />);
+
+ expect(screen.getAllByTestId("row").map((row) => row.textContent)).toEqual([
+ "finished",
+ "untouched",
+ ]);
+ });
+
it("offers to clear filters when they hide every notification", () => {
reset();
listData.active = [
@@ -523,6 +600,20 @@ describe("InboxPage", () => {
expect(archivedView.querySelector('[aria-haspopup="menu"]')).toBeNull();
});
+ it("ignores a carried-over idle selection in the archive", () => {
+ reset();
+ searchParams = new URLSearchParams("view=archived");
+ listData.archived = [item({ id: "archived-busy", issue_id: "issue-1", archived: true })];
+ listData.tasks = [
+ { id: "task-1", agent_id: "agent-1", issue_id: "issue-1", status: "running" },
+ ] as AgentTask[];
+ useInboxFilterStore.getState().toggleIdleOnly("workspace-1");
+
+ render(<InboxPage />);
+
+ expect(screen.getByTestId("row")).toHaveTextContent("archived-busy");
+ });
+
it("keeps the archive open when it is empty", () => {
reset();
searchParams = new URLSearchParams("view=archived");
@@ -712,6 +803,33 @@ describe("InboxPage", () => {
expect(replace).not.toHaveBeenCalledWith("/acme/inbox");
});
+ it("keeps an idle-filtered notification open after an agent starts on it", () => {
+ // Replying from the detail can start an agent on the open issue. With the
+ // idle filter on, that would drop the row the user is working in.
+ reset();
+ layout.width = DESKTOP;
+ listData.active = [
+ item({ id: "inbox-a", issue_id: "issue-a", read: true }),
+ item({ id: "inbox-b", issue_id: "issue-b", read: true }),
+ ];
+ useInboxFilterStore.getState().toggleIdleOnly("workspace-1");
+
+ const { rerender } = render(<InboxPage />);
+ fireEvent.click(screen.getAllByTestId("row")[0]!);
+ rerender(<InboxPage />);
+ listData.tasks = [
+ { id: "task-a", agent_id: "agent-1", issue_id: "issue-a", status: "queued" },
+ { id: "task-b", agent_id: "agent-1", issue_id: "issue-b", status: "running" },
+ ] as AgentTask[];
+ rerender(<InboxPage />);
+
+ // The open row stays; another row that turned busy is still filtered.
+ expect(screen.getAllByTestId("row").map((row) => row.textContent)).toEqual([
+ "inbox-a",
+ ]);
+ expect(replace).not.toHaveBeenCalledWith("/acme/inbox");
+ });
+
it("keeps an explicitly unread row unread while it stays open", () => {
// Without the guard the auto-read effect fires on the very next commit and
// silently undoes the user's "mark as unread" — the action looks like a
diff --git a/packages/views/inbox/components/inbox-page.tsx b/packages/views/inbox/components/inbox-page.tsx
index 2985ed1ce6..995fa78db8 100644
--- a/packages/views/inbox/components/inbox-page.tsx
+++ b/packages/views/inbox/components/inbox-page.tsx
@@ -43,6 +43,7 @@ import {
} from "@multica/core/inbox/mutations";
import {
filterInboxItems,
+ inboxFiltersForArchive,
inboxFiltersForPrioritySupport,
inboxFilterCount,
inboxPriorityFilterSupport,
@@ -52,6 +53,7 @@ import {
import { IssueDetail, issueHighlightMementoKey } from "../../issues/components/issue-detail";
import { IssuePeekHost } from "../../issues/components/issue-peek";
+import { useIssueSurfaceActivity } from "../../issues/surface/activity";
import { useViewStateWriter } from "../../platform";
import { ErrorBoundary } from "@multica/ui/components/common/error-boundary";
import { useNavigation, useReportNavigating } from "../../navigation";
@@ -125,6 +127,11 @@ export function InboxPage() {
// so the filter would otherwise drop the row before the detail finishes
// mounting. Scoped to the selection: moving away releases it.
const pinnedUnreadKeyRef = useRef<string | null>(null);
+ // The row the user opened under the idle filter. Replying from the detail
+ // can start an agent on its issue, which would otherwise drop the row the
+ // user is working in. Set once the open row has passed the idle filter, so
+ // turning the filter on over a busy row still filters it out.
+ const pinnedIdleKeyRef = useRef<string | null>(null);
// Sync from URL when searchParams change (e.g. navigation)
useEffect(() => {
@@ -155,14 +162,35 @@ export function InboxPage() {
const viewItems = isArchivedView ? archivedItems : items;
// The paginated endpoint guarantees the projection, including on empty pages.
const priorityFilterSupport = isArchivedView ? "supported" : inboxPriorityFilterSupport(rawItems);
- const effectiveFilters = useMemo(() => inboxFiltersForPrioritySupport(filters, priorityFilterSupport), [filters, priorityFilterSupport]);
+ const effectiveFilters = useMemo(() => {
+ const supported = inboxFiltersForPrioritySupport(filters, priorityFilterSupport);
+ return isArchivedView ? inboxFiltersForArchive(supported) : supported;
+ }, [filters, priorityFilterSupport, isArchivedView]);
+ // "Active" is the same running-or-queued rule the row's activity badge uses.
+ const { activityByIssueId } = useIssueSurfaceActivity();
+ const activeIssueIds = useMemo(() => new Set(activityByIssueId.keys()), [activityByIssueId]);
+ // Only an idle selection reads the snapshot, so task churn leaves the list
+ // alone while it is off.
+ const idleFilterIssueIds = effectiveFilters.idleOnly ? activeIssueIds : undefined;
+ // The open row survives the unread and idle dimensions while it stays
+ // selected; see the pin refs above. Each pin is passed separately so it
+ // only crosses its own dimension.
const pinnedUnreadKey =
effectiveFilters.unreadOnly && pinnedUnreadKeyRef.current === selectedKey
? selectedKey
: null;
+ const pinnedIdleKey =
+ effectiveFilters.idleOnly && pinnedIdleKeyRef.current === selectedKey
+ ? selectedKey
+ : null;
+ const pinnedKey = pinnedUnreadKey ?? pinnedIdleKey;
+ const filterContext = useMemo(
+ () => ({ activeIssueIds: idleFilterIssueIds, pinnedUnreadKey, pinnedIdleKey }),
+ [idleFilterIssueIds, pinnedUnreadKey, pinnedIdleKey],
+ );
const filteredItems = useMemo(
- () => filterInboxItems(viewItems, effectiveFilters, pinnedUnreadKey),
- [viewItems, effectiveFilters, pinnedUnreadKey],
+ () => filterInboxItems(viewItems, effectiveFilters, filterContext),
+ [viewItems, effectiveFilters, filterContext],
);
const hasActiveFilters = inboxFilterCount(effectiveFilters) > 0;
const selectedOnPage = viewItems.find((i) => (i.issue_id ?? i.id) === selectedKey);
@@ -177,10 +205,10 @@ export function InboxPage() {
if (!isArchivedView || selectedOnPage) return filteredItems;
return deduplicateArchivedInboxItems([
...filteredItems,
- ...filterInboxItems(lookupItems, effectiveFilters, pinnedUnreadKey),
+ ...filterInboxItems(lookupItems, effectiveFilters, filterContext),
]);
- }, [isArchivedView, selectedOnPage, filteredItems, lookupItems, effectiveFilters, pinnedUnreadKey]);
- const visibleItems = isArchivedView && pinnedUnreadKey ? selectionItems : filteredItems;
+ }, [isArchivedView, selectedOnPage, filteredItems, lookupItems, effectiveFilters, filterContext]);
+ const visibleItems = isArchivedView && pinnedKey ? selectionItems : filteredItems;
const selected = selectionItems.find((i) => (i.issue_id ?? i.id) === selectedKey) ?? null;
const selectedInView = selectedOnPage ?? (isArchivedView ? lookupItems.find((i) => (i.issue_id ?? i.id) === selectedKey) : null);
const selectionFilteredOut = !!selectedKey && !!selectedInView && !selected;
@@ -355,8 +383,31 @@ export function InboxPage() {
if (pinnedUnreadKeyRef.current && pinnedUnreadKeyRef.current !== selectedKey) {
pinnedUnreadKeyRef.current = null;
}
+ if (pinnedIdleKeyRef.current && pinnedIdleKeyRef.current !== selectedKey) {
+ pinnedIdleKeyRef.current = null;
+ }
}, [selectedId, selectedKey]);
+ // `selected` only exists once the open row passed every filter, so under
+ // the idle filter this pins a row that was idle when the user opened it.
+ const idleOnlyActive = effectiveFilters.idleOnly;
+ const unreadOnlyActive = effectiveFilters.unreadOnly;
+ const hasSelected = selected != null;
+ useEffect(() => {
+ if (idleOnlyActive && hasSelected && selectedKey) {
+ pinnedIdleKeyRef.current = selectedKey;
+ }
+ }, [idleOnlyActive, hasSelected, selectedKey]);
+
+ // Turning a filter off releases its pin, so turning it back on judges the
+ // open row by its current state instead of an exemption from earlier.
+ useEffect(() => {
+ if (!idleOnlyActive) pinnedIdleKeyRef.current = null;
+ }, [idleOnlyActive]);
+ useEffect(() => {
+ if (!unreadOnlyActive) pinnedUnreadKeyRef.current = null;
+ }, [unreadOnlyActive]);
+
const writeViewState = useViewStateWriter();
// Bumped when the already-open notification row is re-clicked; threaded to
// IssueDetail so it replays the comment-highlight landing without a
@@ -544,6 +595,7 @@ export function InboxPage() {
wsId={wsId}
items={viewItems}
priorityFilterSupport={priorityFilterSupport}
+ activeIssueIds={activeIssueIds}
archived={isArchivedView}
/>
{/* Batch actions are main-view only. Every entry archives from the MAIN
diff --git a/packages/views/locales/en/inbox.json b/packages/views/locales/en/inbox.json
index d4ee657b8e..ceb7c6ac9d 100644
--- a/packages/views/locales/en/inbox.json
+++ b/packages/views/locales/en/inbox.json
@@ -17,6 +17,7 @@
"priority": "Priority",
"from": "From",
"unread_only": "Unread only",
+ "no_agents_working": "No agents working",
"notification_count_one": "{{count}} notification",
"notification_count_other": "{{count}} notifications",
"clear": "Clear filters",
diff --git a/packages/views/locales/fr/inbox.json b/packages/views/locales/fr/inbox.json
index 35654d390d..5d48ee2d52 100644
--- a/packages/views/locales/fr/inbox.json
+++ b/packages/views/locales/fr/inbox.json
@@ -17,6 +17,7 @@
"priority": "Priorité",
"from": "De",
"unread_only": "Non lues uniquement",
+ "no_agents_working": "Aucun agent au travail",
"notification_count_one": "{{count}} notification",
"notification_count_other": "{{count}} notifications",
"clear": "Effacer les filtres",
diff --git a/packages/views/locales/ja/inbox.json b/packages/views/locales/ja/inbox.json
index e5b00c829c..5b154dd71e 100644
--- a/packages/views/locales/ja/inbox.json
+++ b/packages/views/locales/ja/inbox.json
@@ -16,6 +16,7 @@
"priority": "優先度",
"from": "送信者",
"unread_only": "未読のみ",
+ "no_agents_working": "作業中のエージェントなし",
"notification_count_other": "{{count}} 件の通知",
"clear": "フィルターをクリア",
"empty": "フィルターに一致する通知はありません"
diff --git a/packages/views/locales/ko/inbox.json b/packages/views/locales/ko/inbox.json
index 1a23d044b3..dc66eb8d09 100644
--- a/packages/views/locales/ko/inbox.json
+++ b/packages/views/locales/ko/inbox.json
@@ -16,6 +16,7 @@
"priority": "우선순위",
"from": "보낸 사람",
"unread_only": "읽지 않음만",
+ "no_agents_working": "작업 중인 에이전트 없음",
"notification_count_other": "알림 {{count}}개",
"clear": "필터 지우기",
"empty": "필터와 일치하는 알림이 없습니다"
diff --git a/packages/views/locales/zh-Hans/inbox.json b/packages/views/locales/zh-Hans/inbox.json
index 03271e5cf0..19dfb39cea 100644
--- a/packages/views/locales/zh-Hans/inbox.json
+++ b/packages/views/locales/zh-Hans/inbox.json
@@ -16,6 +16,7 @@
"priority": "优先级",
"from": "来自",
"unread_only": "只看未读",
+ "no_agents_working": "没有智能体在工作",
"notification_count_other": "{{count}} 条通知",
"clear": "清除筛选",
"empty": "没有符合筛选条件的通知"