feat(desktop): pulse thread ingress rows while an agent works in the thread

Derive a stable, sorted set of working thread head ids from thread-scoped
bot typing entries in ChannelPane and pass it down the timeline as a
ReadonlySet, so each thread summary row gets a plain boolean instead of
scanning raw typing entries. The set identity only changes when the set of
working threads changes — not on each 1s typing prune tick — preserving the
existing timeline memo boundaries. Channel-level working surfaces are
untouched; thread-only typing still stays out of agentWorkingSignal.

The badge is a small motion-safe pulsing dot on the matching
MessageThreadSummaryRow, with an aria-label suffix for screen readers.

Co-authored-by: Taylor Ho <taylorkmho@gmail.com>
Signed-off-by: Taylor Ho <taylorkmho@gmail.com>
This commit is contained in:
npub1223z34hd7vtwc6qj4s7flsxkj644nlre2nthu7lrrmkumhu3xddsrx9r6w
2026-07-06 21:32:24 -07:00
parent 1f5ba5bb27
commit 9ebae61c1c
6 changed files with 105 additions and 3 deletions

View File

@@ -45,6 +45,7 @@ import {
mentionsKnownAgent,
} from "@/features/channels/ui/ChannelPane.helpers";
import type { ChannelPaneProps } from "@/features/channels/ui/ChannelPane.types";
import { threadScopedBotTypingHeadIdKey } from "@/features/channels/ui/useChannelActivityTyping";
import * as agentSessionSelection from "@/features/channels/ui/agentSessionSelection";
import { Button } from "@/shared/ui/button";
import { buildMainTimelineEntries } from "@/features/messages/lib/threadPanel";
@@ -55,6 +56,10 @@ import { KIND_SYSTEM_MESSAGE } from "@/shared/constants/kinds";
import { useIsThreadPanelOverlay } from "@/shared/hooks/use-mobile";
import { channelChrome } from "@/shared/layout/chromeLayout";
import { cn } from "@/shared/lib/cn";
/** Stable empty set so no-typing renders keep a constant identity. */
const EMPTY_WORKING_THREAD_HEAD_IDS: ReadonlySet<string> = new Set();
export const ChannelPane = React.memo(function ChannelPane({
activeChannel,
agentPubkeys,
@@ -356,6 +361,19 @@ export const ChannelPane = React.memo(function ChannelPane({
}, [botTypingEntries, openThreadHeadId]);
const hasThreadComposerBotActivity =
threadComposerBotTypingPubkeys.length > 0;
// Thread ingress working badges: derive once per typing update, keyed on a
// stable sorted string so the Set identity (and every memoized row below it)
// only changes when the set of working threads changes — not on each 1s
// typing prune tick or entry-array recreation.
const workingThreadHeadIdKey =
threadScopedBotTypingHeadIdKey(botTypingEntries);
const workingThreadHeadIds = React.useMemo<ReadonlySet<string>>(
() =>
workingThreadHeadIdKey
? new Set(workingThreadHeadIdKey.split(","))
: EMPTY_WORKING_THREAD_HEAD_IDS,
[workingThreadHeadIdKey],
);
const directMessageIntro = React.useMemo(
() =>
buildDirectMessageIntro({
@@ -624,6 +642,7 @@ export const ChannelPane = React.memo(function ChannelPane({
searchQuery={channelFind.query}
targetMessageId={targetMessageId}
threadUnreadCounts={threadUnreadCounts}
workingThreadHeadIds={workingThreadHeadIds}
/>
{isNonMemberView ? (
<div

View File

@@ -8,7 +8,10 @@ import {
resetAgentWorkingSignal,
} from "../../agents/agentWorkingSignal.ts";
import { resetActiveAgentTurnsStore } from "../../agents/activeAgentTurnsStore.ts";
import { channelScopedBotTypingPubkeyKey } from "./useChannelActivityTyping.ts";
import {
channelScopedBotTypingPubkeyKey,
threadScopedBotTypingHeadIdKey,
} from "./useChannelActivityTyping.ts";
const AGENT =
"abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234";
@@ -40,6 +43,44 @@ describe("channelScopedBotTypingPubkeyKey", () => {
});
});
describe("threadScopedBotTypingHeadIdKey", () => {
it("excludes channel-scoped typing entries", () => {
const key = threadScopedBotTypingHeadIdKey([
{ pubkey: AGENT, threadHeadId: null },
]);
assert.equal(key, "");
});
it("keeps thread-scoped entries and drops channel-scoped ones", () => {
const key = threadScopedBotTypingHeadIdKey([
{ pubkey: AGENT, threadHeadId: null },
{ pubkey: AGENT_2, threadHeadId: "thread-1" },
]);
assert.equal(key, "thread-1");
});
it("dedupes multiple agents in the same thread and sorts head ids", () => {
const key = threadScopedBotTypingHeadIdKey([
{ pubkey: AGENT, threadHeadId: "thread-2" },
{ pubkey: AGENT_2, threadHeadId: "thread-1" },
{ pubkey: AGENT, threadHeadId: "thread-1" },
]);
assert.equal(key, "thread-1,thread-2");
});
it("is stable across entry order so memoized row state keeps identity", () => {
const first = threadScopedBotTypingHeadIdKey([
{ pubkey: AGENT, threadHeadId: "thread-1" },
{ pubkey: AGENT_2, threadHeadId: "thread-2" },
]);
const second = threadScopedBotTypingHeadIdKey([
{ pubkey: AGENT_2, threadHeadId: "thread-2" },
{ pubkey: AGENT, threadHeadId: "thread-1" },
]);
assert.equal(first, second);
});
});
describe("thread-only bot typing regression", () => {
beforeEach(() => {
resetActiveAgentTurnsStore();

View File

@@ -31,6 +31,25 @@ export function channelScopedBotTypingPubkeyKey(
.join(",");
}
/**
* Stable key of thread head ids with active bot typing. Deduped and sorted so
* the key (and anything memoized on it) only changes identity when the set of
* working threads actually changes — not on every typing prune tick. Channel
* -scoped entries (`threadHeadId === null`) are excluded; they belong to
* channel-level surfaces.
*/
export function threadScopedBotTypingHeadIdKey(
entries: readonly Pick<TypingIndicatorEntry, "threadHeadId">[],
): string {
const headIds = new Set<string>();
for (const entry of entries) {
if (entry.threadHeadId !== null) {
headIds.add(entry.threadHeadId);
}
}
return [...headIds].sort().join(",");
}
export function useChannelActivityTyping({
activeChannel,
activeChannelId,

View File

@@ -59,6 +59,7 @@ export function MessageThreadSummaryRow({
depth = 0,
depthGuideDepths,
highlightThreadLineDepths,
isAgentWorking = false,
message,
onCollapseDepthGuide,
onCollapseDepthGuideHoverChange,
@@ -72,6 +73,8 @@ export function MessageThreadSummaryRow({
depth?: number;
depthGuideDepths?: ReadonlyArray<number>;
highlightThreadLineDepths?: ReadonlyArray<number>;
/** True when an agent is actively working (bot typing) in this thread. */
isAgentWorking?: boolean;
message: TimelineMessage;
onCollapseDepthGuide?: (message: TimelineMessage) => void;
onCollapseDepthGuideHoverChange?: (
@@ -95,9 +98,10 @@ export function MessageThreadSummaryRow({
THREAD_SUMMARY_SURFACE_AVATAR_INSET_REM,
)})`;
const replyLabel = summary.replyCount === 1 ? "reply" : "replies";
const workingSuffix = isAgentWorking ? ", agent working" : "";
const summaryAriaLabel = summary.lastReplyAt
? `View thread with ${summary.replyCount} ${replyLabel}, last reply ${formatThreadSummaryLastReplyTime(summary.lastReplyAt)}`
: `View thread with ${summary.replyCount} ${replyLabel}`;
? `View thread with ${summary.replyCount} ${replyLabel}, last reply ${formatThreadSummaryLastReplyTime(summary.lastReplyAt)}${workingSuffix}`
: `View thread with ${summary.replyCount} ${replyLabel}${workingSuffix}`;
const guideDepths = depthGuideDepths
? [...depthGuideDepths]
: Array.from({ length: Math.max(0, depth - 1) }, (_, index) => index + 1);
@@ -240,6 +244,13 @@ export function MessageThreadSummaryRow({
/>
))}
</div>
{isAgentWorking ? (
<span
aria-hidden="true"
className="relative z-10 h-1.5 w-1.5 shrink-0 rounded-full bg-primary motion-safe:animate-pulse"
data-testid="message-thread-summary-working-badge"
/>
) : null}
<div className="relative z-10 min-w-0">
<div>
<span className="font-medium transition-colors group-hover:text-foreground">

View File

@@ -97,6 +97,8 @@ type MessageTimelineProps = {
unreadCount?: number;
/** Per-thread unread counts keyed by thread root id. */
threadUnreadCounts?: ReadonlyMap<string, number>;
/** Thread root ids with an agent actively working (bot typing). */
workingThreadHeadIds?: ReadonlySet<string>;
};
type ChannelIntroAction = {
@@ -184,6 +186,7 @@ const MessageTimelineBase = React.forwardRef<
firstUnreadMessageId = null,
unreadCount = 0,
threadUnreadCounts,
workingThreadHeadIds,
}: MessageTimelineProps,
ref,
) {
@@ -614,6 +617,7 @@ const MessageTimelineBase = React.forwardRef<
searchQuery={searchQuery}
threadUnreadCounts={threadUnreadCounts}
unfollowThreadById={unfollowThreadById}
workingThreadHeadIds={workingThreadHeadIds}
/>
</div>
) : null}

View File

@@ -81,6 +81,8 @@ type TimelineMessageListProps = {
searchQuery?: string;
/** Per-thread unread counts keyed by thread root id. */
threadUnreadCounts?: ReadonlyMap<string, number>;
/** Thread root ids with an agent actively working (bot typing). */
workingThreadHeadIds?: ReadonlySet<string>;
};
export const TimelineMessageList = React.memo(function TimelineMessageList({
@@ -114,6 +116,7 @@ export const TimelineMessageList = React.memo(function TimelineMessageList({
searchQuery,
threadUnreadCounts,
unfollowThreadById,
workingThreadHeadIds,
}: TimelineMessageListProps) {
const entries = React.useMemo(
() =>
@@ -224,6 +227,7 @@ export const TimelineMessageList = React.memo(function TimelineMessageList({
videoReviewContext={videoReviewContextById.get(
item.entry.message.id,
)}
workingThreadHeadIds={workingThreadHeadIds}
/>
);
}
@@ -252,6 +256,7 @@ export const TimelineMessageList = React.memo(function TimelineMessageList({
threadUnreadCounts,
unfollowThreadById,
videoReviewContextById,
workingThreadHeadIds,
],
);
@@ -338,6 +343,7 @@ type MessageRowItemProps = Pick<
| "searchQuery"
| "threadUnreadCounts"
| "unfollowThreadById"
| "workingThreadHeadIds"
> & {
entry: MainTimelineEntry;
footer: React.ReactNode;
@@ -374,6 +380,7 @@ function MessageRowItem({
threadUnreadCounts,
unfollowThreadById,
videoReviewContext,
workingThreadHeadIds,
}: MessageRowItemProps) {
const { message, summary } = entry;
const canManage = canManageMessageForCurrentUser(
@@ -429,6 +436,7 @@ function MessageRowItem({
/>
<MessageThreadSummaryRow
depth={message.depth}
isAgentWorking={workingThreadHeadIds?.has(message.id) ?? false}
message={message}
onOpenThread={onReply}
showDepthGuides={false}