Skip to content

Commit 0f8fa7e

Browse files
matt2eclaude
andcommitted
feat(desktop): show an active-agents dot on the community rail
Give each community button in the experimental far-left rail (workspaceRail) a green status dot when that community has active managed agents, so concurrently running workspaces stay visible at a glance (extends the Phase 3 per-community agents UI scoping): - Add countActiveAgentsByCommunity to agentRelayScope: active (running or deployed, mirroring isManagedAgentActive) agents per community id, matched on the normalized relay pin. A blank pin counts toward the active community only — the per-surface "blank follows the community being viewed" fallback would light every rail dot for one stray unstamped record. Communities sharing a relay URL both light up. - Render the dot at the button's top-right (unread badge/dot keeps bottom-right), emerald to mirror the agents list's "online" PresenceDot, with the count woven into the tooltip/aria label via a new pure communityRailTooltipLabel ("Bravo — 1 agent active"). - Add a slow 60s tier to the useManagedAgentsQuery poll gate while agents run only in other communities, so a background process dying clears their rail dots (and the "running in other communities" line) instead of staying green forever — previously that state could go permanently stale once the active community had nothing running. - Seed support: mock managed agents accept a relayUrl pin in the E2E bridge, and the rail spec covers dot-on-running / no-dot-on-stopped across two communities. - Re-register the rail Playwright spec: playwright.config.ts still matched the old workspace-rail.spec.ts name after the community-rail rename, so the spec had silently stopped running. Tested: desktop pnpm test (2954 passed, incl. 13 new unit tests), tsc --noEmit, biome check, Playwright community-rail spec (8 passed, incl. the new dot test), plus a visual check of the rendered dot. Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: Matt Toohey <[email protected]>
1 parent f3baa96 commit 0f8fa7e

9 files changed

Lines changed: 355 additions & 18 deletions

File tree

