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

address review: fix expand/collapse propagation, stale edge geometry, dashed tag edges, deterministic layout, add goal tree tests

Adam Eivy7e04108f9def
diff --git a/client/src/components/goals/GoalsListView.jsx b/client/src/components/goals/GoalsListView.jsx
index 86977b6755..930bdd3662 100644
--- a/client/src/components/goals/GoalsListView.jsx
+++ b/client/src/components/goals/GoalsListView.jsx
@@ -11,9 +11,10 @@ function urgencyIndicator(urgency) {
return <div className={`w-2 h-2 rounded-full ${color}`} title={`${Math.round(urgency * 100)}% urgency`} />;
}
-function GoalRow({ goal, depth, expanded, onToggle, onSelect, selectedId, allGoals, onAddChild }) {
+function GoalRow({ goal, depth, expandedIds, onToggle, onSelect, selectedId, allGoals, onAddChild }) {
const cat = CATEGORY_CONFIG[goal.category] || CATEGORY_CONFIG.mastery;
const CatIcon = cat.icon;
+ const expanded = expandedIds.has(goal.id);
const hasChildren = goal.children?.length > 0;
const isSelected = selectedId === goal.id;
@@ -79,7 +80,7 @@ function GoalRow({ goal, depth, expanded, onToggle, onSelect, selectedId, allGoa
key={child.id}
goal={child}
depth={depth + 1}
- expanded={expanded}
+ expandedIds={expandedIds}
onToggle={onToggle}
onSelect={onSelect}
selectedId={selectedId}
@@ -248,7 +249,7 @@ export default function GoalsListView({ data, onRefresh }) {
key={root.id}
goal={root}
depth={0}
- expanded={expandedIds.has(root.id)}
+ expandedIds={expandedIds}
onToggle={toggleExpand}
onSelect={handleSelect}
selectedId={selectedGoal?.id}
diff --git a/client/src/components/goals/GoalsTreeView.jsx b/client/src/components/goals/GoalsTreeView.jsx
index efa483c063..d79335a23a 100644
--- a/client/src/components/goals/GoalsTreeView.jsx
+++ b/client/src/components/goals/GoalsTreeView.jsx
@@ -13,44 +13,60 @@ const EDGE_COLORS = {
};
function GoalEdges({ edges, selectedId }) {
- const geoRef = useRef();
+ // Split edges into parent and tag groups for different materials
+ const parentEdges = useMemo(() => edges.filter(e => e.type === 'parent'), [edges]);
+ const tagEdges = useMemo(() => edges.filter(e => e.type === 'tag'), [edges]);
- useEffect(() => {
- const geo = geoRef.current;
- if (!geo || !edges.length) return;
-
- const count = edges.length;
- const positions = new Float32Array(count * 6);
- const colors = new Float32Array(count * 6);
- const tmpColor = new THREE.Color();
-
- edges.forEach((e, i) => {
- const a = e.sourceNode, b = e.targetNode;
- const off = i * 6;
- positions[off] = a.x; positions[off + 1] = a.y; positions[off + 2] = a.z;
- positions[off + 3] = b.x; positions[off + 4] = b.y; positions[off + 5] = b.z;
-
- const dimmed = selectedId && e.source !== selectedId && e.target !== selectedId;
- tmpColor.set(EDGE_COLORS[e.type] || '#6b7280');
- const intensity = dimmed ? 0.06 : (e.type === 'parent' ? 0.5 : 0.2);
- colors[off] = tmpColor.r * intensity;
- colors[off + 1] = tmpColor.g * intensity;
- colors[off + 2] = tmpColor.b * intensity;
- colors[off + 3] = tmpColor.r * intensity;
- colors[off + 4] = tmpColor.g * intensity;
- colors[off + 5] = tmpColor.b * intensity;
- });
+ const parentGeoRef = useRef();
+ const tagGeoRef = useRef();
- geo.setAttribute('position', new THREE.BufferAttribute(positions, 3));
- geo.setAttribute('color', new THREE.BufferAttribute(colors, 3));
- geo.computeBoundingSphere();
- }, [edges, selectedId]);
+ useEffect(() => {
+ const setupGeo = (geo, edgeList) => {
+ if (!geo) return;
+ if (!edgeList.length) {
+ geo.setAttribute('position', new THREE.BufferAttribute(new Float32Array(0), 3));
+ geo.setAttribute('color', new THREE.BufferAttribute(new Float32Array(0), 3));
+ geo.computeBoundingSphere();
+ return;
+ }
+ const count = edgeList.length;
+ const positions = new Float32Array(count * 6);
+ const colors = new Float32Array(count * 6);
+ const tmpColor = new THREE.Color();
+ edgeList.forEach((e, i) => {
+ const a = e.sourceNode, b = e.targetNode;
+ const off = i * 6;
+ positions[off] = a.x; positions[off + 1] = a.y; positions[off + 2] = a.z;
+ positions[off + 3] = b.x; positions[off + 4] = b.y; positions[off + 5] = b.z;
+ const dimmed = selectedId && e.source !== selectedId && e.target !== selectedId;
+ tmpColor.set(EDGE_COLORS[e.type] || '#6b7280');
+ const intensity = dimmed ? 0.06 : (e.type === 'parent' ? 0.5 : 0.2);
+ colors[off] = tmpColor.r * intensity;
+ colors[off + 1] = tmpColor.g * intensity;
+ colors[off + 2] = tmpColor.b * intensity;
+ colors[off + 3] = tmpColor.r * intensity;
+ colors[off + 4] = tmpColor.g * intensity;
+ colors[off + 5] = tmpColor.b * intensity;
+ });
+ geo.setAttribute('position', new THREE.BufferAttribute(positions, 3));
+ geo.setAttribute('color', new THREE.BufferAttribute(colors, 3));
+ geo.computeBoundingSphere();
+ };
+ setupGeo(parentGeoRef.current, parentEdges);
+ setupGeo(tagGeoRef.current, tagEdges);
+ }, [parentEdges, tagEdges, selectedId]);
return (
- <lineSegments>
- <bufferGeometry ref={geoRef} />
- <lineBasicMaterial vertexColors />
- </lineSegments>
+ <>
+ <lineSegments>
+ <bufferGeometry ref={parentGeoRef} />
+ <lineBasicMaterial vertexColors />
+ </lineSegments>
+ <lineSegments>
+ <bufferGeometry ref={tagGeoRef} />
+ <lineDashedMaterial vertexColors dashSize={0.5} gapSize={0.3} />
+ </lineSegments>
+ </>
);
}
diff --git a/client/src/components/goals/goalTreeLayout.js b/client/src/components/goals/goalTreeLayout.js
index f6d32ed67a..3a23e2dcf4 100644
--- a/client/src/components/goals/goalTreeLayout.js
+++ b/client/src/components/goals/goalTreeLayout.js
@@ -1,6 +1,20 @@
// Tiered radial layout: lifetime/north-star goals at center, shorter horizons in outer rings
// Sub-goals cluster near their parents
+// Deterministic pseudo-random based on goal id (seeded hash)
+function seededRandom(seed) {
+ let h = 0;
+ for (let i = 0; i < seed.length; i++) {
+ h = Math.imul(31, h) + seed.charCodeAt(i) | 0;
+ }
+ return () => {
+ h = Math.imul(h ^ (h >>> 16), 0x45d9f3b);
+ h = Math.imul(h ^ (h >>> 13), 0x45d9f3b);
+ h = (h ^ (h >>> 16)) >>> 0;
+ return h / 4294967296;
+ };
+}
+
const HORIZON_RING = {
'lifetime': 0,
'20-year': 1,
@@ -35,6 +49,7 @@ export function layoutGoalNodes(flatGoals) {
const count = goals.length;
goals.forEach((goal, i) => {
+ const rng = seededRandom(goal.id);
const angle = (2 * Math.PI * i) / Math.max(count, 1);
// If goal has parent that's already positioned, cluster near it
const parent = goal.parentId ? positioned.get(goal.parentId) : null;
@@ -47,16 +62,16 @@ export function layoutGoalNodes(flatGoals) {
const childAngle = parentAngle + (i - count / 2) * spread;
x = Math.cos(childAngle) * radius;
z = Math.sin(childAngle) * radius;
- y = parent.y + (Math.random() - 0.5) * Y_SPREAD;
+ y = parent.y + (rng() - 0.5) * Y_SPREAD;
} else if (radius === 0) {
// Center ring - small spread
- x = (Math.random() - 0.5) * 3;
- z = (Math.random() - 0.5) * 3;
- y = (Math.random() - 0.5) * Y_SPREAD;
+ x = (rng() - 0.5) * 3;
+ z = (rng() - 0.5) * 3;
+ y = (rng() - 0.5) * Y_SPREAD;
} else {
x = Math.cos(angle) * radius;
z = Math.sin(angle) * radius;
- y = (Math.random() - 0.5) * Y_SPREAD;
+ y = (rng() - 0.5) * Y_SPREAD;
}
positioned.set(goal.id, {
diff --git a/server/services/identity.test.js b/server/services/identity.test.js
index 7cfd994e4a..f23210346d 100644
--- a/server/services/identity.test.js
+++ b/server/services/identity.test.js
@@ -1288,4 +1288,133 @@ describe('Integration: Goal CRUD', () => {
expect(await completeMilestone(goal.id, 'nonexistent')).toBeNull();
expect(await completeMilestone('nonexistent', 'fake')).toBeNull();
});
+
+ it('should create a goal with parentId', async () => {
+ const parent = await createGoal({ title: 'Parent Goal' });
+ const child = await createGoal({ title: 'Child Goal', parentId: parent.id });
+
+ expect(child.parentId).toBe(parent.id);
+ });
+
+ it('should create a goal with tags', async () => {
+ const goal = await createGoal({ title: 'Tagged Goal', tags: ['fitness', 'health'] });
+
+ expect(goal.tags).toEqual(['fitness', 'health']);
+ });
+
+ it('should update tags on a goal', async () => {
+ const goal = await createGoal({ title: 'Tag Test' });
+ const updated = await updateGoal(goal.id, { tags: ['career', 'growth'] });
+
+ expect(updated.tags).toEqual(['career', 'growth']);
+ });
+
+ it('should reject update with invalid parentId', async () => {
+ const goal = await createGoal({ title: 'Orphan' });
+
+ await expect(updateGoal(goal.id, { parentId: 'nonexistent' }))
+ .rejects.toMatchObject({ code: 'INVALID_PARENT' });
+ });
+
+ it('should reject update that creates a cycle', async () => {
+ const a = await createGoal({ title: 'A' });
+ const b = await createGoal({ title: 'B', parentId: a.id });
+ const c = await createGoal({ title: 'C', parentId: b.id });
+
+ await expect(updateGoal(a.id, { parentId: c.id }))
+ .rejects.toMatchObject({ code: 'CYCLE_DETECTED' });
+ });
+
+ it('should reparent children when deleting a middle node', async () => {
+ const grandparent = await createGoal({ title: 'Grandparent' });
+ const parent = await createGoal({ title: 'Parent', parentId: grandparent.id });
+ const child = await createGoal({ title: 'Child', parentId: parent.id });
+
+ expect(await deleteGoal(parent.id)).toBe(true);
+
+ const goals = await getGoals();
+ const updatedChild = goals.goals.find(g => g.id === child.id);
+ expect(updatedChild.parentId).toBe(grandparent.id);
+ });
+
+ it('should promote children to root when deleting a root parent', async () => {
+ const root = await createGoal({ title: 'Root' });
+ const child = await createGoal({ title: 'Child', parentId: root.id });
+
+ expect(await deleteGoal(root.id)).toBe(true);
+
+ const goals = await getGoals();
+ const updatedChild = goals.goals.find(g => g.id === child.id);
+ expect(updatedChild.parentId).toBeNull();
+ });
+});
+
+describe('Integration: Goal Tree', () => {
+ let createGoal, getGoalsTree;
+
+ beforeEach(async () => {
+ vi.resetModules();
+
+ vi.doMock('fs/promises', () => {
+ const store = {};
+ return {
+ readFile: vi.fn(async (path) => {
+ if (store[path]) return store[path];
+ throw new Error('ENOENT');
+ }),
+ writeFile: vi.fn(async (path, data) => {
+ store[path] = data;
+ }),
+ mkdir: vi.fn(async () => {})
+ };
+ });
+
+ vi.doMock('./genome.js', () => ({
+ getGenomeSummary: vi.fn(async () => ({
+ uploaded: true, markerCount: 0, uploadedAt: '2025-01-01T00:00:00.000Z', savedMarkers: {}
+ }))
+ }));
+
+ vi.doMock('./taste-questionnaire.js', () => ({
+ getTasteProfile: vi.fn(async () => ({
+ completedCount: 0, totalSections: 5, overallPercentage: 0, lastSessionAt: null
+ }))
+ }));
+
+ const mod = await import('./identity.js');
+ createGoal = mod.createGoal;
+ getGoalsTree = mod.getGoalsTree;
+ });
+
+ it('should return correct tree structure with roots and children', async () => {
+ const parent = await createGoal({ title: 'Parent' });
+ const child = await createGoal({ title: 'Child', parentId: parent.id });
+
+ const tree = await getGoalsTree();
+
+ expect(tree.roots).toHaveLength(1);
+ expect(tree.roots[0].id).toBe(parent.id);
+ expect(tree.roots[0].children).toHaveLength(1);
+ expect(tree.roots[0].children[0].id).toBe(child.id);
+ expect(tree.flat).toHaveLength(2);
+ });
+
+ it('should build tagIndex mapping tags to goal ids', async () => {
+ const g1 = await createGoal({ title: 'G1', tags: ['fitness', 'health'] });
+ const g2 = await createGoal({ title: 'G2', tags: ['fitness'] });
+
+ const tree = await getGoalsTree();
+
+ expect(tree.tagIndex.fitness).toContain(g1.id);
+ expect(tree.tagIndex.fitness).toContain(g2.id);
+ expect(tree.tagIndex.health).toEqual([g1.id]);
+ });
+
+ it('should return empty roots for no goals', async () => {
+ const tree = await getGoalsTree();
+
+ expect(tree.roots).toHaveLength(0);
+ expect(tree.flat).toHaveLength(0);
+ expect(tree.tagIndex).toEqual({});
+ });
});