feat(session): show the workspace branch in the session detail header

Resolve the branch from the repo's siblings so a session running in a worktree shows that worktree's branch, falling back to the repo branch and staying empty when no branch is resolvable. Desktop renders a branch chip in the header; mobile appends it to the repo name in the subtitle.
This commit is contained in:
Chris Scott committed 2026-10-16 17:29:31 -04:00
1 parent 4e8051b75a
commit f5d073d7ee
8 files changed
+105 -2

No files matched your search

+18
View File
@@ -3,6 +3,7 @@ import type { ChildOutcome } from '@/lib/backgroundWork'
import type { SessionStatusType } from '@/stores/sessionStatusStore'
import { getSessionKey } from '@/lib/sessionKey'
import { getSessionPath } from '@/lib/navigation'
import { getRepoBranchLabel } from '@/lib/utils'
import { findRepoForDirectory, normalizeDirectory } from '@/components/navigation/sidebar-session-tree'
import { isWorktreeSibling, type RepoSibling } from '@opencode-manager/shared/utils'
@@ -259,6 +260,23 @@ export function buildWorktreeActivity(
return worktrees
}
/**
* The branch of the workspace a session runs in: the matching sibling's branch when the session
* directory is one of the repo's siblings (a worktree), otherwise the repo's own branch.
*/
export function resolveSessionBranch(
repo: Pick<Repo, 'currentBranch' | 'branch'>,
directory: string | null | undefined,
siblings?: ReadonlyArray<RepoSibling>,
): string | null {
const normalized = normalizeDirectory(directory)
const sibling = normalized
? siblings?.find((entry) => normalizeDirectory(entry.fullPath) === normalized)
: undefined
if (!sibling) return getRepoBranchLabel(repo)
return sibling.currentBranch ?? sibling.branch ?? null
}
/**
* Whether the worktree lookup is worth running: true when some non-archived session that matches no
* repo is either updated inside the window or has its root active (needs-input or running).