Track the chat's PR link from any participant, not just agents

Author-scoping the work panel's PR scan proved brittle twice over:
first it matched only the default agent, then only the viewer's
managed agents — an agent someone else added to the chat still slipped
through, leaving the panel on the bare branch chip. Any PR link posted
in the chat is the chat's work; the scan now simply takes the latest
one regardless of author.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
klopez4212
2026-07-07 07:51:26 +01:00
co-authored by Claude Fable 5
parent cf1f4b5dbc
commit 48a9ff9742
+8 -29
View File
@@ -310,42 +310,21 @@ export function ChatsScreen({
);
const archiveChatMutation = useArchiveChatMutation();
// Latest PR link ANY agent in the chat posted — drives the header toggle
// and the top-right work module. Matching only the default agent missed
// PRs from additional agents added to the chat.
// Latest PR link posted in the chat by ANY participant — drives the header
// toggle and the top-right work module. Author-scoping this proved too
// brittle (agents added to the chat aren't necessarily in the viewer's
// managed list), and a PR link dropped by a human is the chat's work too.
const agentPullRequestHref = React.useMemo(() => {
const agentKeys = new Set(
(managedAgentsQuery.data ?? []).map((agent) =>
normalizePubkey(agent.pubkey),
),
);
const configuredAgent =
metadata?.defaultAgentPubkey ?? defaultAgent?.pubkey;
if (configuredAgent) {
agentKeys.add(normalizePubkey(configuredAgent));
}
if (agentKeys.size === 0) {
return null;
}
for (let index = messages.length - 1; index >= 0; index--) {
const message = messages[index];
if (!agentKeys.has(normalizePubkey(message.pubkey))) {
continue;
}
const preview = extractSupportedLinkPreviews(message.content).find(
(candidate) => candidate.kind === "github-pull-request",
);
const preview = extractSupportedLinkPreviews(
messages[index].content,
).find((candidate) => candidate.kind === "github-pull-request");
if (preview) {
return preview.href;
}
}
return null;
}, [
defaultAgent?.pubkey,
managedAgentsQuery.data,
messages,
metadata?.defaultAgentPubkey,
]);
}, [messages]);
// null = auto: open once the agent has produced a PR, closed otherwise.
// A click stores an explicit preference for the current chat.
const [workPanelPreference, setWorkPanelPreference] = React.useState<