Toggle the chat work panel from the header

A pull-request button sits left of the chat settings menu whenever the
agent has posted a PR, toggling the top-right work module (tinted
primary while open; each chat starts with it visible). The panel's
card now uses the standard rich PR card style, matching PR link cards
elsewhere.

Splits ChatList out of ChatsScreen (file size ceiling) with the
shared-chat metadata check moved to lib/chatShared.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
klopez4212
2026-07-04 11:35:08 +01:00
parent 3c23b8e62c
commit 8c7f49d1fb
7 changed files with 425 additions and 362 deletions

View File

@@ -0,0 +1,15 @@
import type { ChatMetadata } from "@/shared/api/types";
import { normalizePubkey } from "@/shared/lib/pubkey";
/** Chat metadata authored by someone else — a chat shared with us. */
export function isSharedChatMetadata(
metadata: ChatMetadata | null | undefined,
identityPubkey: string | null | undefined,
) {
if (!metadata?.authorPubkey || !identityPubkey) {
return false;
}
return (
normalizePubkey(metadata.authorPubkey) !== normalizePubkey(identityPubkey)
);
}

View File

@@ -47,7 +47,6 @@ import type {
} from "@/shared/api/types";
import { KIND_SYSTEM_MESSAGE } from "@/shared/constants/kinds";
import { cn } from "@/shared/lib/cn";
import { extractSupportedLinkPreviews } from "@/shared/lib/linkPreview";
import { normalizePubkey } from "@/shared/lib/pubkey";
import {
MessageScroller,
@@ -88,7 +87,11 @@ type ChatDetailProps = {
profiles?: UserProfileLookup;
projects: ChatProject[];
shareAction?: React.ReactNode;
/** Show the top-right work module for this PR (toggled from the header). */
showWorkPanel?: boolean;
templates: ChannelTemplate[];
/** Latest PR link the chat's agent posted, if any. */
workPanelHref?: string | null;
};
export function ChatDetail({
@@ -106,7 +109,9 @@ export function ChatDetail({
profiles,
projects,
shareAction,
showWorkPanel = true,
templates,
workPanelHref = null,
}: ChatDetailProps) {
const queryClient = useQueryClient();
const updateMetadataMutation = useUpdateChatMetadataMutation();
@@ -249,28 +254,6 @@ export function ChatDetail({
);
const hasTranscriptActivity = chatActivity.totalBlockCount > 0;
// The latest PR link the agent posted in this chat drives the top-right
// work module (branch + live PR card).
const agentPullRequestHref = React.useMemo(() => {
if (!defaultAgent?.pubkey) {
return null;
}
const agentKey = normalizePubkey(defaultAgent.pubkey);
for (let index = messages.length - 1; index >= 0; index--) {
const message = messages[index];
if (normalizePubkey(message.pubkey) !== agentKey) {
continue;
}
const preview = extractSupportedLinkPreviews(message.content).find(
(candidate) => candidate.kind === "github-pull-request",
);
if (preview) {
return preview.href;
}
}
return null;
}, [defaultAgent?.pubkey, messages]);
// Solo chats (you + one agent) read as a plain stream: agent rows drop
// their avatar and name. Identities come back as soon as another agent or
// person participates, so multi-party chats stay attributable.
@@ -641,8 +624,8 @@ export function ChatDetail({
/>
</div>
</div>
{agentPullRequestHref ? (
<ChatWorkPanel prHref={agentPullRequestHref} />
{workPanelHref && showWorkPanel ? (
<ChatWorkPanel prHref={workPanelHref} />
) : null}
</div>
</>

View File

@@ -50,6 +50,8 @@ type ChatHeaderActionsProps = {
defaultAgentPubkey?: string | null;
messages: RelayEvent[];
metadata: ChatMetadata | null;
/** Rendered between Share and the settings menu (work panel toggle). */
workPanelToggle?: React.ReactNode;
};
export function ChatHeaderActions({
@@ -57,6 +59,7 @@ export function ChatHeaderActions({
defaultAgentPubkey,
messages,
metadata,
workPanelToggle,
}: ChatHeaderActionsProps) {
const [isCanvasOpen, setIsCanvasOpen] = React.useState(false);
const [isDefaultAgentOpen, setIsDefaultAgentOpen] = React.useState(false);
@@ -81,6 +84,7 @@ export function ChatHeaderActions({
messages={messages}
metadata={metadata}
/>
{workPanelToggle}
<ChatSettingsMenu
onOpenCanvas={() => setIsCanvasOpen(true)}
onOpenDefaultAgent={() => setIsDefaultAgentOpen(true)}

View File

@@ -0,0 +1,321 @@
// @ts-nocheck
import * as React from "react";
import {
ChevronDown,
ChevronRight,
MoreVertical,
Notebook,
Plus,
} from "lucide-react";
import { useActiveAgentTurnsByChannel } from "@/features/agents/activeAgentTurnsStore";
import type { buildChatProjects } from "@/features/chats/lib/chatProjects";
import { ChatListHeader, ChatListItem } from "@/features/chats/ui/ChatListItem";
import { ChatListSectionHeader } from "@/features/chats/ui/ChatListSectionHeader";
import { ChatListSkeleton } from "@/features/chats/ui/ChatListSkeleton";
import { ChatProjectDialog } from "@/features/chats/ui/ChatProjectDialog";
import { isSharedChatMetadata } from "@/features/chats/lib/chatShared";
import type {
Channel,
ChannelTemplate,
ChatMetadata,
} from "@/shared/api/types";
import { Button } from "@/shared/ui/button";
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuTrigger,
} from "@/shared/ui/dropdown-menu";
export function ChatList({
archivingChatId,
chats,
getChannelReadAt,
identityPubkey,
isLoading,
metadataByChatId,
onArchiveChat,
onCreateChat,
onCreateProjectChat,
onRenameChat,
onSelectChat,
onTogglePin,
onUpdateProject,
pinnedChatIds,
projects,
readStateVersion: _readStateVersion,
selectedChatId,
templates,
unreadChannelCounts,
unreadChannelIds,
}: {
archivingChatId: string | null;
chats: Channel[];
getChannelReadAt: (channelId: string) => number | null;
identityPubkey?: string | null;
isLoading: boolean;
metadataByChatId: ReadonlyMap<string, ChatMetadata>;
onArchiveChat: (chatId: string) => void;
onCreateChat: () => void;
onCreateProjectChat: (projectId: string) => void;
onRenameChat: (chatId: string) => void;
onSelectChat: (chatId: string) => void;
onTogglePin: (chatId: string) => void;
pinnedChatIds: ReadonlySet<string>;
onUpdateProject: (
project: ReturnType<typeof buildChatProjects>[number],
) => void;
projects: ReturnType<typeof buildChatProjects>;
readStateVersion: number;
selectedChatId: string | null;
templates: ChannelTemplate[];
unreadChannelCounts: ReadonlyMap<string, number>;
unreadChannelIds: ReadonlySet<string>;
}) {
const [collapsedProjectIds, setCollapsedProjectIds] = React.useState(
() => new Set<string>(),
);
const [editingProject, setEditingProject] = React.useState<
ReturnType<typeof buildChatProjects>[number] | null
>(null);
const [isCreateProjectOpen, setIsCreateProjectOpen] = React.useState(false);
const activeAgentTurnsByChannel = useActiveAgentTurnsByChannel();
const activeChatIds = React.useMemo(
() => new Set(activeAgentTurnsByChannel.map((turn) => turn.channelId)),
[activeAgentTurnsByChannel],
);
const chatsByProject = React.useMemo(() => {
const groups = new Map<string, Channel[]>();
const unprojected: Channel[] = [];
const shared: Channel[] = [];
const knownProjectIds = new Set(projects.map((project) => project.id));
for (const chat of chats) {
const metadata = metadataByChatId.get(chat.id);
if (isSharedChatMetadata(metadata, identityPubkey)) {
shared.push(chat);
continue;
}
const projectId = metadata?.projectId;
if (projectId && knownProjectIds.has(projectId)) {
const group = groups.get(projectId) ?? [];
group.push(chat);
groups.set(projectId, group);
} else {
unprojected.push(chat);
}
}
const pinnedFirst = (list: Channel[]) =>
[...list].sort(
(left, right) =>
Number(pinnedChatIds.has(right.id)) -
Number(pinnedChatIds.has(left.id)),
);
return {
groups: new Map(
[...groups.entries()].map(([projectId, group]) => [
projectId,
pinnedFirst(group),
]),
),
shared: pinnedFirst(shared),
unprojected: pinnedFirst(unprojected),
};
}, [chats, identityPubkey, metadataByChatId, pinnedChatIds, projects]);
const toggleProject = React.useCallback((projectId: string) => {
setCollapsedProjectIds((current) => {
const next = new Set(current);
if (next.has(projectId)) {
next.delete(projectId);
} else {
next.add(projectId);
}
return next;
});
}, []);
if (isLoading) {
return (
<div className="flex h-full min-h-0 flex-col">
<ChatListHeader />
<ChatListSkeleton />
</div>
);
}
return (
<div className="flex h-full min-h-0 flex-col">
<ChatListHeader />
<div className="buzz-sidebar-scrollbar min-h-0 flex-1 overflow-y-auto p-2 pt-3">
<div className="mb-3 space-y-1">
<ChatListSectionHeader
actionLabel="Add project"
label="Projects"
onAction={() => setIsCreateProjectOpen(true)}
/>
{projects.map((project) => {
const projectChats = chatsByProject.groups.get(project.id) ?? [];
const isCollapsed = collapsedProjectIds.has(project.id);
return (
<div key={project.id} className="mb-1">
<div className="group/project flex h-8 w-full min-w-0 items-center gap-1.5 rounded-md px-2 text-xs font-semibold text-muted-foreground transition-colors hover:bg-muted/60 hover:text-foreground">
<Notebook className="h-3.5 w-3.5 shrink-0" />
<button
className="flex min-w-0 flex-1 items-center gap-1.5 text-left"
onClick={() => toggleProject(project.id)}
type="button"
>
<span className="min-w-0 truncate">{project.name}</span>
{isCollapsed ? (
<ChevronRight className="h-3.5 w-3.5 shrink-0" />
) : (
<ChevronDown className="h-3.5 w-3.5 shrink-0" />
)}
</button>
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button
aria-label={`Project settings for ${project.name}`}
className="h-6 w-6 text-muted-foreground opacity-0 transition-opacity hover:text-foreground focus-visible:opacity-100 data-[state=open]:opacity-100 group-hover/project:opacity-100"
size="icon-xs"
type="button"
variant="ghost"
>
<MoreVertical className="h-3.5 w-3.5" />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end" className="w-44">
<DropdownMenuItem
onSelect={() => setEditingProject(project)}
>
Project settings
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
<Button
aria-label={`New chat in ${project.name}`}
className="h-6 w-6 text-muted-foreground opacity-0 transition-opacity hover:text-foreground focus-visible:opacity-100 group-hover/project:opacity-100"
onClick={() => onCreateProjectChat(project.id)}
size="icon-xs"
type="button"
variant="ghost"
>
<Plus className="h-3.5 w-3.5" />
</Button>
</div>
{!isCollapsed ? (
<div className="space-y-1">
{projectChats.length > 0 ? (
projectChats.map((chat) => (
<ChatListItem
chat={chat}
displayName={metadataByChatId.get(chat.id)?.title}
getChannelReadAt={getChannelReadAt}
isAgentRunning={activeChatIds.has(chat.id)}
isArchiving={archivingChatId === chat.id}
isPinned={pinnedChatIds.has(chat.id)}
key={chat.id}
onArchiveChat={onArchiveChat}
onRenameChat={onRenameChat}
onSelectChat={onSelectChat}
onTogglePin={onTogglePin}
selectedChatId={selectedChatId}
unreadChannelCounts={unreadChannelCounts}
unreadChannelIds={unreadChannelIds}
/>
))
) : (
<div className="px-3 py-1.5 text-xs text-muted-foreground">
No chats yet
</div>
)}
</div>
) : null}
</div>
);
})}
</div>
<div className="space-y-1">
<ChatListSectionHeader
actionLabel="New chat without a project"
label="Chats"
onAction={onCreateChat}
/>
{chatsByProject.unprojected.length > 0 ? (
chatsByProject.unprojected.map((chat) => (
<ChatListItem
chat={chat}
displayName={metadataByChatId.get(chat.id)?.title}
getChannelReadAt={getChannelReadAt}
isAgentRunning={activeChatIds.has(chat.id)}
isArchiving={archivingChatId === chat.id}
isPinned={pinnedChatIds.has(chat.id)}
key={chat.id}
onArchiveChat={onArchiveChat}
onRenameChat={onRenameChat}
onSelectChat={onSelectChat}
onTogglePin={onTogglePin}
selectedChatId={selectedChatId}
unreadChannelCounts={unreadChannelCounts}
unreadChannelIds={unreadChannelIds}
/>
))
) : (
<div className="px-3 py-1.5 text-xs text-muted-foreground">
No chats yet
</div>
)}
</div>
{chatsByProject.shared.length > 0 ? (
<div className="mt-4 space-y-1">
<ChatListSectionHeader label="Shared" />
{chatsByProject.shared.map((chat) => (
<ChatListItem
canRename={false}
chat={chat}
displayName={metadataByChatId.get(chat.id)?.title}
getChannelReadAt={getChannelReadAt}
isAgentRunning={activeChatIds.has(chat.id)}
isArchiving={archivingChatId === chat.id}
isPinned={pinnedChatIds.has(chat.id)}
key={chat.id}
onArchiveChat={onArchiveChat}
onRenameChat={onRenameChat}
onSelectChat={onSelectChat}
onTogglePin={onTogglePin}
selectedChatId={selectedChatId}
unreadChannelCounts={unreadChannelCounts}
unreadChannelIds={unreadChannelIds}
/>
))}
</div>
) : null}
</div>
<ChatProjectDialog
onOpenChange={setIsCreateProjectOpen}
onSaveProject={(project) => {
onUpdateProject(project);
setIsCreateProjectOpen(false);
}}
open={isCreateProjectOpen}
templates={templates}
/>
<ChatProjectDialog
mode="edit"
onOpenChange={(open) => {
if (!open) {
setEditingProject(null);
}
}}
onSaveProject={(project) => {
onUpdateProject(project);
setEditingProject(null);
}}
open={editingProject !== null}
project={editingProject}
templates={templates}
/>
</div>
);
}

View File

@@ -5,7 +5,7 @@ import {
useGithubPullRequestQuery,
} from "@/shared/lib/githubPullRequest";
import { parseSupportedLinkPreview } from "@/shared/lib/linkPreview";
import { AgentPullRequestCard } from "@/shared/ui/link-preview-attachment";
import { GithubPullRequestCard } from "@/shared/ui/link-preview-attachment";
/**
* Right-hand work module for a chat whose agent produced a pull request:
@@ -36,7 +36,7 @@ export function ChatWorkPanel({ prHref }: { prHref: string }) {
<span className="min-w-0 truncate font-mono">{branch}</span>
</div>
) : null}
<AgentPullRequestCard preview={preview} />
<GithubPullRequestCard className="w-full" preview={preview} />
</aside>
);
}

View File

@@ -2,17 +2,10 @@
import * as React from "react";
import { useQueryClient } from "@tanstack/react-query";
import { toast } from "sonner";
import {
ChevronDown,
ChevronRight,
MoreVertical,
Notebook,
Plus,
} from "lucide-react";
import { GitPullRequest } from "lucide-react";
import { useAppNavigation } from "@/app/navigation/useAppNavigation";
import { useAppShell } from "@/app/AppShellContext";
import { useActiveAgentTurnsByChannel } from "@/features/agents/activeAgentTurnsStore";
import {
useManagedAgentsQuery,
useStartManagedAgentMutation,
@@ -26,6 +19,8 @@ import {
useUpdateChatMetadataMutation,
} from "@/features/chats/hooks";
import { buildChatProjects } from "@/features/chats/lib/chatProjects";
import { isSharedChatMetadata } from "@/features/chats/lib/chatShared";
import { ChatList } from "@/features/chats/ui/ChatList";
import {
toggleStoredChatPin,
useStoredChatPins,
@@ -42,10 +37,6 @@ import {
} from "@/features/chats/lib/chatSetup";
import { ChatDetail } from "@/features/chats/ui/ChatDetail";
import { ChatHeaderActions } from "@/features/chats/ui/ChatHeaderActions";
import { ChatListHeader, ChatListItem } from "@/features/chats/ui/ChatListItem";
import { ChatListSectionHeader } from "@/features/chats/ui/ChatListSectionHeader";
import { ChatListSkeleton } from "@/features/chats/ui/ChatListSkeleton";
import { ChatProjectDialog } from "@/features/chats/ui/ChatProjectDialog";
import { ChatRenameDialog } from "@/features/chats/ui/ChatRenameDialog";
import { QuickStartChat } from "@/features/chats/ui/QuickStartChat";
import {
@@ -58,19 +49,10 @@ import { useUsersBatchQuery } from "@/features/profile/hooks";
import { useWorkspaces } from "@/features/workspaces/useWorkspaces";
import { useIdentityQuery } from "@/shared/api/hooks";
import { addChannelMembers, getCanvas, setCanvas } from "@/shared/api/tauri";
import type {
Channel,
ChannelTemplate,
ChatMetadata,
} from "@/shared/api/types";
import { extractSupportedLinkPreviews } from "@/shared/lib/linkPreview";
import { cn } from "@/shared/lib/cn";
import { normalizePubkey } from "@/shared/lib/pubkey";
import { Button } from "@/shared/ui/button";
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuTrigger,
} from "@/shared/ui/dropdown-menu";
type ChatsScreenProps = {
initialProjectId?: string | null;
@@ -100,18 +82,6 @@ async function addBotToChat(channelId: string, pubkey: string) {
}
}
function isSharedChatMetadata(
metadata: ChatMetadata | null | undefined,
identityPubkey: string | null | undefined,
) {
if (!metadata?.authorPubkey || !identityPubkey) {
return false;
}
return (
normalizePubkey(metadata.authorPubkey) !== normalizePubkey(identityPubkey)
);
}
export function ChatsScreen({
initialProjectId,
selectedChatId = null,
@@ -339,6 +309,36 @@ export function ChatsScreen({
identityQuery.data,
);
const archiveChatMutation = useArchiveChatMutation();
// Latest PR link the chat's agent posted — drives the header toggle and
// the top-right work module in the conversation.
const agentPullRequestHref = React.useMemo(() => {
const agentPubkey = metadata?.defaultAgentPubkey ?? defaultAgent?.pubkey;
if (!agentPubkey) {
return null;
}
const agentKey = normalizePubkey(agentPubkey);
for (let index = messages.length - 1; index >= 0; index--) {
const message = messages[index];
if (normalizePubkey(message.pubkey) !== agentKey) {
continue;
}
const preview = extractSupportedLinkPreviews(message.content).find(
(candidate) => candidate.kind === "github-pull-request",
);
if (preview) {
return preview.href;
}
}
return null;
}, [defaultAgent?.pubkey, messages, metadata?.defaultAgentPubkey]);
const [isWorkPanelOpen, setIsWorkPanelOpen] = React.useState(true);
const workPanelChatRef = React.useRef(selectedChatId);
if (workPanelChatRef.current !== selectedChatId) {
// Each chat starts with its work module visible.
workPanelChatRef.current = selectedChatId;
setIsWorkPanelOpen(true);
}
const startManagedAgentMutation = useStartManagedAgentMutation();
const [isEnsuringDefaultAgent, setIsEnsuringDefaultAgent] =
React.useState(false);
@@ -616,12 +616,36 @@ export function ChatsScreen({
onSend={handleSend}
profiles={profiles}
projects={chatProjects}
showWorkPanel={isWorkPanelOpen}
workPanelHref={agentPullRequestHref}
shareAction={
<ChatHeaderActions
chat={selectedChat}
defaultAgentPubkey={defaultAgent?.pubkey}
messages={messages}
metadata={metadata}
workPanelToggle={
agentPullRequestHref ? (
<Button
aria-label={
isWorkPanelOpen ? "Hide work panel" : "Show work panel"
}
aria-pressed={isWorkPanelOpen}
data-testid="toggle-work-panel"
onClick={() => setIsWorkPanelOpen((open) => !open)}
size="icon"
type="button"
variant="ghost"
>
<GitPullRequest
className={cn(
"h-4 w-4",
isWorkPanelOpen && "text-primary",
)}
/>
</Button>
) : null
}
/>
}
templates={templates}
@@ -654,295 +678,3 @@ export function ChatsScreen({
</div>
);
}
function ChatList({
archivingChatId,
chats,
getChannelReadAt,
identityPubkey,
isLoading,
metadataByChatId,
onArchiveChat,
onCreateChat,
onCreateProjectChat,
onRenameChat,
onSelectChat,
onTogglePin,
onUpdateProject,
pinnedChatIds,
projects,
readStateVersion: _readStateVersion,
selectedChatId,
templates,
unreadChannelCounts,
unreadChannelIds,
}: {
archivingChatId: string | null;
chats: Channel[];
getChannelReadAt: (channelId: string) => number | null;
identityPubkey?: string | null;
isLoading: boolean;
metadataByChatId: ReadonlyMap<string, ChatMetadata>;
onArchiveChat: (chatId: string) => void;
onCreateChat: () => void;
onCreateProjectChat: (projectId: string) => void;
onRenameChat: (chatId: string) => void;
onSelectChat: (chatId: string) => void;
onTogglePin: (chatId: string) => void;
pinnedChatIds: ReadonlySet<string>;
onUpdateProject: (
project: ReturnType<typeof buildChatProjects>[number],
) => void;
projects: ReturnType<typeof buildChatProjects>;
readStateVersion: number;
selectedChatId: string | null;
templates: ChannelTemplate[];
unreadChannelCounts: ReadonlyMap<string, number>;
unreadChannelIds: ReadonlySet<string>;
}) {
const [collapsedProjectIds, setCollapsedProjectIds] = React.useState(
() => new Set<string>(),
);
const [editingProject, setEditingProject] = React.useState<
ReturnType<typeof buildChatProjects>[number] | null
>(null);
const [isCreateProjectOpen, setIsCreateProjectOpen] = React.useState(false);
const activeAgentTurnsByChannel = useActiveAgentTurnsByChannel();
const activeChatIds = React.useMemo(
() => new Set(activeAgentTurnsByChannel.map((turn) => turn.channelId)),
[activeAgentTurnsByChannel],
);
const chatsByProject = React.useMemo(() => {
const groups = new Map<string, Channel[]>();
const unprojected: Channel[] = [];
const shared: Channel[] = [];
const knownProjectIds = new Set(projects.map((project) => project.id));
for (const chat of chats) {
const metadata = metadataByChatId.get(chat.id);
if (isSharedChatMetadata(metadata, identityPubkey)) {
shared.push(chat);
continue;
}
const projectId = metadata?.projectId;
if (projectId && knownProjectIds.has(projectId)) {
const group = groups.get(projectId) ?? [];
group.push(chat);
groups.set(projectId, group);
} else {
unprojected.push(chat);
}
}
const pinnedFirst = (list: Channel[]) =>
[...list].sort(
(left, right) =>
Number(pinnedChatIds.has(right.id)) -
Number(pinnedChatIds.has(left.id)),
);
return {
groups: new Map(
[...groups.entries()].map(([projectId, group]) => [
projectId,
pinnedFirst(group),
]),
),
shared: pinnedFirst(shared),
unprojected: pinnedFirst(unprojected),
};
}, [chats, identityPubkey, metadataByChatId, pinnedChatIds, projects]);
const toggleProject = React.useCallback((projectId: string) => {
setCollapsedProjectIds((current) => {
const next = new Set(current);
if (next.has(projectId)) {
next.delete(projectId);
} else {
next.add(projectId);
}
return next;
});
}, []);
if (isLoading) {
return (
<div className="flex h-full min-h-0 flex-col">
<ChatListHeader />
<ChatListSkeleton />
</div>
);
}
return (
<div className="flex h-full min-h-0 flex-col">
<ChatListHeader />
<div className="buzz-sidebar-scrollbar min-h-0 flex-1 overflow-y-auto p-2 pt-3">
<div className="mb-3 space-y-1">
<ChatListSectionHeader
actionLabel="Add project"
label="Projects"
onAction={() => setIsCreateProjectOpen(true)}
/>
{projects.map((project) => {
const projectChats = chatsByProject.groups.get(project.id) ?? [];
const isCollapsed = collapsedProjectIds.has(project.id);
return (
<div key={project.id} className="mb-1">
<div className="group/project flex h-8 w-full min-w-0 items-center gap-1.5 rounded-md px-2 text-xs font-semibold text-muted-foreground transition-colors hover:bg-muted/60 hover:text-foreground">
<Notebook className="h-3.5 w-3.5 shrink-0" />
<button
className="flex min-w-0 flex-1 items-center gap-1.5 text-left"
onClick={() => toggleProject(project.id)}
type="button"
>
<span className="min-w-0 truncate">{project.name}</span>
{isCollapsed ? (
<ChevronRight className="h-3.5 w-3.5 shrink-0" />
) : (
<ChevronDown className="h-3.5 w-3.5 shrink-0" />
)}
</button>
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button
aria-label={`Project settings for ${project.name}`}
className="h-6 w-6 text-muted-foreground opacity-0 transition-opacity hover:text-foreground focus-visible:opacity-100 data-[state=open]:opacity-100 group-hover/project:opacity-100"
size="icon-xs"
type="button"
variant="ghost"
>
<MoreVertical className="h-3.5 w-3.5" />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end" className="w-44">
<DropdownMenuItem
onSelect={() => setEditingProject(project)}
>
Project settings
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
<Button
aria-label={`New chat in ${project.name}`}
className="h-6 w-6 text-muted-foreground opacity-0 transition-opacity hover:text-foreground focus-visible:opacity-100 group-hover/project:opacity-100"
onClick={() => onCreateProjectChat(project.id)}
size="icon-xs"
type="button"
variant="ghost"
>
<Plus className="h-3.5 w-3.5" />
</Button>
</div>
{!isCollapsed ? (
<div className="space-y-1">
{projectChats.length > 0 ? (
projectChats.map((chat) => (
<ChatListItem
chat={chat}
displayName={metadataByChatId.get(chat.id)?.title}
getChannelReadAt={getChannelReadAt}
isAgentRunning={activeChatIds.has(chat.id)}
isArchiving={archivingChatId === chat.id}
isPinned={pinnedChatIds.has(chat.id)}
key={chat.id}
onArchiveChat={onArchiveChat}
onRenameChat={onRenameChat}
onSelectChat={onSelectChat}
onTogglePin={onTogglePin}
selectedChatId={selectedChatId}
unreadChannelCounts={unreadChannelCounts}
unreadChannelIds={unreadChannelIds}
/>
))
) : (
<div className="px-3 py-1.5 text-xs text-muted-foreground">
No chats yet
</div>
)}
</div>
) : null}
</div>
);
})}
</div>
<div className="space-y-1">
<ChatListSectionHeader
actionLabel="New chat without a project"
label="Chats"
onAction={onCreateChat}
/>
{chatsByProject.unprojected.length > 0 ? (
chatsByProject.unprojected.map((chat) => (
<ChatListItem
chat={chat}
displayName={metadataByChatId.get(chat.id)?.title}
getChannelReadAt={getChannelReadAt}
isAgentRunning={activeChatIds.has(chat.id)}
isArchiving={archivingChatId === chat.id}
isPinned={pinnedChatIds.has(chat.id)}
key={chat.id}
onArchiveChat={onArchiveChat}
onRenameChat={onRenameChat}
onSelectChat={onSelectChat}
onTogglePin={onTogglePin}
selectedChatId={selectedChatId}
unreadChannelCounts={unreadChannelCounts}
unreadChannelIds={unreadChannelIds}
/>
))
) : (
<div className="px-3 py-1.5 text-xs text-muted-foreground">
No chats yet
</div>
)}
</div>
{chatsByProject.shared.length > 0 ? (
<div className="mt-4 space-y-1">
<ChatListSectionHeader label="Shared" />
{chatsByProject.shared.map((chat) => (
<ChatListItem
canRename={false}
chat={chat}
displayName={metadataByChatId.get(chat.id)?.title}
getChannelReadAt={getChannelReadAt}
isAgentRunning={activeChatIds.has(chat.id)}
isArchiving={archivingChatId === chat.id}
isPinned={pinnedChatIds.has(chat.id)}
key={chat.id}
onArchiveChat={onArchiveChat}
onRenameChat={onRenameChat}
onSelectChat={onSelectChat}
onTogglePin={onTogglePin}
selectedChatId={selectedChatId}
unreadChannelCounts={unreadChannelCounts}
unreadChannelIds={unreadChannelIds}
/>
))}
</div>
) : null}
</div>
<ChatProjectDialog
onOpenChange={setIsCreateProjectOpen}
onSaveProject={(project) => {
onUpdateProject(project);
setIsCreateProjectOpen(false);
}}
open={isCreateProjectOpen}
templates={templates}
/>
<ChatProjectDialog
mode="edit"
onOpenChange={(open) => {
if (!open) {
setEditingProject(null);
}
}}
onSaveProject={(project) => {
onUpdateProject(project);
setEditingProject(null);
}}
open={editingProject !== null}
project={editingProject}
templates={templates}
/>
</div>
);
}

View File

@@ -141,15 +141,23 @@ test("first message in a new chat is sent and rendered", async ({ page }) => {
)
.toBeGreaterThanOrEqual(-1);
// Agent-authored PR links render the prominent agent-work card variant
// twice: inline in the message and in the top-right work panel (which
// also shows the PR's source branch).
// Agent-authored PR links render the prominent agent-work card inline in
// the message; the top-right work panel shows the standard rich card plus
// the PR's source branch.
await expect(
page.locator("[data-link-preview='github-pull-request-agent']"),
).toHaveCount(2, { timeout: 10_000 });
await expect(page.getByTestId("chat-work-panel")).toBeVisible();
await expect(page.getByTestId("chat-work-panel")).toContainText(
"kennylopez-chatmode",
);
).toHaveCount(1, { timeout: 10_000 });
const workPanel = page.getByTestId("chat-work-panel");
await expect(workPanel).toBeVisible();
await expect(workPanel).toContainText("kennylopez-chatmode");
await expect(
workPanel.locator("[data-link-preview='github-pull-request']"),
).toBeVisible();
// The header's PR button toggles the panel.
await page.getByTestId("toggle-work-panel").click();
await expect(workPanel).not.toBeVisible();
await page.getByTestId("toggle-work-panel").click();
await expect(workPanel).toBeVisible();
await page.screenshot({ path: "test-results/agent-pr-card.png" });
});