‎desktop/playwright.config.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export default defineConfig({
6565
"**/home-collapsed-top-chrome.spec.ts",
6666
"**/top-chrome-zoom-clearance.spec.ts",
6767
"**/thread-unread.spec.ts",
68-
"**/workspace-rail.spec.ts",
68+
"**/community-rail.spec.ts",
6969
"**/boot-splash.spec.ts",
7070
"**/thread-reply-anchor-roleplay.spec.ts",
7171
"**/threadpane-ultrawide.spec.ts",

‎desktop/src/features/agents/agentRelayScope.test.mjs‎

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import test from "node:test";
33

44
import {
55
agentBelongsToRelay,
6+
countActiveAgentsByCommunity,
7+
hasRunningAgentAnywhere,
68
hasRunningAgentInCommunity,
79
normalizeRelayUrlForCompare,
810
partitionAgentsByRelay,
@@ -127,3 +129,103 @@ test("pollingGate_blankPinRunningAgent_polls", () => {
127129
true,
128130
);
129131
});
132+
133+
// ── hasRunningAgentAnywhere: the slow cross-community poll tier ──────────────
134+
135+
test("anywhereGate_runningAgentInAnyCommunity_polls", () => {
136+
assert.equal(
137+
hasRunningAgentAnywhere([
138+
{ relayUrl: RELAY_A, status: "stopped" },
139+
{ relayUrl: RELAY_B, status: "running" },
140+
]),
141+
true,
142+
);
143+
});
144+
145+
test("anywhereGate_deployedOnly_doesNotPoll", () => {
146+
// Provider-backed agents change status only through control-plane
147+
// actions — no silent process death to notice, so no poll.
148+
assert.equal(
149+
hasRunningAgentAnywhere([{ relayUrl: RELAY_A, status: "deployed" }]),
150+
false,
151+
);
152+
assert.equal(hasRunningAgentAnywhere(undefined), false);
153+
});
154+
155+
// ── countActiveAgentsByCommunity: the community-rail active-agents dot ───────
156+
157+
const COMMUNITIES = [
158+
{ id: "community-a", relayUrl: RELAY_A },
159+
{ id: "community-b", relayUrl: RELAY_B },
160+
];
161+
162+
test("railCounts_scopesActiveAgentsToTheirPinnedCommunity", () => {
163+
const counts = countActiveAgentsByCommunity(
164+
[
165+
{ relayUrl: RELAY_A, status: "running" },
166+
// Cosmetic URL differences must not split an agent from its community.
167+
{ relayUrl: `WS://RELAY-A.example.com:3000/`, status: "running" },
168+
{ relayUrl: RELAY_B, status: "stopped" },
169+
],
170+
COMMUNITIES,
171+
"community-b",
172+
);
173+
174+
assert.equal(counts.get("community-a"), 2);
175+
assert.equal(counts.get("community-b"), undefined);
176+
});
177+
178+
test("railCounts_deployedCountsAsActive", () => {
179+
// Mirrors isManagedAgentActive: the agents screen presents deployed
180+
// provider-backed agents as active, so the rail dot must agree.
181+
const counts = countActiveAgentsByCommunity(
182+
[{ relayUrl: RELAY_B, status: "deployed" }],
183+
COMMUNITIES,
184+
"community-a",
185+
);
186+
187+
assert.equal(counts.get("community-b"), 1);
188+
});
189+
190+
test("railCounts_blankPin_followsActiveCommunityOnly", () => {
191+
// On an all-communities surface the per-surface "blank follows the
192+
// community being viewed" fallback would light EVERY dot for one stray
193+
// unstamped record; here it must attach to the active community alone.
194+
const counts = countActiveAgentsByCommunity(
195+
[{ relayUrl: "", status: "running" }],
196+
COMMUNITIES,
197+
"community-a",
198+
);
199+
200+
assert.equal(counts.get("community-a"), 1);
201+
assert.equal(counts.get("community-b"), undefined);
202+
});
203+
204+
test("railCounts_blankPin_noActiveCommunity_countsNowhere", () => {
205+
const counts = countActiveAgentsByCommunity(
206+
[{ relayUrl: "", status: "running" }],
207+
COMMUNITIES,
208+
null,
209+
);
210+
211+
assert.equal(counts.size, 0);
212+
});
213+
214+
test("railCounts_communitiesSharingARelay_bothLight", () => {
215+
const counts = countActiveAgentsByCommunity(
216+
[{ relayUrl: RELAY_A, status: "running" }],
217+
[
218+
{ id: "community-a", relayUrl: RELAY_A },
219+
{ id: "community-a-alias", relayUrl: `${RELAY_A}/` },
220+
],
221+
"community-a",
222+
);
223+
224+
assert.equal(counts.get("community-a"), 1);
225+
assert.equal(counts.get("community-a-alias"), 1);
226+
});
227+
228+
test("railCounts_undefinedAgents_yieldsEmpty", () => {
229+
const counts = countActiveAgentsByCommunity(undefined, COMMUNITIES, null);
230+
assert.equal(counts.size, 0);
231+
});

‎desktop/src/features/agents/agentRelayScope.ts‎

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,64 @@ export function hasRunningAgentInCommunity(
9696
agentBelongsToRelay(agent.relayUrl, communityRelayUrl),
9797
);
9898
}
99+
100+
/**
101+
* Whether any local agent process is running, in ANY community. Drives the
102+
* slow cross-community poll tier: all-communities surfaces (the community
103+
* rail's active-agents dot, the "running in other communities" line) render
104+
* last-known process state for backgrounded communities, so a relaxed poll
105+
* must keep that state from going permanently stale when a background
106+
* process dies. Deployed (provider-backed) agents are excluded — their
107+
* status changes only through control-plane actions, never silently.
108+
*/
109+
export function hasRunningAgentAnywhere(
110+
agents: readonly { status: string }[] | undefined,
111+
): boolean {
112+
return (agents ?? []).some((agent) => agent.status === "running");
113+
}
114+
115+
/**
116+
* Active (running or deployed — mirrors `isManagedAgentActive`) managed
117+
* agents per community id, for surfaces that render ALL communities at once
118+
* (the community rail).
119+
*
120+
* A pinned agent counts toward every community whose relay normalizes to
121+
* its pin — two rail entries pointing at the same relay genuinely share
122+
* their agents. A blank pin counts toward the ACTIVE community only: the
123+
* per-surface `agentBelongsToRelay` fallback ("blank follows the community
124+
* being viewed") would light every community for one stray unstamped
125+
* record when evaluated against all of them side by side.
126+
*/
127+
export function countActiveAgentsByCommunity(
128+
agents: readonly { relayUrl?: string | null; status: string }[] | undefined,
129+
communities: readonly { id: string; relayUrl: string }[],
130+
activeCommunityId: string | null,
131+
): Map<string, number> {
132+
const counts = new Map<string, number>();
133+
const idsByRelay = new Map<string, string[]>();
134+
for (const community of communities) {
135+
const key = normalizeRelayUrlForCompare(community.relayUrl);
136+
const ids = idsByRelay.get(key);
137+
if (ids) {
138+
ids.push(community.id);
139+
} else {
140+
idsByRelay.set(key, [community.id]);
141+
}
142+
}
143+
for (const agent of agents ?? []) {
144+
if (agent.status !== "running" && agent.status !== "deployed") {
145+
continue;
146+
}
147+
const pinned = agent.relayUrl?.trim() ?? "";
148+
const ids =
149+
pinned === ""
150+
? activeCommunityId !== null
151+
? [activeCommunityId]
152+
: []
153+
: (idsByRelay.get(normalizeRelayUrlForCompare(pinned)) ?? []);
154+
for (const id of ids) {
155+
counts.set(id, (counts.get(id) ?? 0) + 1);
156+
}
157+
}
158+
return counts;
159+
}

‎desktop/src/features/agents/hooks.ts‎

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import * as React from "react";
22
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
33

4-
import { hasRunningAgentInCommunity } from "@/features/agents/agentRelayScope";
4+
import {
5+
hasRunningAgentAnywhere,
6+
hasRunningAgentInCommunity,
7+
} from "@/features/agents/agentRelayScope";
58
import {
69
attachManagedAgentToChannel,
710
createChannelManagedAgents,
@@ -294,11 +297,18 @@ export function useManagedAgentsQuery(options?: { enabled?: boolean }) {
294297
// with no relay event to signal it, so this poll is the only liveness
295298
// path for them. When nothing is running there IS an event path —
296299
// `agents-data-changed` (control-plane changes) — so the idle branch
297-
// drops its poll entirely rather than falling back to 30s. Scoped to
298-
// the active community's relay: agents left running in other
299-
// communities render no process state on this community's surfaces,
300-
// so they must not keep its poll alive.
301-
return hasRunningAgentInCommunity(agents, activeRelayUrl) ? 5_000 : false;
300+
// drops its poll entirely rather than falling back to 30s. Two tiers:
301+
// 5s while an agent in the ACTIVE community runs (its rows render live
302+
// process state), relaxed to 60s while agents run only in other
303+
// communities — those surface merely as last-known indicators (the
304+
// community rail's active-agents dot, the "running in other
305+
// communities" line), which must still notice a background process
306+
// dying rather than staying green forever.
307+
return hasRunningAgentInCommunity(agents, activeRelayUrl)
308+
? 5_000
309+
: hasRunningAgentAnywhere(agents)
310+
? 60_000
311+
: false;
302312
},
303313
});
304314
}

