From 5920bbf2ec50ec35e02c47476715f479d318fc3f Mon Sep 17 00:00:00 2001 From: Miguel Palhas Date: Mon, 31 Aug 2026 17:53:38 +0100 Subject: [PATCH] fix(maestro): fold the sole root sidebar folder into its own children MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ~ never distinguishes anything from a sibling — nothing else sits beside it — so it showed as its own header even when it immediately branched into multiple real projects. Now it folds into each child instead, at the top only; a real divergence further down still gets its own header. --- web/src/tree.test.ts | 10 ++++++++++ web/src/tree.ts | 9 +++++++++ 2 files changed, 19 insertions(+) diff --git a/web/src/tree.test.ts b/web/src/tree.test.ts index 8a1e40c..e3f9642 100644 --- a/web/src/tree.test.ts +++ b/web/src/tree.test.ts @@ -39,6 +39,16 @@ describe("buildTree", () => { expect(names(root)).toEqual(["~/git/naps62/maestro"]); }); + it("folds the sole root folder into each of its own children when it branches", () => { + const root = buildTree( + [session("a", "/home/n/subvisual/bullish"), session("b", "/home/n/tea/maestro")], + "/home/n", + "", + ) as TreeFolder; + + expect(names(root).sort()).toEqual(["~/subvisual/bullish", "~/tea/maestro"]); + }); + it("stops collapsing where a directory branches", () => { const root = buildTree( [session("a", "/home/n/git/one"), session("b", "/home/n/git/two")], diff --git a/web/src/tree.ts b/web/src/tree.ts index 6f47ef7..b403d94 100644 --- a/web/src/tree.ts +++ b/web/src/tree.ts @@ -59,6 +59,15 @@ export function buildTree(sessions: Session[], home: string | undefined, filter: for (const c of n.children) if (c.kind === "folder") sortRec(c); }; sortRec(root); + // The root's sole child (usually `~`) has no sibling to distinguish it + // from, so it folds into every one of its own children, not just a lone + // one — unlike the chain merge below, and only here at the very top. + if (root.children.length === 1 && root.children[0].kind === "folder") { + const only = root.children[0]; + root.children = only.children.map((c) => + c.kind === "folder" ? { ...c, name: `${only.name}/${c.name}` } : c, + ); + } // Collapse linear directory chains so `~/git.naps.pt/naps62/maestro` reads as // one compact folder rather than four nested ones. root.children = root.children.map((c) => (c.kind === "folder" ? mergeLinear(c) : c));