Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix([issue-819]): detect goal hierarchy before the root cap and count overflowed sub-trees

[._.]/ Adam Eivy769dcc8679c0
diff --git a/client/src/utils/cityGoalMonuments.js b/client/src/utils/cityGoalMonuments.js
index 0a2f997876..cc049ed2b4 100644
--- a/client/src/utils/cityGoalMonuments.js
+++ b/client/src/utils/cityGoalMonuments.js
@@ -285,7 +285,11 @@ export function computeGoalForest(goals, now = Date.now()) {
.sort(compareByStatusThenId);
const visibleRoots = rankedRoots.slice(0, FOREST.maxRoots);
- const rootOverflow = Math.max(0, rankedRoots.length - visibleRoots.length);
+ // Root overflow counts the folded-away root trees AND everything nested under them, so a
+ // child-bearing root past the cap isn't silently undercounted (it's `roots + descendants`).
+ const rootOverflow = rankedRoots
+ .slice(FOREST.maxRoots)
+ .reduce((sum, { node }) => sum + 1 + countDescendants(node), 0);
const clusters = visibleRoots.map(({ node }, rootIndex) => {
// Spread root clusters along x, centered on FOREST.base.
@@ -300,7 +304,11 @@ export function computeGoalForest(goals, now = Date.now()) {
attachMilestones(spire, node.goal, spire.height);
const childNodes = node.children.slice(0, FOREST.maxChildren);
- const childOverflow = Math.max(0, node.children.length - childNodes.length);
+ // Child overflow counts the folded-away children plus their own sub-trees, mirroring
+ // the descendantCount surfaced on displayed children — nothing nested vanishes silently.
+ const childOverflow = node.children
+ .slice(FOREST.maxChildren)
+ .reduce((sum, child) => sum + 1 + countDescendants(child), 0);
// Children ring around the spire. A single child sits directly in front; multiple
// children spread evenly across a forward-facing arc so links don't cross the spire.
@@ -317,10 +325,11 @@ export function computeGoalForest(goals, now = Date.now()) {
return m;
});
- // Links: from each child's apex up to the root spire's apex.
+ // Links: from each child's apex up to the root spire's apex. Towers rise from a 0.4
+ // plinth, so the true top sits at 0.4 + height — match that so links join the tips.
const links = children.map((child) => ({
- from: [child.position[0], child.height, child.position[2]],
- to: [spire.position[0], spire.height, spire.position[2]],
+ from: [child.position[0], 0.4 + child.height, child.position[2]],
+ to: [spire.position[0], 0.4 + spire.height, spire.position[2]],
childId: child.id,
}));
@@ -336,6 +345,9 @@ export function computeGoalForest(goals, now = Date.now()) {
// A forest is only worth showing when at least one root actually has children;
// otherwise it's just the flat row with extra spacing. The component uses this to
// decide whether to render the hierarchy view vs. fall back to the flat row.
- hasHierarchy: clusters.some((c) => c.children.length > 0),
+ // Derived from ALL ranked roots (pre-cap) so a child-bearing root that overflows past
+ // FOREST.maxRoots still flips the district into the forest layout instead of the flat
+ // row — otherwise its sub-tree would be invisible AND uncounted.
+ hasHierarchy: rankedRoots.some(({ node }) => node.children.length > 0),
};
}
diff --git a/client/src/utils/cityGoalMonuments.test.js b/client/src/utils/cityGoalMonuments.test.js
index 2c34de3ff6..d54861e474 100644
--- a/client/src/utils/cityGoalMonuments.test.js
+++ b/client/src/utils/cityGoalMonuments.test.js
@@ -363,7 +363,8 @@ describe('computeGoalForest', () => {
// Children carry a parentId back-reference and one link each to the spire apex.
expect(cluster.children.every((c) => c.parentId === 'apex')).toBe(true);
expect(cluster.links).toHaveLength(2);
- expect(cluster.links[0].to).toEqual([cluster.spire.position[0], cluster.spire.height, cluster.spire.position[2]]);
+ // Links join the tower tops, which sit a 0.4 plinth above the height baseline.
+ expect(cluster.links[0].to).toEqual([cluster.spire.position[0], 0.4 + cluster.spire.height, cluster.spire.position[2]]);
});
it('centers a single root cluster on FOREST.base', () => {
@@ -372,7 +373,7 @@ describe('computeGoalForest', () => {
expect(vm.clusters[0].spire.position[2]).toBe(FOREST.base[2]);
});
- it('caps root clusters and reports the overflow', () => {
+ it('caps root clusters and reports the overflow (folded roots + their descendants)', () => {
const goals = [];
for (let i = 0; i < FOREST.maxRoots + 2; i++) {
goals.push(goal({ id: `r${i}`, parentId: null }));
@@ -380,10 +381,29 @@ describe('computeGoalForest', () => {
}
const vm = computeGoalForest(goals, NOW);
expect(vm.clusters).toHaveLength(FOREST.maxRoots);
- expect(vm.rootOverflow).toBe(2);
+ // 2 overflowed roots, each with 1 child → 2 * (1 + 1) = 4 goals folded away.
+ expect(vm.rootOverflow).toBe(4);
expect(vm.rootCount).toBe(FOREST.maxRoots + 2);
});
+ it('flips to the forest view when only an OVERFLOWED root has children', () => {
+ // First maxRoots roots are flat leaves; the next root (which overflows the cap) is the
+ // only one with a child. hasHierarchy must be derived pre-cap so the forest still shows.
+ // Status ties sort by id ascending, so the flat roots use ids that sort BEFORE the deep
+ // one ('aflat*' < 'zdeep-root') to guarantee the child-bearing root lands past the cap.
+ const goals = [];
+ for (let i = 0; i < FOREST.maxRoots; i++) goals.push(goal({ id: `aflat${i}`, parentId: null }));
+ goals.push(goal({ id: 'zdeep-root', parentId: null }));
+ goals.push(goal({ id: 'zdeep-child', parentId: 'zdeep-root' }));
+ const vm = computeGoalForest(goals, NOW);
+ // The child-bearing root is beyond FOREST.maxRoots, so it is NOT in the visible clusters…
+ expect(vm.clusters.every((c) => c.children.length === 0)).toBe(true);
+ // …yet the district must still pick the forest layout (pre-cap hierarchy detection)…
+ expect(vm.hasHierarchy).toBe(true);
+ // …and the overflowed root + its child are both counted, not silently dropped.
+ expect(vm.rootOverflow).toBe(2);
+ });
+
it('surfaces a descendant count on a child that has its own sub-tree (no silent drop)', () => {
const vm = computeGoalForest([
goal({ id: 'apex', parentId: null }),