🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
✨ feat(topic): lead byProject grouping with explicit-project groups (#20715)
Arvin Xu944e1d0804fe
diff --git a/packages/utils/src/client/topic.test.ts b/packages/utils/src/client/topic.test.tsindex c21c16b9baa..f2bdea4b66f 100644--- a/packages/utils/src/client/topic.test.ts+++ b/packages/utils/src/client/topic.test.ts@@ -723,6 +723,53 @@ describe('groupTopicsByProject project merging', () => {'no-project',]);});++ /** @example A stale explicit project still leads a freshly active directory group. */+ it('sorts explicit-project groups ahead of directory groups regardless of activity', () => {+ // ROOT CAUSE:+ //+ // Groups sorted purely by most recent activity, so a project the user+ // deliberately bound topics to could sink below an inferred directory+ // group. Explicit bindings are stronger signals and lead the list; only+ // groups within the same tier compete on activity.+ const topics: ChatTopic[] = [+ {+ ...base,+ createdAt: 1,+ updatedAt: 1,+ id: 'bound-stale',+ projectId: 'project-1',+ metadata: { workingDirectory: '/home/lobehub' },+ },+ {+ ...base,+ createdAt: 3,+ updatedAt: 3,+ id: 'unbound-recent',+ metadata: { workingDirectory: '/tmp/scratch' },+ },+ { ...base, createdAt: 2, updatedAt: 2, id: 'unbound' },+ ];++ expect(groupTopicsByProject(topics, 'updatedAt').map((group) => group.id)).toEqual([+ 'project-id:project-1',+ 'project:/tmp/scratch',+ 'no-project',+ ]);+ });++ /** @example Within the explicit-project tier the most recently active project still leads. */+ it('keeps most-recent-activity order inside the explicit-project tier', () => {+ const topics: ChatTopic[] = [+ { ...base, createdAt: 1, updatedAt: 1, id: 'older', projectId: 'project-1' },+ { ...base, createdAt: 2, updatedAt: 2, id: 'newer', projectId: 'project-2' },+ ];++ expect(groupTopicsByProject(topics, 'updatedAt').map((group) => group.id)).toEqual([+ 'project-id:project-2',+ 'project-id:project-1',+ ]);+ });});describe('groupTopicsByAgent', () => {diff --git a/packages/utils/src/client/topic.ts b/packages/utils/src/client/topic.tsindex df81c077117..ea6390d79c4 100644--- a/packages/utils/src/client/topic.ts+++ b/packages/utils/src/client/topic.ts@@ -195,6 +195,9 @@ export const getTopicWorkingDirectoryEffectivePath = (topic: ChatTopic): string* - `project-id:{projectId}` groups that merge every directory of one project* into a single group, `project-directory:{id}` / path-based IDs for topics* without a project, and `no-project` last.+ * - Groups ordered with explicit-project groups first (the binding is+ * deliberate, not inferred from a directory), then directory-derived groups,+ * then `no-project`; each tier keeps most-recent-activity order.* - Basenames for unique projects and distinguishing path suffixes for collisions.*/export const groupTopicsByProject = (@@ -270,10 +273,17 @@ export const groupTopicsByProject = (},);- // Most-recently-active project first; "no project" always last+ // Explicit-project groups first (the `projectId` binding is deliberate, not+ // inferred), then directory-derived groups, then "no project" last. Within a+ // tier the most recently active group leads.+ const groupRank = (id: string): number => {+ if (id === NO_PROJECT_GROUP_ID) return 2;+ return id.startsWith(PROJECT_ID_GROUP_PREFIX) ? 0 : 1;+ };+return groups.sort((a, b) => {- if (a.id === NO_PROJECT_GROUP_ID) return 1;- if (b.id === NO_PROJECT_GROUP_ID) return -1;+ const rankDiff = groupRank(a.id) - groupRank(b.id);+ if (rankDiff !== 0) return rankDiff;const aTime = a.children[0] ? getTopicSortTime(a.children[0], field) : 0;const bTime = b.children[0] ? getTopicSortTime(b.children[0], field) : 0;return bTime - aTime;