‎desktop/src/features/sidebar/ui/CommunityRail.test.mjs‎

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import assert from "node:assert/strict";
22
import { describe, it } from "node:test";
33

4-
import { communityRailIndicators } from "./CommunityRail.tsx";
4+
import {
5+
communityRailIndicators,
6+
communityRailTooltipLabel,
7+
} from "./CommunityRail.tsx";
58

69
describe("communityRailIndicators", () => {
710
it("shows no badge for an observed community with unread but no mentions", () => {
@@ -70,3 +73,55 @@ describe("communityRailIndicators", () => {
7073
assert.equal(r.pending, false);
7174
});
7275
});
76+
77+
describe("communityRailTooltipLabel", () => {
78+
const quiet = { showBadge: false, showDot: false, mentionCount: 0 };
79+
80+
it("is just the name with nothing to report", () => {
81+
assert.equal(communityRailTooltipLabel("Acme", quiet, 0), "Acme");
82+
});
83+
84+
it("reports active agents with singular/plural forms", () => {
85+
assert.equal(
86+
communityRailTooltipLabel("Acme", quiet, 1),
87+
"Acme — 1 agent active",
88+
);
89+
assert.equal(
90+
communityRailTooltipLabel("Acme", quiet, 3),
91+
"Acme — 3 agents active",
92+
);
93+
});
94+
95+
it("combines mentions with active agents — mentions beat plain unread", () => {
96+
assert.equal(
97+
communityRailTooltipLabel(
98+
"Acme",
99+
{ showBadge: true, showDot: false, mentionCount: 2 },
100+
1,
101+
),
102+
"Acme — 2 mentions, 1 agent active",
103+
);
104+
});
105+
106+
it("combines plain unread with active agents", () => {
107+
assert.equal(
108+
communityRailTooltipLabel(
109+
"Acme",
110+
{ showBadge: false, showDot: true, mentionCount: 0 },
111+
2,
112+
),
113+
"Acme — unread, 2 agents active",
114+
);
115+
});
116+
117+
it("keeps the plain unread form without agents", () => {
118+
assert.equal(
119+
communityRailTooltipLabel(
120+
"Acme",
121+
{ showBadge: false, showDot: true, mentionCount: 0 },
122+
0,
123+
),
124+
"Acme — unread",
125+
);
126+
});
127+
});

0 commit comments

Comments
 (0)