Compare commits

...
Author SHA1 Message Date
paseo-bot[bot]andClaude Opus 5.5 fc1f715184 Count background workspaces in the badge while Show background is on
The sidebar shows background workspaces when Show background is on, so
the dock badge and favicon now count them in that case too. They follow
the same setting the sidebar reads.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 11:35:44 +00:00
paseo-bot[bot] 40275bc3a4 Keep background workspaces out of the dock badge and favicon
A workspace created with `--background` is hidden from the sidebar, but an
agent finishing in it still counted toward the macOS dock badge and turned
the web favicon to attention, pointing at something the user cannot see.

The dock badge now skips background workspaces, and the favicon skips
agents whose workspace is background, the same way both already skipped
background agents. The favicon selector also rescans when the workspace
map changes, so an agent synced before its workspace is dropped once the
workspace arrives.

Closes #9975
2026-11-17 11:21:51 +00:00
6 changed files with 124 additions and 20 deletions
+11 -2
View File
@@ -6,6 +6,7 @@ import { createMacDockBadgeCountSelector } from "@/utils/desktop-badge-state";
import { createFaviconStatusSelector, type FaviconStatus } from "@/utils/favicon-status";
import { isNative } from "@/constants/platform";
import { useSessionStore } from "@/stores/session-store";
import { useSidebarViewStore } from "@/stores/sidebar-view-store";
import { useHosts } from "@/runtime/host-runtime";
type ColorScheme = "dark" | "light";
@@ -85,8 +86,16 @@ export function useFaviconStatus() {
// The favicon reads the whole fleet, so it has to keep every host's directory loading even
// though it no longer subscribes to the agent maps.
useAllDirectoryDemand({ serverIds, enabled: !isNative });
const selectFaviconStatus = useMemo(createFaviconStatusSelector, []);
const selectMacDockBadgeCount = useMemo(createMacDockBadgeCountSelector, []);
// Background workspaces count exactly when the sidebar shows them.
const showBackground = useSidebarViewStore((state) => state.showBackground);
const selectFaviconStatus = useMemo(
() => createFaviconStatusSelector({ showBackground }),
[showBackground],
);
const selectMacDockBadgeCount = useMemo(
() => createMacDockBadgeCountSelector({ showBackground }),
[showBackground],
);
const status = useSessionStore(selectFaviconStatus);
const dockBadgeCount = useSessionStore(selectMacDockBadgeCount);
const [colorScheme, setColorScheme] = useState<ColorScheme>(getSystemColorScheme);
@@ -73,6 +73,18 @@ describe("desktop-badge-state", () => {
expect(selectMacDockBadgeCount(state)).toBe(3);
});
it("leaves out background workspaces, which the sidebar hides", () => {
const hidden = { ...workspace("a", "attention"), background: true };
expect(selectMacDockBadgeCount(stateWith(hidden))).toBeUndefined();
expect(selectMacDockBadgeCount(stateWith(hidden, workspace("b", "failed")))).toBe(1);
});
it("counts background workspaces while Show background puts them in the sidebar", () => {
const hidden = { ...workspace("a", "attention"), background: true };
expect(selectMacDockBadgeCount(stateWith(hidden), { showBackground: true })).toBe(1);
expect(createMacDockBadgeCountSelector({ showBackground: true })(stateWith(hidden))).toBe(1);
});
it("recounts only when a workspace map is replaced", () => {
const select = createMacDockBadgeCountSelector();
const state = stateWith(workspace("a", "attention"));
+16 -6
View File
@@ -19,11 +19,21 @@ export function isWorkspaceActionableForDesktopBadge(status: DesktopBadgeWorkspa
* The macOS dock badge only needs a count, so count here instead of materialising every
* workspace status and comparing the whole list on every store write.
*/
export function selectMacDockBadgeCount(state: WorkspaceStatusSource): number | undefined {
export interface DockBadgeOptions {
/** Count background workspaces too, as the sidebar shows them while Show background is on. */
showBackground?: boolean;
}
export function selectMacDockBadgeCount(
state: WorkspaceStatusSource,
options: DockBadgeOptions = {},
): number | undefined {
let actionableCount = 0;
for (const session of Object.values(state.sessions)) {
if (!session) continue;
for (const workspace of session.workspaces.values()) {
// A hidden background workspace would leave the badge pointing at nothing in the sidebar.
if (workspace.background && !options.showBackground) continue;
if (isWorkspaceActionableForDesktopBadge(workspace.status)) actionableCount += 1;
}
}
@@ -31,11 +41,11 @@ export function selectMacDockBadgeCount(state: WorkspaceStatusSource): number |
}
/** A session-store selector for the dock badge count that recounts only when a workspace map changes. */
export function createMacDockBadgeCountSelector(): (
state: WorkspaceStatusSource,
) => number | undefined {
export function createMacDockBadgeCountSelector(
options: DockBadgeOptions = {},
): (state: WorkspaceStatusSource) => number | undefined {
return memoizeOnSessionMaps<WorkspaceStatusSession, WorkspaceStatusSource, number | undefined>(
(session) => session.workspaces,
selectMacDockBadgeCount,
(session) => [session.workspaces],
(state) => selectMacDockBadgeCount(state, options),
);
}
+59 -2
View File
@@ -1,5 +1,5 @@
import { describe, expect, it } from "vitest";
import type { Agent } from "@/stores/session-store";
import type { Agent, WorkspaceDescriptor } from "@/stores/session-store";
import { createFaviconStatusSelector, deriveFaviconStatus } from "./favicon-status";
function agent(input: Partial<Agent> & { id: string }): Agent {
@@ -14,7 +14,21 @@ function agent(input: Partial<Agent> & { id: string }): Agent {
}
function stateWith(...agents: Agent[]) {
return { sessions: { srv: { agents: new Map(agents.map((entry) => [entry.id, entry])) } } };
return stateWithWorkspaces([], ...agents);
}
function stateWithWorkspaces(
workspaces: Array<Pick<WorkspaceDescriptor, "id" | "background">>,
...agents: Agent[]
) {
return {
sessions: {
srv: {
agents: new Map(agents.map((entry) => [entry.id, entry])),
workspaces: new Map(workspaces.map((entry) => [entry.id, entry])),
},
},
};
}
describe("deriveFaviconStatus", () => {
@@ -50,6 +64,37 @@ describe("deriveFaviconStatus", () => {
),
).toBe("none");
});
it("ignores agents in background workspaces, which the sidebar hides", () => {
const hidden = { id: "ws-hidden", background: true };
expect(
deriveFaviconStatus(
stateWithWorkspaces(
[hidden],
agent({ id: "a", workspaceId: "ws-hidden", requiresAttention: true }),
agent({ id: "b", workspaceId: "ws-hidden", status: "running" }),
),
),
).toBe("none");
expect(
deriveFaviconStatus(
stateWithWorkspaces(
[hidden, { id: "ws-shown", background: false }],
agent({ id: "a", workspaceId: "ws-hidden", status: "running" }),
agent({ id: "b", workspaceId: "ws-shown", requiresAttention: true }),
),
),
).toBe("attention");
});
it("counts agents in background workspaces while Show background puts them in the sidebar", () => {
const state = stateWithWorkspaces(
[{ id: "ws-hidden", background: true }],
agent({ id: "a", workspaceId: "ws-hidden", requiresAttention: true }),
);
expect(deriveFaviconStatus(state, { showBackground: true })).toBe("attention");
expect(createFaviconStatusSelector({ showBackground: true })(state)).toBe("attention");
});
});
describe("createFaviconStatusSelector", () => {
@@ -63,6 +108,18 @@ describe("createFaviconStatusSelector", () => {
expect(select({ sessions: { ...state.sessions } })).toBe("running");
});
it("rescans when a workspace map is replaced", () => {
const select = createFaviconStatusSelector();
const state = stateWithWorkspaces(
[],
agent({ id: "a", workspaceId: "ws-hidden", requiresAttention: true }),
);
expect(select(state)).toBe("attention");
// The agent synced before its workspace; only the workspace map changes.
const workspaces = new Map([["ws-hidden", { id: "ws-hidden", background: true }]]);
expect(select({ sessions: { srv: { ...state.sessions.srv, workspaces } } })).toBe("none");
});
it("rescans when an agent map is replaced", () => {
const select = createFaviconStatusSelector();
expect(select(stateWith(agent({ id: "a", status: "running" })))).toBe("running");
+22 -6
View File
@@ -1,10 +1,11 @@
import type { Agent } from "@/stores/session-store";
import type { Agent, WorkspaceDescriptor } from "@/stores/session-store";
import { memoizeOnSessionMaps } from "./memoize-on-session-maps";
export type FaviconStatus = "none" | "running" | "attention";
interface FaviconAgentSession {
agents: ReadonlyMap<string, Agent>;
workspaces: ReadonlyMap<string, Pick<WorkspaceDescriptor, "background">>;
}
interface FaviconAgentSource {
@@ -16,13 +17,22 @@ interface FaviconAgentSource {
* three states here instead of building the aggregated agent list: the list allocates a
* projection per agent, deep-compares it and sorts every agent on the host on each update.
*/
export function deriveFaviconStatus(state: FaviconAgentSource): FaviconStatus {
export interface FaviconStatusOptions {
/** Count agents in background workspaces too, as the sidebar shows them while Show background is on. */
showBackground?: boolean;
}
export function deriveFaviconStatus(
state: FaviconAgentSource,
options: FaviconStatusOptions = {},
): FaviconStatus {
let hasAttention = false;
let hasNeedsInput = false;
for (const session of Object.values(state.sessions)) {
if (!session) continue;
for (const agent of session.agents.values()) {
if (agent.background || agent.archivedAt) continue;
if (!options.showBackground && isInBackgroundWorkspace(agent, session)) continue;
if (agent.status === "running") return "running";
if (agent.requiresAttention) hasAttention = true;
if (agent.pendingPermissions.length > 0) hasNeedsInput = true;
@@ -31,10 +41,16 @@ export function deriveFaviconStatus(state: FaviconAgentSource): FaviconStatus {
return hasAttention || hasNeedsInput ? "attention" : "none";
}
/** A session-store selector for the favicon status that rescans only when an agent map changes. */
export function createFaviconStatusSelector(): (state: FaviconAgentSource) => FaviconStatus {
function isInBackgroundWorkspace(agent: Agent, session: FaviconAgentSession): boolean {
return agent.workspaceId ? session.workspaces.get(agent.workspaceId)?.background === true : false;
}
/** A session-store selector for the favicon status that rescans only when an agent or workspace map changes. */
export function createFaviconStatusSelector(
options: FaviconStatusOptions = {},
): (state: FaviconAgentSource) => FaviconStatus {
return memoizeOnSessionMaps<FaviconAgentSession, FaviconAgentSource, FaviconStatus>(
(session) => session.agents,
deriveFaviconStatus,
(session) => [session.agents, session.workspaces],
(state) => deriveFaviconStatus(state, options),
);
}
@@ -4,18 +4,18 @@ interface SessionsSource<TSession> {
/**
* Wraps a whole-store selector so it reruns only when one of the per-session maps it reads has
* changed. Session-store writes that leave those maps alone (timeline updates, drafts) then cost
* changed. `pickMaps` returns every map the selector reads from one session. Session-store writes that leave those maps alone (timeline updates, drafts) then cost
* a reference check per host instead of a walk over every entry.
*/
export function memoizeOnSessionMaps<TSession, TState extends SessionsSource<TSession>, TResult>(
pickMap: (session: TSession) => unknown,
pickMaps: (session: TSession) => readonly unknown[],
derive: (state: TState) => TResult,
): (state: TState) => TResult {
let previousMaps: unknown[] | null = null;
let previousResult: TResult;
return (state) => {
const maps = Object.values(state.sessions).map((session) =>
session ? pickMap(session) : undefined,
const maps = Object.values(state.sessions).flatMap((session) =>
session ? pickMaps(session) : [undefined],
);
if (
previousMaps &&