Skip to content

The agent that grows with you

fix: route sidebar row classifiers through the backend session owner map

teknium1b111e4139242
diff --git a/apps/desktop/src/app/chat/sidebar/index.tsx b/apps/desktop/src/app/chat/sidebar/index.tsx
index 2d24ef862ef..7ec0fc67ff2 100644
--- a/apps/desktop/src/app/chat/sidebar/index.tsx
+++ b/apps/desktop/src/app/chat/sidebar/index.tsx
@@ -86,6 +86,7 @@ import { $profileRailVisible } from '@/store/profile-rail-prefs'
import {
$activeProjectId,
$newProjectDropPlacement,
+ $projectOwnerBySessionId,
$projects,
$projectScope,
$projectTree,
@@ -163,7 +164,6 @@ import {
PROJECT_PREVIEW_COUNT,
ProjectBackRow,
ProjectMenu,
- projectOwnerBySessionId,
projectTreeCwd,
reconcileEnteredProjectSessions,
sessionBucketId,
@@ -439,6 +439,7 @@ export function ChatSidebar({
const projectOrderIds = useStore($sidebarProjectOrderIds)
const projects = useStore($projects)
const projectTree = useStore($projectTree)
+ const projectOwners = useStore($projectOwnerBySessionId)
// The persisted project filter's storage is shared across profiles, so ids
// picked in another profile don't resolve in the active one and the raw
@@ -548,11 +549,22 @@ export function ChatSidebar({
}
}
- // Same membership the sidebar groups and colors by, so a filtered row
- // lands in the lane the user picked it from.
- return sessionMatchesProjectFilter(session, projectFilter, projects)
+ // Same membership the sidebar groups and colors by (backend owner first,
+ // cwd walk otherwise), so a filtered row lands in the lane the user
+ // picked it from.
+ return sessionMatchesProjectFilter(session, projectFilter, projects, projectOwners)
},
- [statusFilter, projectFilter, profileFilter, showAllProfiles, prFilter, pullRequests, projects, dotStates]
+ [
+ statusFilter,
+ projectFilter,
+ profileFilter,
+ showAllProfiles,
+ prFilter,
+ pullRequests,
+ projects,
+ projectOwners,
+ dotStates
+ ]
)
const filtersNarrow =
@@ -1047,14 +1059,9 @@ export function ChatSidebar({
const enteredProjectContent = useMemo(
() =>
enteredProject
- ? overlayLiveLanes(
- enteredProject,
- enteredProjectOverlaySessions,
- removedSessionIds,
- projectOwnerBySessionId(agentProjectTree ?? [])
- )
+ ? overlayLiveLanes(enteredProject, enteredProjectOverlaySessions, removedSessionIds, projectOwners)
: undefined,
- [enteredProject, enteredProjectOverlaySessions, removedSessionIds, agentProjectTree]
+ [enteredProject, enteredProjectOverlaySessions, removedSessionIds, projectOwners]
)
const scopedRepoPaths = useMemo(
@@ -1183,7 +1190,7 @@ export function ChatSidebar({
const counts: Record<string, number> = {}
for (const session of sessions) {
- const projectId = isHidden(session) ? sessionBucketId(session, projects) : null
+ const projectId = isHidden(session) ? sessionBucketId(session, projects, projectOwners) : null
if (projectId) {
counts[projectId] = (counts[projectId] ?? 0) + 1
@@ -1191,7 +1198,7 @@ export function ChatSidebar({
}
return { isHidden, counts }
- }, [sessions, projects, isHiddenFromProjects, removedSessionIds])
+ }, [sessions, projects, projectOwners, isHiddenFromProjects, removedSessionIds])
const onEnterProject = useCallback(
(id: string) => {
diff --git a/apps/desktop/src/app/chat/sidebar/projects/workspace-groups.test.ts b/apps/desktop/src/app/chat/sidebar/projects/workspace-groups.test.ts
index 7bdd50ab1b1..2045d4a7d35 100644
--- a/apps/desktop/src/app/chat/sidebar/projects/workspace-groups.test.ts
+++ b/apps/desktop/src/app/chat/sidebar/projects/workspace-groups.test.ts
@@ -15,6 +15,7 @@ import {
overlayLivePreviews,
projectOwnerBySessionId,
reconcileEnteredProjectSessions,
+ sessionBucketId,
sessionMatchesProjectFilter,
sessionProjectColor,
type SidebarProjectTree,
@@ -1311,4 +1312,22 @@ describe('project filter row rule (#97762)', () => {
expect(sessionMatchesProjectFilter(appRow, ['p_app'], projects)).toBe(true)
expect(sessionMatchesProjectFilter(homeRow, ['p_app'], projects)).toBe(false)
})
+
+ // Issue layout: the sibling worktree /work/repos/app-2 sits under the
+ // ancestor "work" folder by cwd alone, but the backend tree owns it via "app".
+ // Filter, bucket and color must follow that owner, like the lane overlay does.
+ it('follows the backend owner map for a sibling worktree row, not the cwd walk', () => {
+ const explicit = [makeProject('p_work', ['/work']), { ...makeProject('p_app', ['/work/repos/app']), color: '#abc' }]
+ const sibling = makeCwdSession('/work/repos/app-2', { id: 'sibling', git_repo_root: null })
+
+ const owners = projectOwnerBySessionId([
+ projectNode({ id: 'p_work', path: '/work' }),
+ projectNode({ id: 'p_app', path: '/work/repos/app', sessionIds: ['sibling'] })
+ ])
+
+ expect(sessionMatchesProjectFilter(sibling, ['p_work'], explicit, owners)).toBe(false)
+ expect(sessionMatchesProjectFilter(sibling, ['p_app'], explicit, owners)).toBe(true)
+ expect(sessionBucketId(sibling, explicit, owners)).toBe('p_app')
+ expect(sessionProjectColor(sibling, explicit, owners)).toBe('#abc')
+ })
})
diff --git a/apps/desktop/src/app/chat/sidebar/projects/workspace-groups.ts b/apps/desktop/src/app/chat/sidebar/projects/workspace-groups.ts
index c6ec5f1aacd..ae1fa18c2b4 100644
--- a/apps/desktop/src/app/chat/sidebar/projects/workspace-groups.ts
+++ b/apps/desktop/src/app/chat/sidebar/projects/workspace-groups.ts
@@ -359,6 +359,8 @@ export function mergeRepoWorktreeGroups(
// needs the backend common-root probe, so those rows are left for the next
// tree refresh; the common case (a new main-checkout session) overlays here.
+const NO_OWNERS: ReadonlyMap<string, string> = new Map()
+
/** True when `target` equals `folder` or is nested under it (segment-wise). */
function isPathUnder(folder: string, target: string): boolean {
const f = comparisonSegments(folder)
@@ -385,8 +387,21 @@ function isPathUnder(folder: string, target: string): boolean {
* the row's cwd sits outside its recorded repo root (a mid-session relocation,
* or a sibling worktree of a project repo), the folder match is authoritative;
* only the repo-root AUTO-project fallback needs cwd-under-root confidence.
+ * When the backend tree already claims the row (`owners`, see
+ * {@link projectOwnerBySessionId}), that owner wins over the cwd walk so a
+ * sibling worktree under an umbrella folder files with its repo project.
*/
-export function liveSessionProjectId(session: SessionInfo, explicitProjects: ProjectInfo[]): null | string {
+export function liveSessionProjectId(
+ session: SessionInfo,
+ explicitProjects: ProjectInfo[],
+ owners: ReadonlyMap<string, string> = NO_OWNERS
+): null | string {
+ const owner = owners.get(session.id)
+
+ if (owner && owner !== NO_PROJECT_ID) {
+ return owner
+ }
+
const cwd = (session.cwd || '').trim()
// A session may carry only a git_repo_root and no cwd — older/imported rows,
// or ones captured before cwd tracking. The backend still groups those by repo
@@ -435,8 +450,12 @@ export function liveSessionProjectId(session: SessionInfo, explicitProjects: Pro
}
/** The lane a row files under: its live project, or Home for detached (cwd-less) rows. */
-export function sessionBucketId(session: SessionInfo, explicitProjects: ProjectInfo[]): null | string {
- return liveSessionProjectId(session, explicitProjects) ?? (isDetachedSession(session) ? NO_PROJECT_ID : null)
+export function sessionBucketId(
+ session: SessionInfo,
+ explicitProjects: ProjectInfo[],
+ owners: ReadonlyMap<string, string> = NO_OWNERS
+): null | string {
+ return liveSessionProjectId(session, explicitProjects, owners) ?? (isDetachedSession(session) ? NO_PROJECT_ID : null)
}
/**
@@ -448,13 +467,14 @@ export function sessionBucketId(session: SessionInfo, explicitProjects: ProjectI
export function sessionMatchesProjectFilter(
session: SessionInfo,
filter: readonly string[],
- explicitProjects: ProjectInfo[]
+ explicitProjects: ProjectInfo[],
+ owners: ReadonlyMap<string, string> = NO_OWNERS
): boolean {
if (!filter.length) {
return true
}
- const id = sessionBucketId(session, explicitProjects)
+ const id = sessionBucketId(session, explicitProjects, owners)
return id !== null && filter.includes(id)
}
@@ -469,8 +489,12 @@ export function sessionMatchesProjectFilter(
* sidebar groups by; returns null for rootless / kanban / out-of-tree rows and
* for sessions under an uncolored (or auto) project.
*/
-export function sessionProjectColor(session: SessionInfo, projects: ProjectInfo[]): null | string {
- const projectId = liveSessionProjectId(session, projects)
+export function sessionProjectColor(
+ session: SessionInfo,
+ projects: ProjectInfo[],
+ owners: ReadonlyMap<string, string> = NO_OWNERS
+): null | string {
+ const projectId = liveSessionProjectId(session, projects, owners)
if (!projectId) {
return null
@@ -776,7 +800,7 @@ export function overlayLiveLanes(
project: SidebarProjectTree,
live: SessionInfo[],
removed: ReadonlySet<string> = NO_REMOVED,
- authoritativeOwners: ReadonlyMap<string, string> = new Map()
+ authoritativeOwners: ReadonlyMap<string, string> = NO_OWNERS
): SidebarProjectTree {
if (project.isNoProject) {
return overlayHomeLane(project, live, removed)
diff --git a/apps/desktop/src/lib/session-project-label.ts b/apps/desktop/src/lib/session-project-label.ts
index aa64f523660..c1bb4de0b0a 100644
--- a/apps/desktop/src/lib/session-project-label.ts
+++ b/apps/desktop/src/lib/session-project-label.ts
@@ -1,5 +1,6 @@
import { liveSessionProjectId } from '@/app/chat/sidebar/projects/workspace-groups'
import { pathLeaf } from '@/lib/display-path'
+import { $projectOwnerBySessionId } from '@/store/projects'
import type { ProjectInfo, SessionInfo } from '@/types/hermes'
/**
@@ -26,7 +27,7 @@ import type { ProjectInfo, SessionInfo } from '@/types/hermes'
* unplaced.
*/
export function sessionProjectLabel(session: SessionInfo, projects: ProjectInfo[]): null | string {
- const projectId = liveSessionProjectId(session, projects)
+ const projectId = liveSessionProjectId(session, projects, $projectOwnerBySessionId.get())
if (projectId) {
const explicit = projects.find(project => project.id === projectId)
diff --git a/apps/desktop/src/store/projects.ts b/apps/desktop/src/store/projects.ts
index 47693451c93..13d4ee93f69 100644
--- a/apps/desktop/src/store/projects.ts
+++ b/apps/desktop/src/store/projects.ts
@@ -1,9 +1,10 @@
-import { atom } from 'nanostores'
+import { atom, computed } from 'nanostores'
import type { NewSessionPlacement } from '@/app/chat/new-session-drag'
import {
liveSessionProjectId,
NO_PROJECT_ID,
+ projectOwnerBySessionId,
type SidebarProjectTree
} from '@/app/chat/sidebar/projects/workspace-groups'
import type { HermesGitBaseBranch, HermesGitBranch } from '@/global'
@@ -48,6 +49,11 @@ export const $activeProjectId = atom<null | string>(null)
// source of project membership — the desktop no longer derives it.
export const $projectTree = atom<SidebarProjectTree[]>([])
export const $projectTreeLoading = atom(false)
+// Backend-resolved session -> project owner, the ONE authority the row
+// classifiers (filter, bucket, color, label) and the lane overlay share, so a
+// sibling worktree the git probe assigned to its repo project never re-files
+// under an umbrella folder by cwd.
+export const $projectOwnerBySessionId = computed($projectTree, projectOwnerBySessionId)
// False when the connected backend predates the projects.* JSON-RPC surface
// (same semver label, older install). Null until the first probe.
@@ -1106,7 +1112,7 @@ function openSessionBelongsToProject(projectId: string, projects: ProjectInfo[])
const open = $sessions.get().find(s => sessionMatchesStoredId(s, openId))
- return Boolean(open && liveSessionProjectId(open, projects) === projectId)
+ return Boolean(open && liveSessionProjectId(open, projects, $projectOwnerBySessionId.get()) === projectId)
}
// Optimistic: drop the project from the cached tree + list the instant it's
diff --git a/apps/desktop/src/store/session-color.ts b/apps/desktop/src/store/session-color.ts
index f4925496d99..d211ceff439 100644
--- a/apps/desktop/src/store/session-color.ts
+++ b/apps/desktop/src/store/session-color.ts
@@ -2,7 +2,7 @@ import { computed } from 'nanostores'
import { sessionProjectColor } from '@/app/chat/sidebar/projects/workspace-groups'
import { Codecs, persistentAtom } from '@/lib/persisted'
-import { $projects } from '@/store/projects'
+import { $projectOwnerBySessionId, $projects } from '@/store/projects'
import { $sessions, sessionPinId } from '@/store/session'
import type { ProjectInfo, SessionInfo } from '@/types/hermes'
@@ -42,18 +42,19 @@ export function setSessionColorOverride(durableId: string, color: null | string)
function resolveSessionColor(
session: SessionInfo,
projects: ProjectInfo[],
- overrides: Record<string, string>
+ overrides: Record<string, string>,
+ owners: ReadonlyMap<string, string>
): string | undefined {
- return overrides[sessionPinId(session)] ?? sessionProjectColor(session, projects) ?? undefined
+ return overrides[sessionPinId(session)] ?? sessionProjectColor(session, projects, owners) ?? undefined
}
export const $sessionColorById = computed(
- [$sessions, $projects, $sessionColorOverrides],
- (sessions, projects, overrides) => {
+ [$sessions, $projects, $sessionColorOverrides, $projectOwnerBySessionId],
+ (sessions, projects, overrides, owners) => {
const map: Record<string, string> = {}
for (const session of sessions) {
- const color = resolveSessionColor(session, projects, overrides)
+ const color = resolveSessionColor(session, projects, overrides, owners)
if (color) {
map[session.id] = color
@@ -75,6 +76,7 @@ export function sessionColorFor(session: null | SessionInfo | undefined): string
}
return (
- $sessionColorById.get()[session.id] ?? resolveSessionColor(session, $projects.get(), $sessionColorOverrides.get())
+ $sessionColorById.get()[session.id] ??
+ resolveSessionColor(session, $projects.get(), $sessionColorOverrides.get(), $projectOwnerBySessionId.get())
)
}