Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

feat(chat-sidebar): list existing groups in "Move to group" submenu (#4528)

Louis Beaumonta8b27e888305
diff --git a/apps/screenpipe-app-tauri/components/__tests__/chat-sidebar-grouping.test.ts b/apps/screenpipe-app-tauri/components/__tests__/chat-sidebar-grouping.test.ts
index a30b30254..cec8bf725 100644
--- a/apps/screenpipe-app-tauri/components/__tests__/chat-sidebar-grouping.test.ts
+++ b/apps/screenpipe-app-tauri/components/__tests__/chat-sidebar-grouping.test.ts
@@ -9,6 +9,7 @@ import {
sessionGroupTitle,
buildGroupedRecents,
buildSidebarRecentsSections,
+ listMoveTargetGroups,
recurringPipeGroupKeys,
validateSidebarGroupName,
} from "@/lib/utils/chat-sidebar-grouping";
@@ -300,6 +301,96 @@ describe("buildSidebarRecentsSections", () => {
expect(productSection?.items).toHaveLength(10);
expect(ungroupedSection?.items).toHaveLength(20);
});
+
+ it("folds a chat moved into a pipe-group name into that group", () => {
+ // Two runs of the "daily" pipe form an auto group; a plain chat moved
+ // into "daily" should join that group, not spawn a separate section.
+ const result = buildSidebarRecentsSections([
+ s("p1", "daily #1", "daily"),
+ s("p2", "daily #2", "daily"),
+ s("c", "moved chat", undefined, "daily"),
+ ]);
+ expect(result).toHaveLength(1);
+ expect(result[0].title).toBe("");
+ expect(result[0].items).toHaveLength(1);
+ const group = result[0].items[0];
+ expect(group.kind).toBe("group");
+ if (group.kind === "group") {
+ expect(group.title).toBe("daily");
+ expect(group.sessions.map((x) => x.id).sort()).toEqual(["c", "p1", "p2"]);
+ }
+ });
+
+ it("merges case-insensitively against the pipe-group name", () => {
+ const result = buildSidebarRecentsSections([
+ s("p1", "daily #1", "daily"),
+ s("p2", "daily #2", "daily"),
+ s("c", "moved chat", undefined, "DAILY"),
+ ]);
+ expect(result).toHaveLength(1);
+ expect(result[0].items[0].kind).toBe("group");
+ if (result[0].items[0].kind === "group") {
+ expect(result[0].items[0].sessions).toHaveLength(3);
+ }
+ });
+
+ it("keeps a manual group separate when no pipe-group shares its name", () => {
+ const result = buildSidebarRecentsSections([
+ s("p1", "daily #1", "daily"),
+ s("p2", "daily #2", "daily"),
+ s("c", "moved chat", undefined, "work"),
+ ]);
+ // "work" has no matching pipe → its own titled section; "daily" stays a
+ // pipe group in the ungrouped section.
+ expect(result.map((sec) => sec.title)).toEqual(["work", "other"]);
+ expect(result[0].items[0].kind).toBe("single");
+ expect(result[1].items[0].kind).toBe("group");
+ });
+
+ it("does not adopt into a single (non-recurring) pipe session", () => {
+ // Only one "daily" run → not an auto group, so "daily" is a plain
+ // manual section, not a merge target.
+ const result = buildSidebarRecentsSections([
+ s("p1", "daily #1", "daily"),
+ s("c", "moved chat", undefined, "daily"),
+ ]);
+ expect(result.map((sec) => sec.title)).toEqual(["daily", "other"]);
+ });
+});
+
+// ── listMoveTargetGroups ─────────────────────────────────────────────
+
+describe("listMoveTargetGroups", () => {
+ it("lists manual groups before recurring pipe groups", () => {
+ const result = listMoveTargetGroups([
+ s("a", "chat", undefined, "work"),
+ s("p1", "daily #1", "daily"),
+ s("p2", "daily #2", "daily"),
+ s("u", "ungrouped chat"),
+ ]);
+ expect(result).toEqual(["work", "daily"]);
+ });
+
+ it("omits pipe names that appear only once", () => {
+ const result = listMoveTargetGroups([
+ s("p1", "daily #1", "daily"),
+ s("o", "one-off #1", "oneoff"),
+ ]);
+ expect(result).toEqual([]);
+ });
+
+ it("dedupes a manual group that shadows a pipe name", () => {
+ const result = listMoveTargetGroups([
+ s("p1", "daily #1", "daily"),
+ s("p2", "daily #2", "daily"),
+ s("c", "moved chat", undefined, "daily"),
+ ]);
+ expect(result).toEqual(["daily"]);
+ });
+
+ it("returns an empty list when there are no groups", () => {
+ expect(listMoveTargetGroups([s("a", "chat A"), s("b", "chat B")])).toEqual([]);
+ });
});
// ── applySidebarRecentsCap ───────────────────────────────────────────
diff --git a/apps/screenpipe-app-tauri/components/chat-sidebar.tsx b/apps/screenpipe-app-tauri/components/chat-sidebar.tsx
index 0192f67a2..c5ba78930 100644
--- a/apps/screenpipe-app-tauri/components/chat-sidebar.tsx
+++ b/apps/screenpipe-app-tauri/components/chat-sidebar.tsx
@@ -115,6 +115,7 @@ import { requestPipeStop } from "@/lib/pipe-stop";
import {
applySidebarRecentsCap,
buildSidebarRecentsSections,
+ listMoveTargetGroups,
recurringPipeGroupKeys,
sessionGroupKey,
type SidebarItem,
@@ -571,21 +572,14 @@ export function ChatSidebar({ className, onViewAll }: ChatSidebarProps) {
} catch { /* ignore */ }
}, [groupedSections]);
- // Derive existing manual group names from all visible non-hidden
- // sessions (pinned + recents) so the "Move to group" submenu
- // includes groups that currently only contain pinned chats.
- const existingGroups = useMemo(() => {
- const groups: string[] = [];
- const seen = new Set<string>();
- for (const s of [...pinned, ...recents]) {
- const g = s.sidebarGroup?.trim();
- if (g && !seen.has(g)) {
- seen.add(g);
- groups.push(g);
- }
- }
- return groups;
- }, [pinned, recents]);
+ // Group names offered in the "Move to group" submenu, derived from all
+ // visible non-hidden sessions (pinned + recents): manual groups plus the
+ // auto pipe-groups the user actually sees in the sidebar. Moving a chat
+ // into a pipe-group's name folds it into that same group.
+ const existingGroups = useMemo(
+ () => listMoveTargetGroups([...pinned, ...recents]),
+ [pinned, recents],
+ );
// Resolve each running pipe to its SessionRecord so the Scheduled-row
// kebab can offer Pin / Rename / Archive / Delete with the same
@@ -2232,8 +2226,14 @@ export function SidebarChatRow({
const age = formatCompactAge(activityAt, now);
const canSwapAgeForMenu = !isLive && !isError && queuedCount === 0 && !isUnread && Boolean(age);
const menuOpen = openConversationMenuId === session.id;
+ // Exclude the group the session already lives in — whether it was placed
+ // there manually (sidebarGroup) or auto-grouped by pipe name.
+ const currentGroup = (
+ session.sidebarGroup ?? session.pipeContext?.pipeName
+ )?.trim().toLowerCase();
const availableMoveGroups =
- existingGroups?.filter((group) => group !== session.sidebarGroup) ?? [];
+ existingGroups?.filter((group) => group.trim().toLowerCase() !== currentGroup) ??
+ [];
const rowMenuActions = {
onArchive,
onUnarchive,
diff --git a/apps/screenpipe-app-tauri/components/chat/chat-history-view.tsx b/apps/screenpipe-app-tauri/components/chat/chat-history-view.tsx
index 043833d17..367f9681f 100644
--- a/apps/screenpipe-app-tauri/components/chat/chat-history-view.tsx
+++ b/apps/screenpipe-app-tauri/components/chat/chat-history-view.tsx
@@ -39,7 +39,10 @@ import {
type ConversationMeta,
} from "@/lib/chat-storage";
import { useChatStore } from "@/lib/stores/chat-store";
-import { validateSidebarGroupName } from "@/lib/utils/chat-sidebar-grouping";
+import {
+ listMoveTargetGroups,
+ validateSidebarGroupName,
+} from "@/lib/utils/chat-sidebar-grouping";
type HistoryTab = "active" | "archived" | "all";
@@ -302,17 +305,12 @@ export function ChatHistoryView({
[patchSidebarSession, visibleById]
);
- // Derive existing manual groups from loaded conversations for the
- // "Move to group" submenu. Insertion order preserved.
- const existingGroups = useMemo(() => {
- const groups: string[] = [];
- const seen = new Set<string>();
- for (const c of conversations) {
- const g = (c as any).sidebarGroup?.trim() as string | undefined;
- if (g && !seen.has(g)) { seen.add(g); groups.push(g); }
- }
- return groups;
- }, [conversations]);
+ // Group names for the "Move to group" submenu: manual groups plus the
+ // auto pipe-groups visible in the sidebar. Insertion order preserved.
+ const existingGroups = useMemo(
+ () => listMoveTargetGroups(conversations),
+ [conversations],
+ );
const selectableExistingGroups = existingGroups;
// State for the "New group" dialog — stores the conversation id being moved.
@@ -352,9 +350,14 @@ export function ChatHistoryView({
const selectionMode = selectedIds.size > 0;
const rowPending = rowPendingIds.has(conv.id);
const showCheckbox = selectionMode || selected;
- const currentSidebarGroup = (conv as any).sidebarGroup as string | undefined;
+ const currentSidebarGroup = conv.sidebarGroup;
+ // Exclude the group the conversation already lives in — placed there
+ // manually (sidebarGroup) or auto-grouped by pipe name.
+ const currentGroup = (
+ currentSidebarGroup ?? conv.pipeContext?.pipeName
+ )?.trim().toLowerCase();
const availableMoveGroups = selectableExistingGroups.filter(
- (group) => group !== currentSidebarGroup,
+ (group) => group.trim().toLowerCase() !== currentGroup,
);
return (
<div
diff --git a/apps/screenpipe-app-tauri/lib/utils/chat-sidebar-grouping.ts b/apps/screenpipe-app-tauri/lib/utils/chat-sidebar-grouping.ts
index 76b74d2b4..fac94c0de 100644
--- a/apps/screenpipe-app-tauri/lib/utils/chat-sidebar-grouping.ts
+++ b/apps/screenpipe-app-tauri/lib/utils/chat-sidebar-grouping.ts
@@ -111,6 +111,67 @@ export function recurringPipeGroupKeys(
);
}
+/** Minimal session shape needed to derive group membership. Accepts both
+ * live `SessionRecord`s and persisted `ConversationMeta`s. */
+type GroupableSession = {
+ sidebarGroup?: string;
+ pipeContext?: { pipeName?: string } | null;
+};
+
+/**
+ * Maps lowercased pipe-group name → its display (canonical) casing for
+ * every auto pipe-group present: a pipe name carried by ≥2 sessions that
+ * aren't manually re-grouped. Used both to detect when a manual "Move to
+ * group" target coincides with a pipe group (so the two merge) and to list
+ * the pipe groups as move targets.
+ */
+function recurringPipeDisplayNames(
+ sessions: ReadonlyArray<GroupableSession>,
+): Map<string, string> {
+ const counts = new Map<string, { display: string; count: number }>();
+ for (const s of sessions) {
+ if (s.sidebarGroup?.trim()) continue;
+ const name = s.pipeContext?.pipeName?.trim();
+ if (!name) continue;
+ const lower = name.toLowerCase();
+ const entry = counts.get(lower);
+ if (entry) entry.count += 1;
+ else counts.set(lower, { display: name, count: 1 });
+ }
+ const out = new Map<string, string>();
+ for (const [lower, { display, count }] of counts) {
+ if (count >= 2) out.set(lower, display);
+ }
+ return out;
+}
+
+/**
+ * Group names to offer in the "Move to group" submenu: manual sidebar
+ * groups first (insertion order, original casing), then auto pipe-groups
+ * (the groups the user actually sees in the sidebar). Deduped
+ * case-insensitively so a manual group shadowing a pipe name appears once.
+ */
+export function listMoveTargetGroups(
+ sessions: ReadonlyArray<GroupableSession>,
+): string[] {
+ const seen = new Set<string>();
+ const out: string[] = [];
+ for (const s of sessions) {
+ const g = s.sidebarGroup?.trim();
+ if (!g) continue;
+ const lower = g.toLowerCase();
+ if (seen.has(lower)) continue;
+ seen.add(lower);
+ out.push(g);
+ }
+ for (const [lower, display] of recurringPipeDisplayNames(sessions)) {
+ if (seen.has(lower)) continue;
+ seen.add(lower);
+ out.push(display);
+ }
+ return out;
+}
+
// ── Grouped recents builder ──────────────────────────────────────────
/**
@@ -124,12 +185,14 @@ export function recurringPipeGroupKeys(
export function buildGroupedRecents(
recents: SessionRecord[],
cap = 15,
+ keyOf: (s: SessionRecord) => string | null = sessionGroupKey,
+ titleOf: (s: SessionRecord) => string = sessionGroupTitle,
): SidebarItem[] {
// Pre-count how many times each key appears so we know upfront
// whether a key will become a group (count ≥ 2) or a single.
const keyCounts = new Map<string, number>();
for (const s of recents) {
- const key = sessionGroupKey(s);
+ const key = keyOf(s);
if (key) keyCounts.set(key, (keyCounts.get(key) ?? 0) + 1);
}
@@ -137,7 +200,7 @@ export function buildGroupedRecents(
const result: SidebarItem[] = [];
for (const s of recents) {
- const key = sessionGroupKey(s);
+ const key = keyOf(s);
if (key) {
// Append to an already-visible group — bypasses cap.
@@ -160,7 +223,7 @@ export function buildGroupedRecents(
result.push({
kind: "group",
key,
- title: sessionGroupTitle(s),
+ title: titleOf(s),
sessions: group,
});
}
@@ -195,24 +258,45 @@ export function buildSidebarRecentsSections(
recents: SessionRecord[],
cap = Number.POSITIVE_INFINITY,
): SidebarRecentsSection[] {
- // Split sessions by manual sidebarGroup label.
+ // Auto pipe-groups present in this list (pipe name with ≥2 sessions that
+ // aren't manually re-grouped). A chat manually moved into one of these
+ // names folds into the same group row instead of a duplicate section,
+ // so "Move to group" can target the groups the user actually sees.
+ const recurringPipe = recurringPipeDisplayNames(recents);
+
+ // Split sessions by manual sidebarGroup label. A manual label matching an
+ // auto pipe-group is "adopted" into that group (see keyOf/titleOf below).
const manualGroups = new Map<string, SessionRecord[]>();
const ungrouped: SessionRecord[] = [];
+ const adoptedKey = new Map<string, string>();
+ const adoptedTitle = new Map<string, string>();
for (const session of recents) {
const group = session.sidebarGroup?.trim();
if (group) {
- const existing = manualGroups.get(group);
- if (existing) {
- existing.push(session);
+ const pipeMatch = recurringPipe.get(group.toLowerCase());
+ if (pipeMatch) {
+ ungrouped.push(session);
+ adoptedKey.set(session.id, `pipe:${pipeMatch}`);
+ adoptedTitle.set(session.id, pipeMatch);
} else {
- manualGroups.set(group, [session]);
+ const existing = manualGroups.get(group);
+ if (existing) {
+ existing.push(session);
+ } else {
+ manualGroups.set(group, [session]);
+ }
}
} else {
ungrouped.push(session);
}
}
+ const keyOf = (s: SessionRecord): string | null =>
+ adoptedKey.get(s.id) ?? sessionGroupKey(s);
+ const titleOf = (s: SessionRecord): string =>
+ adoptedTitle.get(s.id) ?? sessionGroupTitle(s);
+
const sections: SidebarRecentsSection[] = [];
// Manual groups first — insertion order, no cap.
@@ -226,7 +310,7 @@ export function buildSidebarRecentsSections(
// Ungrouped section. The main sidebar applies the global recents cap
// later, after subsection collapsed state is known.
- const ungroupedItems = buildGroupedRecents(ungrouped, cap);
+ const ungroupedItems = buildGroupedRecents(ungrouped, cap, keyOf, titleOf);
if (ungroupedItems.length > 0 || sections.length === 0) {
sections.push({
key: "manual:__ungrouped__",