Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ function makeState(overrides: Partial<AddRepoSkipFinalizationState>): AddRepoSki
hideDefaultBranchWorkspace: false,
showSleepingWorkspaces: true,
alwaysShowDefaultBranchWorkspace: true,
repos: [],
worktreesByRepo: {},
setActiveRepo: vi.fn(),
setFilterRepoIds: vi.fn(),
Expand Down Expand Up @@ -94,6 +95,28 @@ describe('finalizeImportedRepoAfterSkip', () => {
expect(state.setHideDefaultBranchWorkspace).toHaveBeenCalledWith(false)
})

it('clears default-branch hiding for a folder project whose only row is its root', () => {
const state = makeState({
hideDefaultBranchWorkspace: true,
repos: [{ id: 'folder-new', kind: 'folder' }],
worktreesByRepo: {
'folder-new': [
makeWorktree({
id: 'folder-new::/notes',
repoId: 'folder-new',
isMainWorktree: true,
head: '',
branch: ''
})
]
}
})

finalizeImportedRepoAfterSkip(state, 'folder-new')

expect(state.setHideDefaultBranchWorkspace).toHaveBeenCalledWith(false)
})

it('re-enables the default-branch exemption when the import would land asleep and hidden', () => {
const state = makeState({
showSleepingWorkspaces: false,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { Repo } from '../../../../shared/repo-types'
import type { Worktree } from '../../../../shared/worktree/types'
import { isDefaultBranchWorkspace } from './default-branch-workspace'
import { revealRepoInProjectFilter, type ProjectFilterRevealState } from './project-filter-reveal'
Expand All @@ -8,6 +9,7 @@ export type AddRepoSkipFinalizationState = ProjectFilterRevealState & {
hideDefaultBranchWorkspace: boolean
showSleepingWorkspaces: boolean
alwaysShowDefaultBranchWorkspace: boolean
repos: readonly Pick<Repo, 'id' | 'kind'>[]
worktreesByRepo: Record<string, Worktree[]>
setActiveRepo: (repoId: string | null) => void
setShowActiveOnly: (value: boolean) => void
Expand All @@ -20,6 +22,7 @@ export function finalizeImportedRepoAfterSkip(
importedRepoId: string
): void {
const importedWorktrees = state.worktreesByRepo[importedRepoId] ?? []
const importedRepo = state.repos.find((repo) => repo.id === importedRepoId)

// Why: Skip means "do not open or create a worktree", not "hide the
// imported project behind sidebar filters so it looks like nothing landed."
Expand All @@ -33,7 +36,7 @@ export function finalizeImportedRepoAfterSkip(
if (
importedWorktrees.length > 0 &&
state.hideDefaultBranchWorkspace &&
importedWorktrees.every((worktree) => isDefaultBranchWorkspace(worktree))
importedWorktrees.every((worktree) => isDefaultBranchWorkspace(worktree, importedRepo))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Exclude archived worktrees from the skip visibility decision.

If an imported folder project has a root and an archived non-main workspace, every returns false. computeVisibleWorktrees removes the archived workspace at Line 99 of src/renderer/src/components/sidebar/visible-worktrees.ts and hides the root. The project therefore disappears after Skip. Check the unarchived imported worktrees, with a nonempty guard, before deciding whether to disable default-workspace hiding.

) {
state.setHideDefaultBranchWorkspace(false)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import { describe, expect, it } from 'vitest'
import { LOCAL_EXECUTION_HOST_ID } from '../../../../shared/execution-host'
import type { Repo } from '../../../../shared/repo-types'
import type { Worktree } from '../../../../shared/worktree/types'
import { isDefaultBranchWorkspace } from './default-branch-workspace'
import { computeVisibleWorktreeIds } from './visible-worktrees'

function makeRepo(id: string, path: string, kind: Repo['kind']): Repo {
return { id, path, displayName: id, badgeColor: '#000', addedAt: 0, kind }
}

function makeRow(repo: Repo, overrides: Partial<Worktree> & { id: string }): Worktree {
return {
repoId: repo.id,
path: repo.path,
head: 'abc123',
branch: 'refs/heads/main',
isBare: false,
isMainWorktree: true,
displayName: repo.id,
comment: '',
linkedIssue: null,
linkedPR: null,
linkedLinearIssue: null,
isArchived: false,
isUnread: false,
isPinned: false,
sortOrder: 0,
lastActivityAt: 0,
...overrides
}
}

// Mirrors mergeFolderWorkspace: every row of a folder project has no head or branch,
// and only the root (id `${repoId}::${path}`) is the main worktree.
function folderProjectRows(repo: Repo): { root: Worktree; instance: Worktree } {
const rootId = `${repo.id}::${repo.path}`
return {
root: makeRow(repo, { id: rootId, head: '', branch: '' }),
instance: makeRow(repo, {
id: `${rootId}::workspace:task-1`,
head: '',
branch: '',
isMainWorktree: false
})
}
}

function visibleWithHideDefault(repos: Repo[], worktrees: Worktree[]): string[] {
const worktreesByRepo: Record<string, Worktree[]> = {}
for (const worktree of worktrees) {
;(worktreesByRepo[worktree.repoId] ??= []).push(worktree)
}
return computeVisibleWorktreeIds(
worktreesByRepo,
worktrees.map((worktree) => worktree.id),
{
filterRepoIds: [],
showSleepingWorkspaces: true,
tabsByWorktree: {},
ptyIdsByTabId: {},
browserTabsByWorktree: {},
worktreeIdsWithLiveAgent: new Set(),
hideDefaultBranchWorkspace: true,
hideAutomationGeneratedWorkspaces: false,
hideCliCreatedWorkspaces: false,
hideDetachedHeadWorkspaces: false,
hideWorkspacesFromOtherDevices: false,
pairedDeviceIdsByEnvironment: new Map(),
repoMap: new Map(repos.map((repo) => [repo.id, repo])),
workspaceHostScope: 'all',
defaultHostId: LOCAL_EXECUTION_HOST_ID,
worktreeLineageById: {}
}
)
}

describe('"Hide default branch" on folder projects', () => {
it('hides the root of a non-git folder project and keeps its other workspaces', () => {
const repo = makeRepo('notes', '/Users/me/notes', 'folder')
const { root, instance } = folderProjectRows(repo)

expect(isDefaultBranchWorkspace(root, repo)).toBe(true)
expect(isDefaultBranchWorkspace(instance, repo)).toBe(false)
expect(visibleWithHideDefault([repo], [root, instance])).toEqual([instance.id])
})

it('hides the root of a folder project added from a git subdirectory', () => {
const repo = makeRepo('app', '/Users/me/monorepo/packages/app', 'folder')
const { root, instance } = folderProjectRows(repo)

expect(visibleWithHideDefault([repo], [root, instance])).toEqual([instance.id])
})

it('keeps an empty-branch git main visible: detached HEAD, or an SSH row synthesized offline', () => {
const repo = makeRepo('repo', '/code/repo', 'git')
const remoteRepo = makeRepo('remote', '/srv/remote', 'git')
const detached = makeRow(repo, { id: 'repo::/code/repo', branch: '' })
const sshOffline = makeRow(remoteRepo, { id: 'remote::/srv/remote', branch: '', head: '' })

expect(isDefaultBranchWorkspace(detached, repo)).toBe(false)
expect(isDefaultBranchWorkspace(sshOffline, remoteRepo)).toBe(false)
expect(visibleWithHideDefault([repo, remoteRepo], [detached, sshOffline])).toEqual([
detached.id,
sshOffline.id
])
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function visibleOptions(overrides: Partial<VisibleOptions> = {}): VisibleOptions

describe('#8873 default-branch workspace under "Hide sleeping"', () => {
it('is genuinely the default-branch row the "Hide default branch" toggle targets', () => {
expect(isDefaultBranchWorkspace(makeDefaultBranchWorktree())).toBe(true)
expect(isDefaultBranchWorkspace(makeDefaultBranchWorktree(), repoMap.get('repo1'))).toBe(true)
})

it('stays in the sidebar when it is sleeping and "Hide sleeping" is on', () => {
Expand Down Expand Up @@ -154,16 +154,14 @@ describe('the "Hide sleeping" exemption for project entry-point rows', () => {
})

it('keeps a sleeping folder workspace, which has no sibling row to fall back to', () => {
// Folder-mode projects are main worktrees with an empty branch/head, so the
// default-branch predicate rejects them; sweeping them drops the whole project.
// Folder-mode projects are main worktrees with an empty branch/head; sweeping
// them drops the whole project.
const folder: Worktree = {
...makeDefaultBranchWorktree(),
id: 'wt-folder',
branch: '',
head: ''
}
expect(isDefaultBranchWorkspace(folder)).toBe(false)

expect(visible([folder], { alwaysShowDefaultBranchWorkspace: true })).toEqual([folder.id])
})

Expand Down
18 changes: 12 additions & 6 deletions src/renderer/src/components/sidebar/default-branch-workspace.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import { isFolderRepo } from '../../../../shared/repo-kind'
import type { Repo } from '../../../../shared/repo-types'
import type { Worktree } from '../../../../shared/worktree/types'

/** Keeps provisioned roots visible because they are the recipe-created workspace, not a source-repo row. */
export function isDefaultBranchWorkspace(worktree: Worktree): boolean {
return (
worktree.isMainWorktree &&
worktree.branch.trim() !== '' &&
worktree.ephemeralVmCheckoutMode !== 'provisioned-root'
)
export function isDefaultBranchWorkspace(
worktree: Worktree,
repo: Pick<Repo, 'kind'> | undefined
): boolean {
if (!worktree.isMainWorktree || worktree.ephemeralVmCheckoutMode === 'provisioned-root') {
return false
}
// Why: a folder project's root is its default workspace but has no branch; on a git repo an
// empty branch means detached HEAD or an offline SSH row, which stay visible.
return worktree.branch.trim() !== '' || (repo !== undefined && isFolderRepo(repo))
}
20 changes: 15 additions & 5 deletions src/renderer/src/components/sidebar/sidebar-filter-state.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {
import { isDefaultBranchWorkspace } from './default-branch-workspace'
import type { Worktree } from '../../../../shared/worktree/types'

const gitRepo = { kind: 'git' } as const

function makeWorktree(id: string, repoId = 'repo1'): Worktree {
return {
id,
Expand Down Expand Up @@ -50,26 +52,34 @@ describe('isDefaultBranchWorkspace', () => {
it('returns true for a branch-backed main worktree', () => {
const main = makeWorktree('main')
main.isMainWorktree = true
expect(isDefaultBranchWorkspace(main)).toBe(true)
expect(isDefaultBranchWorkspace(main, gitRepo)).toBe(true)
})

it('returns false for an empty-branch git main (detached HEAD or offline SSH row)', () => {
const detached = makeWorktree('detached')
detached.isMainWorktree = true
detached.branch = ''
expect(isDefaultBranchWorkspace(detached, gitRepo)).toBe(false)
})

it('returns false for folder-mode main worktrees (empty branch)', () => {
it('returns true for a folder project root, which has no branch', () => {
const folder = makeWorktree('folder')
folder.isMainWorktree = true
folder.branch = ''
expect(isDefaultBranchWorkspace(folder)).toBe(false)
folder.head = ''
expect(isDefaultBranchWorkspace(folder, { kind: 'folder' })).toBe(true)
})

it('returns false for non-main worktrees even on the default branch', () => {
const feature = makeWorktree('feature')
expect(isDefaultBranchWorkspace(feature)).toBe(false)
expect(isDefaultBranchWorkspace(feature, gitRepo)).toBe(false)
})

it('keeps a provisioned root visible as the recipe-created workspace', () => {
const provisionedRoot = makeWorktree('provisioned-root')
provisionedRoot.isMainWorktree = true
provisionedRoot.ephemeralVmCheckoutMode = 'provisioned-root'
expect(isDefaultBranchWorkspace(provisionedRoot)).toBe(false)
expect(isDefaultBranchWorkspace(provisionedRoot, gitRepo)).toBe(false)
})
})

Expand Down
14 changes: 7 additions & 7 deletions src/renderer/src/components/sidebar/visible-worktrees.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,18 +389,18 @@ describe('computeVisibleWorktreeIds', () => {
expect(result).toEqual([feature.id])
})

it('keeps folder-mode main worktrees visible when default branch workspaces are hidden', () => {
const folder = makeWorktree('folder')
folder.isMainWorktree = true
folder.branch = ''
it('keeps an empty-branch git main visible when default branch workspaces are hidden', () => {
const detached = makeWorktree('detached')
detached.isMainWorktree = true
detached.branch = ''

const result = computeVisibleWorktreeIds(
{ repo1: [folder] },
[folder.id],
{ repo1: [detached] },
[detached.id],
visibleOptions({ hideDefaultBranchWorkspace: true })
)

expect(result).toEqual([folder.id])
expect(result).toEqual([detached.id])
})

it('filters worktrees to a selected SSH host scope', () => {
Expand Down
10 changes: 5 additions & 5 deletions src/renderer/src/components/sidebar/visible-worktrees.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ import { getWorktreeHostIdentity } from '../../../../shared/worktree/host-qualif
* Whether the "Hide sleeping" sweep must keep this row (#8873).
*
* Why isMainWorktree and not isDefaultBranchWorkspace: the project's primary
* checkout is the repo's only guaranteed entry point. Folder workspaces and
* detached-HEAD mains fail the default-branch predicate yet often have no
* sibling row at all, so sweeping them drops the entire project out of the
* sidebar, Cmd+J and the board with no way back except changing a filter.
* checkout is the repo's only guaranteed entry point. Detached-HEAD and offline
* SSH mains fail the default-branch predicate yet often have no sibling row at
* all, so sweeping them drops the entire project out of the sidebar, Cmd+J and
* the board with no way back except changing a filter.
*
* Why shared: the sidebar pipeline and the jump palette both apply this, and a
* second copy is how the two surfaces drift.
Expand Down Expand Up @@ -109,7 +109,7 @@ export function computeVisibleWorktrees(
}

if (opts.hideDefaultBranchWorkspace) {
all = all.filter((w) => !isDefaultBranchWorkspace(w))
all = all.filter((w) => !isDefaultBranchWorkspace(w, opts.repoMap.get(w.repoId)))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

#!/bin/bash
# Inspect folder-row creation and the lineage rules used by the visibility pass.
rg -n -C 3 'mergeFolderWorkspace|parentWorktreeId|worktreeLineageById' src/renderer/src/components/sidebar -g '*.ts'
rg -n -C 4 'getLineageAncestorIndex|getLineageRenderInfo|addVisibleLineageAncestors' src/renderer/src/components/sidebar/visible-worktrees.ts

Repository: stablyai/orca

Length of output: 41412


🏁 Script executed:

#!/bin/bash
set -e
printf '%s\n' '--- visible-worktrees.ts ---'
sed -n '80,225p' src/renderer/src/components/sidebar/visible-worktrees.ts
printf '%s\n' '--- lineage projection ---'
sed -n '1,180p' src/renderer/src/components/sidebar/worktree-lineage-projection.ts
printf '%s\n' '--- folder workspace symbols ---'
rg -n -C 5 'mergeFolderWorkspace|FolderWorkspace|folderWorkspace|isEligibleWorktreeParent|parent eligibility' src/renderer/src -g '*.ts' -g '*.tsx' | head -n 320

Repository: stablyai/orca

Length of output: 41658


🏁 Script executed:

set -e
printf '%s\n' '--- visible-worktrees.ts ---'
sed -n '80,225p' src/renderer/src/components/sidebar/visible-worktrees.ts
printf '%s\n' '--- worktree-lineage-projection.ts ---'
sed -n '1,180p' src/renderer/src/components/sidebar/worktree-lineage-projection.ts
printf '%s\n' '--- folder and eligibility symbols ---'
rg -n -C 5 'mergeFolderWorkspace|FolderWorkspace|folderWorkspace|isEligibleWorktreeParent|parent eligibility' src/renderer/src -g '*.ts' -g '*.tsx' | head -n 320

Repository: stablyai/orca

Length of output: 42077


🏁 Script executed:

set -e
rg -l 'function isEligibleWorktreeParent|const isEligibleWorktreeParent|isEligibleWorktreeParent\s*=' src
rg -l 'mergeFolderWorkspace' src
rg -n -C 12 'isEligibleWorktreeParent|mergeFolderWorkspace' src/renderer/src/components/sidebar src/renderer/src -g '*.ts' -g '*.tsx' | head -n 240

Repository: stablyai/orca

Length of output: 26177


🏁 Script executed:

set -e
printf '%s\n' '--- worktree-parent-candidates.ts ---'
sed -n '1,145p' src/renderer/src/components/sidebar/worktree-parent-candidates.ts
printf '%s\n' '--- resolved lineage contract ---'
rg -n -C 8 'isValidResolvedWorktreeLineageEdge' src/shared src/renderer/src -g '*.ts' | head -n 180
printf '%s\n' '--- folder workspace catalog ---'
rg -n -C 12 'mergeFolderWorkspace|isMainWorktree|rootId|folderWorkspace' src/main/ipc/worktrees/listing/folder-workspace-catalog.ts

Repository: stablyai/orca

Length of output: 22433


🏁 Script executed:

set -e
printf '%s\n' '--- worktree-parent-candidates.ts ---'
sed -n '1,145p' src/renderer/src/components/sidebar/worktree-parent-candidates.ts
printf '%s\n' '--- resolved lineage helper ---'
rg -n -C 12 'isValidResolvedWorktreeLineageEdge' src/shared src/renderer/src -g '*.ts'
printf '%s\n' '--- folder catalog implementation ---'
rg -n -C 18 'mergeFolderWorkspace|isMainWorktree|rootId' src/main/ipc/worktrees/listing/folder-workspace-catalog.ts

Repository: stablyai/orca

Length of output: 29160


🏁 Script executed:

set -e
printf '%s\n' '--- parent assignment rules ---'
sed -n '1,180p' src/renderer/src/components/sidebar/worktree-parent-eligibility.ts
printf '%s\n' '--- folder workspace model ---'
rg -n -C 20 'export function mergeFolderWorkspace|getFolderWorkspaceRootId|isMainWorktree' src/main/ipc/worktrees/folder-workspace-model.ts src/main/ipc/worktrees -g '*.ts'

Repository: stablyai/orca

Length of output: 41532


Keep hidden folder roots out of lineage injection.

A folder workspace instance can use its folder root as a valid lineage parent. When hideDefaultBranchWorkspace is enabled, line 112 removes that root, but addVisibleLineageAncestors can add it back through the valid lineage edge. Apply the default-branch exclusion to injected ancestors. Continue traversing excluded parents so other required ancestors remain visible.

}

if (opts.hideAutomationGeneratedWorkspaces) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export function useSidebarWorktreeFilters() {
if (scopedHostIds && !scopedHostIds.includes(targetHostId)) {
state.setVisibleWorkspaceHostIds([...scopedHostIds, targetHostId])
}
if (state.hideDefaultBranchWorkspace && isDefaultBranchWorkspace(worktree)) {
if (state.hideDefaultBranchWorkspace && isDefaultBranchWorkspace(worktree, repo)) {
state.setHideDefaultBranchWorkspace(false)
}
if (state.hideAutomationGeneratedWorkspaces && isAutomationGeneratedWorkspace(worktree)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@ export function useWorktreeJumpPaletteWorktrees({
if (filterPredicate && !filterPredicate.matchesWorktree(worktree)) {
return false
}
if (hideDefaultBranchWorkspace && isDefaultBranchWorkspace(worktree)) {
if (
hideDefaultBranchWorkspace &&
isDefaultBranchWorkspace(worktree, repoMap.get(worktree.repoId))
) {
return false
}
if (hideAutomationGeneratedWorkspaces && isAutomationGeneratedWorkspace(worktree)) {
Expand Down Expand Up @@ -143,6 +146,7 @@ export function useWorktreeJumpPaletteWorktrees({
hideWorkspacesFromOtherDevices,
pairedDeviceIdsByEnvironment,
ptyIdsByTabId,
repoMap,
showSleepingWorkspaces,
tabsByWorktree,
worktreeIdsWithLiveAgent,
Expand Down
Loading