diff --git a/apps/web-ui/packages/client/ui-shortcuts/src/client/Reference.tsx b/apps/web-ui/packages/client/ui-shortcuts/src/client/Reference.tsx index 8d4079b596..91ca69325d 100644 --- a/apps/web-ui/packages/client/ui-shortcuts/src/client/Reference.tsx +++ b/apps/web-ui/packages/client/ui-shortcuts/src/client/Reference.tsx @@ -48,6 +48,7 @@ const coreActionOrder = new Map( "session.new", "sidebar.left.toggle", "session.search", + "session.activityView", "workspace.add", "session.rename", "session.fork", diff --git a/apps/web-ui/packages/client/ui-workspace/src/client/activity-view.ts b/apps/web-ui/packages/client/ui-workspace/src/client/activity-view.ts new file mode 100644 index 0000000000..5611d93135 --- /dev/null +++ b/apps/web-ui/packages/client/ui-workspace/src/client/activity-view.ts @@ -0,0 +1,144 @@ +/** + * Pure filtering, prioritization, and unread-ID collection for the sidebar Activity View. + * Reuses the sidebar display-tree derivation so child-thread activity rolls up consistently. + */ +import type { SessionListState } from "@deepseek-ai/dsh-api-session-controller/client"; +import type { SessionId } from "@deepseek-ai/dsh-session/types"; +import { + deriveThreadForest, + type SessionNode, + type SessionRowState, + type SessionStatuses, +} from "./tree.ts"; + +/** Activity priority bucket: lower number renders higher in the Activity View. */ +export type ActivityPriority = 0 | 1 | 2; + +/** Derived Activity View projection and attention counts within the active scope. */ +export interface ActivityViewProjection { + /** Active root sessions ordered by priority (pending > running > unread) and recency. */ + readonly rows: readonly SessionNode[]; + /** All unread completed session IDs in scope, including visible thread-tree descendants. */ + readonly unreadSessionIds: readonly SessionId[]; + /** Total sessions (including descendants) with a pending user interaction. */ + readonly pendingCount: number; + /** Total sessions (including descendants) running or hosting running subagents. */ + readonly runningCount: number; + /** Total sessions (including descendants) with an unread completion reminder. */ + readonly unreadCount: number; + /** True when at least one session in scope needs interaction or has an unread completion. */ + readonly hasAttention: boolean; +} + +/** Whether a single session row has a pending user interaction. */ +function hasOwnPending(node: SessionNode): boolean { + return node.pendingInteraction !== undefined; +} + +/** Whether a single session row is running or has active native subagents. */ +function hasOwnRunning(node: SessionNode): boolean { + return node.running || node.runningSubagentCount > 0; +} + +/** Whether a single session row has an unread completion reminder. */ +function hasOwnUnread(node: SessionNode): boolean { + return node.completed; +} + +/** + * Determine the highest activity priority for a root session node (including its descendants). + * Returns `null` when neither the node nor any visible descendant has active work or unread state. + */ +export function activityPriorityOf(node: SessionNode): ActivityPriority | null { + if (node.archived || node.blank) return null; + if (hasOwnPending(node) || (node.tree?.activity.pendingInteraction ?? 0) > 0) return 0; + if (hasOwnRunning(node) || (node.tree?.activity.running ?? 0) > 0) return 1; + if (hasOwnUnread(node) || (node.tree?.activity.completed ?? 0) > 0) return 2; + return null; +} + +/** + * Collect all unread completed session IDs from a set of display-tree roots and their descendants. + * Excludes archived sessions and deduplicates IDs while preserving traversal order. + */ +export function collectUnreadSessionIds(roots: readonly SessionNode[]): SessionId[] { + const seen = new Set(); + const result: SessionId[] = []; + const visit = (node: SessionNode): void => { + if (!node.archived && !node.blank && hasOwnUnread(node) && !seen.has(node.id)) { + seen.add(node.id); + result.push(node.id); + } + for (const child of node.tree?.children ?? []) { + visit(child); + } + }; + for (const root of roots) { + visit(root); + } + return result; +} + +/** + * Derive the sorted Activity View rows and attention counters for the current session scope. + * Archived sessions and blank drafts are always excluded, regardless of the main list's archive filter. + */ +export function deriveActivityView( + list: SessionListState, + rowState: SessionRowState, + statuses: SessionStatuses, +): ActivityViewProjection { + const activeRowState: SessionRowState = { + pinnedSessionIds: rowState.pinnedSessionIds, + archivedSessionIds: rowState.archivedSessionIds, + archivedFilter: "default", + ...(rowState.sectionedSessionIds === undefined + ? {} + : { sectionedSessionIds: rowState.sectionedSessionIds }), + }; + const forest = deriveThreadForest(list, activeRowState, statuses); + + const candidates: { + readonly node: SessionNode; + readonly priority: ActivityPriority; + readonly updatedAt: number; + readonly index: number; + }[] = []; + + let pendingCount = 0; + let runningCount = 0; + + for (let index = 0; index < forest.length; index++) { + const node = forest[index] as SessionNode; + const priority = activityPriorityOf(node); + if (priority === null) continue; + pendingCount += Number(hasOwnPending(node)) + (node.tree?.activity.pendingInteraction ?? 0); + runningCount += Number(hasOwnRunning(node)) + (node.tree?.activity.running ?? 0); + candidates.push({ + node, + priority, + updatedAt: node.tree?.updatedAt ?? node.updatedAt, + index, + }); + } + + candidates.sort( + (left, right) => + left.priority - right.priority || + right.updatedAt - left.updatedAt || + left.index - right.index, + ); + + const rows = candidates.map((entry) => entry.node); + const unreadSessionIds = collectUnreadSessionIds(rows); + const unreadCount = unreadSessionIds.length; + + return { + rows, + unreadSessionIds, + pendingCount, + runningCount, + unreadCount, + hasAttention: pendingCount > 0 || unreadCount > 0, + }; +} diff --git a/apps/web-ui/packages/client/ui-workspace/src/client/locales.ts b/apps/web-ui/packages/client/ui-workspace/src/client/locales.ts index fc09c3998a..84569b1c7a 100644 --- a/apps/web-ui/packages/client/ui-workspace/src/client/locales.ts +++ b/apps/web-ui/packages/client/ui-workspace/src/client/locales.ts @@ -103,6 +103,12 @@ export const zh = { "empty.noMatches": "无匹配结果", "workspace.add": "添加工作区", "search.sessions.aria": "搜索会话", + "activityView.label": "活动视图", + "activityView.unreadCount.one": "· {n} 条未读", + "activityView.unreadCount.other": "· {n} 条未读", + "activityView.markAllRead": "全部已读", + "activityView.empty": "暂无未读或进行中的会话", + "activityView.backToAll": "返回全部会话", "search.placeholder": "搜索会话名称", "search.clear": "清除搜索", "search.results.aria": "搜索结果", @@ -341,6 +347,12 @@ export const en = { "empty.noMatches": "No matches", "workspace.add": "Add workspace", "search.sessions.aria": "Search sessions", + "activityView.label": "Activity view", + "activityView.unreadCount.one": "· {n} unread", + "activityView.unreadCount.other": "· {n} unread", + "activityView.markAllRead": "Mark all read", + "activityView.empty": "No unread or active conversations", + "activityView.backToAll": "Back to all sessions", "search.placeholder": "Search session names", "search.clear": "Clear search", "search.results.aria": "Search results", diff --git a/apps/web-ui/packages/client/ui-workspace/src/client/rows/ActivityViewList.module.css b/apps/web-ui/packages/client/ui-workspace/src/client/rows/ActivityViewList.module.css new file mode 100644 index 0000000000..dbbfec5258 --- /dev/null +++ b/apps/web-ui/packages/client/ui-workspace/src/client/rows/ActivityViewList.module.css @@ -0,0 +1,142 @@ +.toolbar { + flex: none; + display: flex; + align-items: center; + justify-content: space-between; + gap: 8px; + min-height: 30px; + margin: 0 calc(var(--dsh-session-list-edge-inset) - 4px) 6px 0; + padding: 2px 6px 6px 8px; + border-bottom: 1px solid color-mix(in srgb, var(--dsw-alias-border-l3) 34%, transparent); +} + +.titleGroup { + flex: 1; + min-width: 0; + display: inline-flex; + align-items: center; + gap: 5px; + font-size: 12px; + line-height: 17px; + white-space: nowrap; + overflow: hidden; +} + +.title { + flex: none; + font-weight: 500; + color: var(--dsw-alias-label-secondary); +} + +.unreadMeta { + min-width: 0; + overflow: hidden; + text-overflow: ellipsis; + font-variant-numeric: tabular-nums; + color: var(--dsw-alias-label-tertiary); +} + +.markAllReadButton { + flex: none; + display: inline-flex; + align-items: center; + justify-content: center; + height: 24px; + padding: 0 8px; + border: none; + border-radius: 6px; + background: transparent; + font: inherit; + font-size: 12px; + font-weight: 500; + line-height: 16px; + color: var(--dsw-alias-state-business-primary); + cursor: pointer; + white-space: nowrap; + transition: + background-color 120ms ease, + color 120ms ease, + opacity 120ms ease; +} + +.markAllReadButton:hover:not(:disabled) { + background: color-mix(in srgb, var(--dsw-alias-state-business-primary) 10%, transparent); +} + +.markAllReadButton:active:not(:disabled) { + background: color-mix(in srgb, var(--dsw-alias-state-business-primary) 16%, transparent); +} + +.markAllReadButton:disabled { + color: var(--dsw-alias-label-tertiary); + opacity: 0.45; + cursor: default; +} + +.markAllReadButton:focus-visible, +.backButton:focus-visible { + outline: var(--dsw-focus-ring-width, 2px) solid + var(--dsw-focus-ring-color, var(--dsw-alias-state-business-primary)); + outline-offset: -2px; +} + +.emptyState { + display: flex; + flex-direction: column; + align-items: center; + gap: 8px; + margin-top: 72px; + padding: 0 16px; + text-align: center; + color: var(--dsw-alias-label-tertiary); + font-size: 13px; + line-height: 20px; +} + +.emptyIcon { + margin-bottom: 4px; + color: var(--dsw-alias-label-caption); + opacity: 0.85; +} + +.emptyTitle { + color: var(--dsw-alias-label-tertiary); +} + +.backButton { + margin-top: 2px; + padding: 4px 10px; + border: none; + border-radius: 6px; + background: transparent; + cursor: pointer; + font: inherit; + font-size: 13px; + font-weight: 500; + line-height: 20px; + color: var(--dsw-alias-link); + transition: background-color 120ms ease; +} + +.backButton:hover { + background: var(--dsw-alias-interactive-bg-hover); +} + +@media (hover: none), (pointer: coarse) { + .markAllReadButton { + min-height: 32px; + padding: 0 10px; + } + + .backButton { + min-height: 36px; + padding: 6px 12px; + } +} + +@media (prefers-reduced-motion: reduce) { + .markAllReadButton, + .backButton { + transition: none; + } +} diff --git a/apps/web-ui/packages/client/ui-workspace/src/client/rows/ActivityViewList.tsx b/apps/web-ui/packages/client/ui-workspace/src/client/rows/ActivityViewList.tsx new file mode 100644 index 0000000000..5dd8a23cd6 --- /dev/null +++ b/apps/web-ui/packages/client/ui-workspace/src/client/rows/ActivityViewList.tsx @@ -0,0 +1,148 @@ +/** + * Sidebar Activity View list: renders pending, running, and unread-completed + * sessions with a compact header bar for one-click "Mark all read". + */ +import clsx from "clsx"; +import type { PropsRenderSlots } from "@deepseek-ai/dsh-client-ui-slots"; +import type { SessionId } from "@deepseek-ai/dsh-session/types"; +import type { WorkspaceBrowserProps } from "../contract/slots.ts"; +import type { ActivityViewProjection } from "../activity-view.ts"; +import type { SessionNode } from "../tree.ts"; +import { AnimatedRows } from "./AnimatedRows.tsx"; +import { SessionNodeItem } from "./Rows.tsx"; +import { ThreadTreeRows } from "./ThreadTreeControls.tsx"; +import { useThreadTreeView } from "./ThreadTreeView.tsx"; +import browserCss from "./WorkspaceBrowser.module.css"; +import css from "./ActivityViewList.module.css"; + +/** Minimal 3-bar descending filter icon aligned with 16x16 regular sidebar glyphs. */ +export function ActivityFilterIcon({ + size = 16, + className, +}: { + size?: number; + className?: string; +}) { + return ( + + ); +} + +export interface ActivityViewListProps extends PropsRenderSlots< + | "sidebar.workspaces.session.menu.item" + | "sidebar.workspaces.session.row.action" + | "sidebar.session.row.identity" + | "sidebar.session.row.leading" + | "sidebar.session.row.hover" +> { + projection: ActivityViewProjection; + currentId: SessionId | undefined; + ready: boolean; + animationResetKey: string; + singleRemoteHostScoped?: boolean; + onOpen: (id: SessionNode["id"]) => void; + onSessionRenameRequest: (id: SessionNode["id"], currentTitle: string) => void; + onMarkAllRead: (sessionIds: readonly SessionId[]) => void; + onExit: () => void; + t: WorkspaceBrowserProps["t"]; +} + +export function ActivityViewList({ + projection, + currentId, + ready, + animationResetKey, + singleRemoteHostScoped = false, + onOpen, + onSessionRenameRequest, + onMarkAllRead, + onExit, + renderSlot, + t, +}: ActivityViewListProps) { + const threadView = useThreadTreeView(); + const { rows, unreadSessionIds, unreadCount } = projection; + const now = Date.now(); + const rowKeys = + rows.length === 0 + ? ["empty:activity"] + : threadView.rows(rows).map((row) => `session:${row.id}`); + + return ( +
+
+
+ {t("activityView.label")} + {unreadCount > 0 && ( + + {t( + unreadCount === 1 + ? "activityView.unreadCount.one" + : "activityView.unreadCount.other", + { n: unreadCount }, + )} + + )} +
+ +
+ + {rows.length === 0 ? ( +
+ +
{t("activityView.empty")}
+ +
+ ) : ( + + {(node) => ( + + )} + + )} +
+ +
+ ); +} diff --git a/apps/web-ui/packages/client/ui-workspace/src/client/rows/WorkspaceBrowser.module.css b/apps/web-ui/packages/client/ui-workspace/src/client/rows/WorkspaceBrowser.module.css index 7d7806f283..68e8f327df 100644 --- a/apps/web-ui/packages/client/ui-workspace/src/client/rows/WorkspaceBrowser.module.css +++ b/apps/web-ui/packages/client/ui-workspace/src/client/rows/WorkspaceBrowser.module.css @@ -57,6 +57,45 @@ color: var(--dsw-alias-label-primary); } +.activityButton { + position: relative; +} + +.activityButtonActive { + background: color-mix(in srgb, var(--dsw-alias-state-business-primary) 12%, transparent); + color: var(--dsw-alias-state-business-primary); +} + +.activityButtonActive:hover { + background: color-mix(in srgb, var(--dsw-alias-state-business-primary) 18%, transparent); + color: var(--dsw-alias-state-business-primary); +} + +.activityIconWrap { + position: relative; + display: inline-flex; + align-items: center; + justify-content: center; + width: 16px; + height: 16px; +} + +.activityDot { + position: absolute; + top: -2px; + right: -2px; + width: 5.5px; + height: 5.5px; + border-radius: 50%; + background: var(--dsw-alias-state-business-primary); + box-shadow: 0 0 0 1.5px var(--dsw-specific-sidebar-fill); + pointer-events: none; +} + +.activityDot[data-attention="pending"] { + background: var(--dsw-alias-state-warn-primary); +} + /* View-options dropdown card: labels are short, so a content-sized card reads cramped and its width shifts with the locale — hold a stable floor. */ .viewOptionsMenu { @@ -114,13 +153,39 @@ transition-delay: 0s, 0s, 0s, 0s, 180ms; } +.activitySlot { + flex: none; + display: flex; + align-items: center; + margin-left: auto; + max-width: 28px; + opacity: 1; + visibility: visible; + transition: + max-width 180ms var(--ds-ease-in-out), + margin-right 180ms var(--ds-ease-in-out), + opacity 120ms var(--ds-ease-in-out), + transform 180ms var(--ds-ease-in-out), + visibility 0s linear; +} + +.activitySlotHidden { + max-width: 0; + margin-left: 0; + margin-right: -4px; + opacity: 0; + transform: translateX(-4px); + visibility: hidden; + pointer-events: none; + transition-delay: 0s, 0s, 0s, 0s, 180ms; +} + .searchSlot { flex: 1; max-width: 28px; min-width: 0; display: flex; align-items: center; - margin-left: auto; padding-left: 0; box-sizing: border-box; transition: @@ -743,6 +808,7 @@ .search, .sectionLabel, + .activitySlot, .searchSlot, .searchInput, .headerActions { diff --git a/apps/web-ui/packages/client/ui-workspace/src/client/rows/WorkspaceBrowser.tsx b/apps/web-ui/packages/client/ui-workspace/src/client/rows/WorkspaceBrowser.tsx index 5f236ab038..d119089a46 100644 --- a/apps/web-ui/packages/client/ui-workspace/src/client/rows/WorkspaceBrowser.tsx +++ b/apps/web-ui/packages/client/ui-workspace/src/client/rows/WorkspaceBrowser.tsx @@ -88,7 +88,9 @@ import { UNGROUPED_KEY, } from "../tree.ts"; import { pinOrderSource } from "../pin-order.ts"; +import { deriveActivityView } from "../activity-view.ts"; import { threadTreeOrderSource, workspaceTreeMembers } from "../thread-tree-order.ts"; +import { ActivityFilterIcon, ActivityViewList } from "./ActivityViewList.tsx"; import { ThreadTreeViewProvider, useThreadTreeView } from "./ThreadTreeView.tsx"; import { ProjectRowItem, SearchResultItem, SessionNodeItem } from "./Rows.tsx"; import { ThreadTreeRows } from "./ThreadTreeControls.tsx"; @@ -1724,6 +1726,7 @@ function WorkspaceBrowserContent({ actions, startSession, open, + markCompletionsRead, requestSessionRename, notifyArchivedNotOpenable, renameWorkspace, @@ -1752,8 +1755,11 @@ function WorkspaceBrowserContent({ const home = useHostInfo((info) => info.home); const shortcuts = useShortcuts((rows) => rows); const searchShortcut = shortcuts.find((row) => row.id === "session.search"); + const activityShortcut = shortcuts.find((row) => row.id === "session.activityView"); const addShortcut = shortcuts.find((row) => row.id === "workspace.add"); const shortcutState = useWorkspaceShortcuts((state) => state); + const panelActive = usePanelInfo((info) => info.activePanelId !== null); + const statuses = useSessionStatus((s) => s); // Ordering remains live while the rail or search replaces the list body. const list = useSessions((state) => state); const storedWorkspaces = useWorkspaces((state) => state.items); @@ -1983,6 +1989,7 @@ function WorkspaceBrowserContent({ // does not silently drop an in-progress filter. const [query, setQuery] = useState(""); const [searchExpanded, setSearchExpanded] = useState(false); + const [activityViewOpen, setActivityViewOpen] = useState(false); const [revealSessionId, setRevealSessionId] = useState(undefined); const normalizedQuery = sanitizeSearchQuery(query).trim(); const [remoteSearch, setRemoteSearch] = useState({ @@ -2160,6 +2167,18 @@ function WorkspaceBrowserContent({ () => (hostScopeFiltered ? JSON.stringify(effectiveHostScopeFilter) : "all"), [hostScopeFiltered, effectiveHostScopeFilter], ); + const activityProjection = useMemo( + () => deriveActivityView(scopedList, rowState, statuses), + [scopedList, rowState, statuses], + ); + const activityCurrentId = panelActive ? undefined : mainSessionId; + const markAllActivityRead = useCallback( + (sessionIds: readonly SessionId[]): void => { + if (sessionIds.length === 0) return; + (markCompletionsRead ?? threadView.markCompletionsRead)(sessionIds); + }, + [markCompletionsRead, threadView.markCompletionsRead], + ); const openAddRemoteWorkspace = (): void => { const selectedRemoteHostId = effectiveHostScopeFilter.selectedHost !== "all" && @@ -2199,6 +2218,7 @@ function WorkspaceBrowserContent({ ? undefined : nativeSections.find(({ workspaceIds }) => workspaceIds?.includes(workspaceId) === true)); if (section) actions.setSectionExpanded(`native-section:${section.id}`, true); + setActivityViewOpen(false); setRevealSessionId(sessionId); setQuery(""); setSearchExpanded(false); @@ -2235,6 +2255,26 @@ function WorkspaceBrowserContent({ expandSidebar(); } else searchInput.current?.focus({ preventScroll: true }); }, [shortcutState.searchRequest]); + const activityShortcutContextRef = useRef({ wide, searchActive: false }); + activityShortcutContextRef.current = { wide, searchActive: searchExpanded || query !== "" }; + useEffect(() => { + if (shortcutState.activityViewRequest === 0) return; + closeAddWorkspace(); + const { wide: isWide, searchActive } = activityShortcutContextRef.current; + if (searchActive) { + setQuery(""); + setSearchExpanded(false); + setActivityViewOpen(true); + if (!isWide) expandSidebar(); + return; + } + if (!isWide) { + expandSidebar(); + setActivityViewOpen(true); + return; + } + setActivityViewOpen((prev) => !prev); + }, [shortcutState.activityViewRequest]); useEffect(() => { if (!wide || !searchExpanded || searchOnExpand) return; @@ -2406,6 +2446,44 @@ function WorkspaceBrowserContent({ {t("section.sessions")} )} + {wide && ( +
+ + + +
+ )} {wide && (
{ actions.setOrderBy(mode, activeSessionOrders, orderSource); }} - onArchivedFilterPick={actions.setArchivedFilter} + onArchivedFilterPick={(filter) => { + if (filter === "only") setActivityViewOpen(false); + actions.setArchivedFilter(filter); + }} t={t} /> )} @@ -2658,6 +2739,22 @@ function WorkspaceBrowserContent({ resultLimit={searchResultLimit} t={t} /> + ) : activityViewOpen ? ( + { + setActivityViewOpen(false); + }} + renderSlot={renderSlot} + t={t} + /> ) : groupBy === "flat" ? ( ; search: () => void; + toggleActivityView: () => void; add: () => void; closeAdd: () => void; directoryBusy: (busy: boolean) => void; @@ -35,6 +37,7 @@ interface WorkspaceShortcutControls { export function createWorkspaceShortcutControls(): WorkspaceShortcutControls { const state = createSnapshotStore({ searchRequest: 0, + activityViewRequest: 0, addRequested: false, directoryBusy: false, renameTarget: null, @@ -46,6 +49,10 @@ export function createWorkspaceShortcutControls(): WorkspaceShortcutControls { search: () => { state.set({ ...state.getSnapshot(), searchRequest: state.getSnapshot().searchRequest + 1 }); }, + toggleActivityView: () => { + const current = state.getSnapshot(); + state.set({ ...current, activityViewRequest: current.activityViewRequest + 1 }); + }, add: () => { state.set( state.getSnapshot().directoryBusy @@ -152,6 +159,15 @@ export function installWorkspaceShortcuts( ["primary", "alt"], () => ({ status: "handled", run: controls.search }), ); + register( + "session.activityView", + () => t("activityView.label"), + ["activity view", "unread sessions"], + "KeyU", + ["primary", "alt"], + ["primary", "alt"], + () => ({ status: "handled", run: controls.toggleActivityView }), + ); register( "workspace.add", () => t("workspace.add"), diff --git a/apps/web-ui/packages/client/ui-workspace/test/activity-view.test.ts b/apps/web-ui/packages/client/ui-workspace/test/activity-view.test.ts new file mode 100644 index 0000000000..094600bdef --- /dev/null +++ b/apps/web-ui/packages/client/ui-workspace/test/activity-view.test.ts @@ -0,0 +1,332 @@ +import { describe, expect, it } from "vitest"; +import type { + SessionListState, + SessionSummary, +} from "@deepseek-ai/dsh-api-session-controller/client"; +import type { WorkspaceId, WorkspaceView } from "@deepseek-ai/dsh-api-workspace-controller/client"; +import type { SessionStatus } from "@deepseek-ai/dsh-client-ui-session/client"; +import { SessionId } from "@deepseek-ai/dsh-session/types"; +import { + activityPriorityOf, + collectUnreadSessionIds, + deriveActivityView, +} from "../src/client/activity-view.ts"; +import { + filterSessionsByHostScope, + type HostScopeFilterState, +} from "../src/client/rows/host-scope-filter.ts"; +import type { SessionRowState, SessionStatuses } from "../src/client/tree.ts"; + +function makeSession( + key: string, + options: { + updatedAt?: number; + running?: boolean; + blank?: boolean; + origin?: SessionSummary["origin"]; + parent?: string | null; + remote?: { hostId: string; displayName: string; state: string; color?: string }; + } = {}, +): SessionSummary { + return { + id: SessionId(key), + title: key, + displayTitle: key, + running: options.running ?? false, + blank: options.blank ?? false, + ...(options.origin === undefined ? {} : { origin: options.origin }), + retainedBy: {}, + updatedAt: options.updatedAt ?? 100, + projectionValues: { + threadTreeParent: options.parent ?? null, + threadReference: { hostId: options.remote?.hostId ?? "local" }, + ...(options.remote === undefined ? {} : { remoteHost: options.remote }), + }, + }; +} + +function makeList( + rows: readonly SessionSummary[], + subagents: Readonly> = {}, +): SessionListState { + const byId: Record = Object.fromEntries(rows.map((row) => [row.id, row])); + for (const children of Object.values(subagents)) { + for (const child of children) { + if (byId[child.id] === undefined) { + byId[child.id] = makeSession(child.id, { + running: child.running ?? false, + origin: "subagent", + }); + } + } + } + const projectionsBySession = Object.fromEntries( + Object.entries(subagents).map(([parentId, children]) => [ + parentId, + { + values: { + subagentCatalog: children.map((child) => ({ + id: child.id, + title: child.id, + })), + }, + }, + ]), + ) as SessionListState["projectionsBySession"]; + + return { + ids: rows.map((row) => row.id), + byId, + phase: "ready", + projectionsBySession, + }; +} + +function makeStatuses( + entries: Readonly< + Record< + string, + { + running?: boolean; + completionUnread?: boolean; + pendingKind?: "approval" | "plan-review" | "question"; + } + > + >, +): SessionStatuses { + const map = new Map(); + for (const [key, entry] of Object.entries(entries)) { + const id = SessionId(key); + map.set(id, { + running: entry.running ?? false, + completionUnread: entry.completionUnread ?? false, + pendingInteraction: + entry.pendingKind === undefined + ? undefined + : ({ kind: entry.pendingKind } as SessionStatus["pendingInteraction"]), + } as SessionStatus); + } + return map; +} + +const defaultRowState: SessionRowState = { + pinnedSessionIds: [], + archivedSessionIds: [], + archivedFilter: "default", +}; + +describe("deriveActivityView", () => { + it("filters to pending, running (including subagents), and unread sessions while excluding idle, blank, subagent, and archived rows", () => { + const list = makeList( + [ + makeSession("idle", { updatedAt: 500 }), + makeSession("blank-draft", { blank: true, updatedAt: 600 }), + makeSession("subagent-row", { origin: "subagent", running: true, updatedAt: 700 }), + makeSession("archived-unread", { updatedAt: 800 }), + makeSession("archived-running", { running: true, updatedAt: 900 }), + makeSession("approval-row", { updatedAt: 100 }), + makeSession("plan-row", { updatedAt: 200 }), + makeSession("question-row", { updatedAt: 150 }), + makeSession("running-row", { running: true, updatedAt: 250 }), + makeSession("subagent-host", { updatedAt: 300 }), + makeSession("unread-old", { updatedAt: 120 }), + makeSession("unread-new", { updatedAt: 400 }), + ], + { + "subagent-host": [{ id: SessionId("child-agent"), running: true }], + }, + ); + const statuses = makeStatuses({ + "archived-unread": { completionUnread: true }, + "archived-running": { running: true }, + "approval-row": { pendingKind: "approval" }, + "plan-row": { pendingKind: "plan-review" }, + "question-row": { pendingKind: "question" }, + "running-row": { running: true }, + "unread-old": { completionUnread: true }, + "unread-new": { completionUnread: true }, + }); + + // Even when the main sidebar shows archived rows or archived-only, Activity View excludes archived sessions. + for (const archivedFilter of ["default", "show", "only"] as const) { + const projection = deriveActivityView( + list, + { + ...defaultRowState, + archivedSessionIds: [SessionId("archived-unread"), SessionId("archived-running")], + archivedFilter, + }, + statuses, + ); + + expect(projection.rows.map((row) => row.id)).toEqual([ + SessionId("plan-row"), + SessionId("question-row"), + SessionId("approval-row"), + SessionId("subagent-host"), + SessionId("running-row"), + SessionId("unread-new"), + SessionId("unread-old"), + ]); + expect(projection.unreadSessionIds).toEqual([ + SessionId("unread-new"), + SessionId("unread-old"), + ]); + expect(projection.pendingCount).toBe(3); + expect(projection.runningCount).toBe(2); + expect(projection.unreadCount).toBe(2); + expect(projection.hasAttention).toBe(true); + } + }); + + it("keeps stable ordering for ties within the same priority bucket", () => { + const list = makeList([ + makeSession("unread-first", { updatedAt: 500 }), + makeSession("unread-second", { updatedAt: 500 }), + makeSession("unread-third", { updatedAt: 500 }), + ]); + const statuses = makeStatuses({ + "unread-first": { completionUnread: true }, + "unread-second": { completionUnread: true }, + "unread-third": { completionUnread: true }, + }); + + const projection = deriveActivityView(list, defaultRowState, statuses); + expect(projection.rows.map((row) => row.id)).toEqual([ + SessionId("unread-first"), + SessionId("unread-second"), + SessionId("unread-third"), + ]); + }); + + it("surfaces idle parents with active descendants and collects all unread IDs across the subtree", () => { + const list = makeList([ + makeSession("parent-with-unread-grandchild", { updatedAt: 100 }), + makeSession("mid-idle", { parent: "parent-with-unread-grandchild", updatedAt: 150 }), + makeSession("grandchild-unread", { parent: "mid-idle", updatedAt: 600 }), + makeSession("parent-with-pending-child", { updatedAt: 200 }), + makeSession("child-pending", { parent: "parent-with-pending-child", updatedAt: 210 }), + makeSession("child-unread", { parent: "parent-with-pending-child", updatedAt: 220 }), + makeSession("standalone-running", { running: true, updatedAt: 500 }), + makeSession("standalone-unread", { updatedAt: 300 }), + ]); + + const statusEntries = { + "grandchild-unread": { completionUnread: true }, + "child-pending": { pendingKind: "approval" as const }, + "child-unread": { completionUnread: true }, + "standalone-running": { running: true }, + "standalone-unread": { completionUnread: true }, + }; + const statuses = makeStatuses(statusEntries); + + const projection = deriveActivityView(list, defaultRowState, statuses); + + // Pending subtree ranks first, running second, unread subtree (effective updatedAt 600) ahead of unread (300). + expect(projection.rows.map((row) => row.id)).toEqual([ + SessionId("parent-with-pending-child"), + SessionId("standalone-running"), + SessionId("parent-with-unread-grandchild"), + SessionId("standalone-unread"), + ]); + expect(activityPriorityOf(projection.rows[0]!)).toBe(0); + expect(activityPriorityOf(projection.rows[1]!)).toBe(1); + expect(activityPriorityOf(projection.rows[2]!)).toBe(2); + + const unreadIds = collectUnreadSessionIds(projection.rows); + expect(unreadIds).toEqual([ + SessionId("child-unread"), + SessionId("grandchild-unread"), + SessionId("standalone-unread"), + ]); + expect(projection.unreadSessionIds).toEqual(unreadIds); + + // Simulating markCompletionsRead(unreadIds) clears only unread reminders, leaving pending & running untouched. + const afterMarkRead = new Map(statuses); + for (const id of unreadIds) { + const current = afterMarkRead.get(id); + if (current) afterMarkRead.set(id, { ...current, completionUnread: false }); + } + const nextProjection = deriveActivityView(list, defaultRowState, afterMarkRead); + expect(nextProjection.rows.map((row) => row.id)).toEqual([ + SessionId("parent-with-pending-child"), + SessionId("standalone-running"), + ]); + expect(nextProjection.unreadSessionIds).toEqual([]); + expect(nextProjection.pendingCount).toBe(1); + expect(nextProjection.runningCount).toBe(1); + expect(nextProjection.hasAttention).toBe(true); + }); + + it("sets hasAttention to false when sessions are only running without pending interactions or unread completions", () => { + const list = makeList([makeSession("worker", { running: true, updatedAt: 100 })]); + const statuses = makeStatuses({ worker: { running: true } }); + + const projection = deriveActivityView(list, defaultRowState, statuses); + expect(projection.rows.map((row) => row.id)).toEqual([SessionId("worker")]); + expect(projection.runningCount).toBe(1); + expect(projection.pendingCount).toBe(0); + expect(projection.unreadCount).toBe(0); + expect(projection.hasAttention).toBe(false); + }); + + it("scopes activity rows and unread collection to the active host scope filter", () => { + const remote = { + hostId: "remote-peer:demo-node", + displayName: "Demo Node", + state: "connected", + color: "blue", + }; + const workspaces: WorkspaceView[] = [ + { + workspaceId: "ws-local" as WorkspaceId, + title: "alpha-app", + path: "/work/alpha-app", + sessionIds: [SessionId("local-unread")], + createdAt: "2026-01-01T00:00:00.000Z", + updatedAt: "2026-01-01T00:00:00.000Z", + }, + { + workspaceId: "ws-remote" as WorkspaceId, + title: "beta-service", + path: "/srv/beta-service", + sessionIds: [SessionId("remote-unread")], + remote, + createdAt: "2026-01-01T00:00:00.000Z", + updatedAt: "2026-01-01T00:00:00.000Z", + }, + ]; + const fullList = makeList([ + makeSession("local-unread", { updatedAt: 200 }), + makeSession("remote-unread", { updatedAt: 300, remote }), + ]); + const statuses = makeStatuses({ + "local-unread": { completionUnread: true }, + "remote-unread": { completionUnread: true }, + }); + + const remoteOnlyFilter: HostScopeFilterState = { + selectedHost: remote.hostId, + perHost: {}, + }; + const allowedIds = new Set( + filterSessionsByHostScope( + fullList.ids.map((id) => ({ + id, + remote: fullList.byId[id]?.projectionValues?.remoteHost ?? undefined, + })), + new Set(["ws-remote"]), + workspaces, + remoteOnlyFilter, + ).map((entry) => entry.id), + ); + const scopedList: SessionListState = { + ...fullList, + ids: fullList.ids.filter((id) => allowedIds.has(id)), + }; + + const projection = deriveActivityView(scopedList, defaultRowState, statuses); + expect(projection.rows.map((row) => row.id)).toEqual([SessionId("remote-unread")]); + expect(projection.unreadSessionIds).toEqual([SessionId("remote-unread")]); + }); +}); diff --git a/docs/product/standalone-web.md b/docs/product/standalone-web.md index 1ce63cf501..c935dce1f4 100644 --- a/docs/product/standalone-web.md +++ b/docs/product/standalone-web.md @@ -642,7 +642,7 @@ Web 操作在持久写入并重新读取确认后才发布完整置顶集合;H Desktop 窗口未运行时,Host 使用同一条路径完成置顶和取消置顶;需要原生分区定义或混合排序时按需启动已安装的 Codex app-server,不启动 Desktop 窗口。完整置顶查询始终需要官方分区,即使没有 canonical external 置顶也不能省略官方读取;只读外部工作区元数据本身不启动原生后台。没有可用原生组件或分区协议不受支持时明确失败,保留最后确认的前端投影;不保存预置顶标记、不延迟补写、不回退到 Renderer 或本地置顶,也不自动重发未知结果的写入。`codexhost/workspace/read` 的置顶成员仅投影同一份外部分区记录,不承担完整置顶集合或官方与外部 Thread 混合顺序查询。隔离原生后台测试验证官方与外部成员的无窗口双向置顶/取消、Host 及官方后台重启恢复、原生协议读取与无镜像会话,不修改用户真实置顶;不同原生版本与运行中 Desktop 的即时界面刷新不在此验证范围内。 -侧栏会话的 Harness logo 始终独立于运行状态。运行中在右侧原时间位置显示 16px 转圈,浏览器已有的“运行结束但尚未打开”完成提醒和手动未读标记在同一位置显示蓝点;空闲/已查看后恢复时间,打开会话仍按原有逻辑清除提醒,不另建已读索引。未归档、非当前主视图、没有运行活动、待处理交互或未读提醒的会话可通过内置菜单选择「标记为未读」,不打开会话或改变运行状态。未归档的父会话只要有一个已加载后代显示未读提醒,菜单就提供「将子对话全部标为已读」。归档或被运行、交互状态遮住的未读提醒不单独计数,也不触发该入口。该操作清除父行显示树中全部后代的手动与自动未读,保留父会话自身和树外旁支的提醒,当前选择、运行及展开状态不变。置顶、项目、最近、单列表和搜索状态位置一致;置顶行也仅在悬停或键盘聚焦等操作态显示图钉快捷按钮,手机状态与 44px 菜单按钮并排而不重叠。审批/提问继续使用原有优先级和紧凑文字,归档与未发送草稿不显示新的活动标记,详情卡片保留状态说明。 +侧栏会话的 Harness logo 始终独立于运行状态。运行中在右侧原时间位置显示 16px 转圈,浏览器已有的“运行结束但尚未打开”完成提醒和手动未读标记在同一位置显示蓝点;空闲/已查看后恢复时间,打开会话仍按原有逻辑清除提醒,不另建已读索引。未归档、非当前主视图、没有运行活动、待处理交互或未读提醒的会话可通过内置菜单选择「标记为未读」,不打开会话或改变运行状态。未归档的父会话只要有一个已加载后代显示未读提醒,菜单就提供「将子对话全部标为已读」。归档或被运行、交互状态遮住的未读提醒不单独计数,也不触发该入口。该操作清除父行显示树中全部后代的手动与自动未读,保留父会话自身和树外旁支的提醒,当前选择、运行及展开状态不变。侧栏「会话」标题行右侧提供「活动视图」切换按钮(快捷键 macOS 为 `⌥⌘U`、Windows/Linux 为 `Ctrl+Alt+U`,收纳于快捷键参考面板;未激活且存在待交互或未读会话时显示角标点),仅列出当前主机作用域下未归档且有待处理交互、运行中(含运行中子智能体)或未读完成提醒的会话及其子会话树,按「待交互 > 运行中 > 未读」与最近更新时间排序;活动视图顶部提供「全部已读」按钮,一键清除当前范围内全部未读完成提醒(含可见子会话树后代)而不切换当前会话,也不清除待交互或运行中状态。置顶、项目、最近、单列表和搜索状态位置一致;置顶行也仅在悬停或键盘聚焦等操作态显示图钉快捷按钮,手机状态与 44px 菜单按钮并排而不重叠。审批/提问继续使用原有优先级和紧凑文字,归档与未发送草稿不显示新的活动标记,详情卡片保留状态说明。 状态继续来自已有投影;原生审批按事件通道能力呈现。完成提醒和手动未读仅是当前浏览器内存中的状态,刷新后不恢复,不冒充 Codex 的持久未读状态或跨端已读同步。正文通用运行文案使用“正在处理 / Working”,不暗示某个 Model、推理模式或深度研究能力。 diff --git a/tests/vitest.config.js b/tests/vitest.config.js index 557fa56605..66d9b8115e 100644 --- a/tests/vitest.config.js +++ b/tests/vitest.config.js @@ -22,6 +22,7 @@ const include = [ "apps/web-ui/packages/client/ui-sidebar-browser/test/*.test.ts", "apps/web-ui/packages/client/ui-sidebar-documentpreview/test/*.test.ts", "apps/web-ui/packages/client/ui-sidebar-files/test/*.test.ts", + "apps/web-ui/packages/client/ui-workspace/test/activity-view.test.ts", "apps/web-ui/packages/client/ui-workspace/test/recent-visits.test.ts", "apps/web-ui/packages/client/web/test/*.test.ts", "apps/web-ui/packages/client/hmr/tests/*.spec.ts",