diff --git a/DESIGN.md b/DESIGN.md index 66afaae09a0..265e8f2d96b 100644 --- a/DESIGN.md +++ b/DESIGN.md @@ -776,9 +776,11 @@ Recents appears only when it contains entries, without an empty state. Task entries require the viewer's own participation under the Mine inbox rule, regardless of inbox archive state. Automated provenance, account ownership and read-only visits do not establish participation. A qualifying task's title and -status stay current, but passive visits and background updates do not promote it -above newer user activity. A first passive visit places a qualifying candidate -below existing history. Readable subtasks remain contextual navigation under a +status stay current, but clicking or passively visiting an existing entry and +background updates do not promote it above newer user activity. A first passive +visit seeds an unseen qualifying entry from its latest activity timestamp (or +below existing history when unavailable) so newer items sort near the top +without re-sorting on click. Readable subtasks remain contextual navigation under a qualifying parent. ### Reuse collection behavior as well as appearance diff --git a/doc/PRODUCT.md b/doc/PRODUCT.md index 4b95c53eeb3..48e19b2cd95 100644 --- a/doc/PRODUCT.md +++ b/doc/PRODUCT.md @@ -120,13 +120,14 @@ The Tasks tab keeps the full relationship list and shows each task once. Project groups omit tasks already shown in the other sections and disappear when empty. Sidebar Recents and Classic Recent Tasks show tasks from the viewer’s own -recent activity as a flat list. A subtask has its own row and its own unread -marker. Tasks archived from the viewer’s inbox leave Recents. Canceled and -completed tasks remain eligible. Opening a recent task moves its row to the top -of Recents. Any task a person opens is eligible for their Recents, including -routine, channel, and agent-created tasks. When a person runs a routine manually, -the task that run creates goes to the top of their Recents at once, before they -open it. Neither of these adds the task to Mine. +recent activity as a flat list ordered by most recent activity. A subtask has +its own row and its own unread marker. Tasks archived from the viewer’s inbox +leave Recents. Canceled and completed tasks remain eligible. Clicking or opening +an existing item in Recents does not move it to the top; items re-sort only +when new activity occurs. Any task a person opens is eligible for their Recents, +including routine, channel, and agent-created tasks. When a person runs a +routine manually, the task that run creates goes to the top of their Recents at +once, before they open it. Neither of these adds the task to Mine. Standard Recents also shows recent chats and projects. The Coordinator sidebar pins **Plugins** above **More** by default. Users can diff --git a/ui/src/components/CoordinatorSidebar.tsx b/ui/src/components/CoordinatorSidebar.tsx index 0b7952b2532..249f2b0458c 100644 --- a/ui/src/components/CoordinatorSidebar.tsx +++ b/ui/src/components/CoordinatorSidebar.tsx @@ -1,7 +1,7 @@ import { useEffect, useLayoutEffect, useMemo, useRef, useState, type ReactNode } from "react"; import { useQuery } from "@tanstack/react-query"; import { Inbox, Boxes, CircleCheck, Compass, Folder, History, LayoutDashboard, MessageCircle, MoreHorizontal, Network, Plus, Repeat, Search, Settings, SquarePen, Unplug, type LucideIcon } from "lucide-react"; -import type { Agent, IssueSummary, Project } from "@paperclipai/shared"; +import type { Agent, Issue, IssueSummary, Project } from "@paperclipai/shared"; import { useCoordinatorAttentionCount } from "@/hooks/useCoordinatorAttentionCount"; import { instanceSettingsApi } from "@/api/instanceSettings"; import { useAgentChatNavigation } from "@/hooks/useAgentChatNavigation"; @@ -12,6 +12,11 @@ import { projectPinKey, usePinnedNavigation } from "@/hooks/usePinnedNavigation" import { useDialogActions } from "@/context/DialogContext"; import { useSidebar } from "@/context/SidebarContext"; import { queryKeys } from "@/lib/queryKeys"; +import { + buildCoordinatorRecents, + recordProjectRecentVisit, + type CoordinatorProjectVisits, +} from "@/lib/coordinator-recents"; import type { RecentTaskEntry } from "@/lib/recent-tasks"; import { Link, useLocation } from "@/lib/router"; import { agentRouteRef, projectRouteRef } from "@/lib/utils"; @@ -33,6 +38,9 @@ import { companyProjectsQuery } from "@/lib/company-projects-query"; import { NavigationPinButton, type PinControls } from "./NavigationPinButton"; import { SidebarProjectTasks } from "./SidebarProjectTasks"; +const NO_AGENTS: readonly Agent[] = []; +const NO_CHATS: readonly Issue[] = []; +const NO_PROJECTS: readonly Project[] = []; const NO_RECENT_TASKS: never[] = []; const TASK_PIN_ID_PATTERN = /^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/i; const taskPinKey = (companyId: string, id: string) => `task:${companyId}:${id}`; @@ -156,29 +164,29 @@ export function CoordinatorSidebar({ children }: { children?: ReactNode }) { const { openNewIssue } = useDialogActions(); const attentionCount = useCoordinatorAttentionCount(companyId); const { data: projects } = useQuery({ ...companyProjectsQuery(companyId!), enabled: !!companyId }); - const orderedPins = useMemo(() => buildPinnedNavigationItems(pinnedNavigation.pins, agents.data ?? [], destinations, - pinnedTasks, session.isSuccess ? projects : undefined), [pinnedNavigation.pins, agents.data, destinations, pinnedTasks, projects, session.isSuccess]); - // Only project IDs and visit times are kept in memory. Labels and task lists + const agentList = agents.data ?? NO_AGENTS; + const chatList = chats.data ?? NO_CHATS; + const projectList = projects ?? NO_PROJECTS; + const orderedPins = useMemo(() => buildPinnedNavigationItems(pinnedNavigation.pins, agentList, destinations, + pinnedTasks, session.isSuccess ? projectList : undefined), [pinnedNavigation.pins, agentList, destinations, pinnedTasks, projectList, session.isSuccess]); + // Only project IDs and activity timestamps are kept in memory. Labels and task lists // always come from the authorized API, scoped to the current person/company. const scope = `${companyId}:${userId}`; - const [projectVisits, setProjectVisits] = useState<{ scope: string; entries: Record }>({ scope, entries: {} }); + const [projectVisits, setProjectVisits] = useState({ scope, entries: {} }); useEffect(() => { const ref = location.pathname.match(/\/projects\/([^/]+)/)?.[1]; - const project = projects?.find(item => item.id === ref || projectRouteRef(item) === ref); + const project = projectList.find(item => item.id === ref || projectRouteRef(item) === ref); if (!project) return; - setProjectVisits(previous => ({ scope, entries: { ...(previous.scope === scope ? previous.entries : {}), [project.id]: Date.now() } })); - }, [location.pathname, projects, scope]); - const recents = useMemo(() => { - const roster = new Map((agents.data ?? []).map(agent => [agent.id, agent])); - const taskRows = recentTasks.map(task => ({ kind: "task" as const, id: task.id, time: task.recordedAt, task })); - const chatRows = (chats.data ?? []).flatMap(chat => { - const agent = chat.conversationAgentId ? roster.get(chat.conversationAgentId) : null; - return agent ? [{ kind: "chat" as const, id: chat.id, time: new Date(chat.updatedAt).getTime(), agent }] : []; - }); - const projectRows = (projects ?? []).flatMap(project => projectVisits.scope === scope && projectVisits.entries[project.id] - ? [{ kind: "project" as const, id: project.id, time: projectVisits.entries[project.id]!, project }] : []); - return [...taskRows, ...chatRows, ...projectRows].sort((a, b) => b.time - a.time); - }, [agents.data, chats.data, recentTasks, projects, projectVisits, scope]); + setProjectVisits(previous => recordProjectRecentVisit(previous, scope, project)); + }, [location.pathname, projectList, scope]); + const recents = useMemo(() => buildCoordinatorRecents({ + agents: agentList, + chats: chatList, + recentTasks, + projects: projectList, + projectVisits, + scope, + }), [agentList, chatList, recentTasks, projectList, projectVisits, scope]); const newTaskButton =