diff --git a/packages/kilo-vscode/tests/unit/navigate.test.ts b/packages/kilo-vscode/tests/unit/navigate.test.ts index 2a3e8df437..3f23206ec6 100644 --- a/packages/kilo-vscode/tests/unit/navigate.test.ts +++ b/packages/kilo-vscode/tests/unit/navigate.test.ts @@ -457,6 +457,32 @@ describe("buildProjectNavOrder", () => { ]) }) + it("matches raw ungrouped order when sections are present", () => { + const order = buildProjectNavOrder([ + project({ + id: "A", + expanded: true, + worktrees: [ + { id: "aw1", groupId: "g" }, + { id: "aw2" }, + { id: "aw3", groupId: "g" }, + { id: "aw4", sectionId: "s1" }, + ], + worktreeOrder: ["aw1", "aw2", "aw3", "s1", "aw4"], + sections: [{ id: "s1", collapsed: false }], + unassigned: [], + }), + ]) + + expect(order.map((e) => e.id)).toEqual([ + localNavId("A"), + worktreeNavId("A", "aw1"), + worktreeNavId("A", "aw2"), + worktreeNavId("A", "aw3"), + worktreeNavId("A", "aw4"), + ]) + }) + it("excludes unassigned sessions when the sessions section is collapsed", () => { const order = buildProjectNavOrder([ project({ diff --git a/packages/kilo-vscode/webview-ui/agent-manager/navigate.ts b/packages/kilo-vscode/webview-ui/agent-manager/navigate.ts index bcae169082..8596666cf9 100644 --- a/packages/kilo-vscode/webview-ui/agent-manager/navigate.ts +++ b/packages/kilo-vscode/webview-ui/agent-manager/navigate.ts @@ -191,13 +191,17 @@ export function buildProjectNavOrder(projects: ProjectNavInput[]): NavEntry[] { order.push({ id: localNavId(pid), target: { projectId: pid, kind: "local" } }) const worktrees = sortWorktrees(p.worktrees, p.worktreeOrder ?? []) const rank = new Map((p.worktreeOrder ?? []).map((id, index) => [id, index] as const)) + const ungrouped = worktrees.filter((w) => !w.sectionId) + if (p.sections.length > 0) { + ungrouped.sort( + (a, b) => (rank.get(a.id) ?? Number.MAX_SAFE_INTEGER) - (rank.get(b.id) ?? Number.MAX_SAFE_INTEGER), + ) + } const secs = [...p.sections].sort( (a, b) => (rank.get(a.id) ?? Number.MAX_SAFE_INTEGER) - (rank.get(b.id) ?? Number.MAX_SAFE_INTEGER), ) - for (const w of worktrees) { - if (!w.sectionId) { - order.push({ id: worktreeNavId(pid, w.id), target: { projectId: pid, kind: "worktree", worktreeId: w.id } }) - } + for (const w of ungrouped) { + order.push({ id: worktreeNavId(pid, w.id), target: { projectId: pid, kind: "worktree", worktreeId: w.id } }) } for (const sec of secs) { if (sec.collapsed) continue