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
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix([issue-817]): address dual-reviewer findings on river yaw, today accent, throughput window
[._.]/ Adam Eivyd5c74d61809c
diff --git a/client/src/components/city/CityActivityHeatmap.jsx b/client/src/components/city/CityActivityHeatmap.jsxindex 3f54d52b72..3dba7cc91a 100644--- a/client/src/components/city/CityActivityHeatmap.jsx+++ b/client/src/components/city/CityActivityHeatmap.jsx@@ -40,7 +40,7 @@ export default function CityActivityHeatmap({ calendarData, settings }) {<meshkey={tile.key}position={[tile.x, tileHeight / 2, tile.z]}- userData={{ baseIntensity: tile.tasks > 0 ? tile.intensity : 0, phase: tile.x + tile.z }}+ userData={{ baseIntensity: tile.tasks > 0 ? tile.intensity : 0, phase: tile.phase }}><boxGeometry args={[tileSize, tileHeight, tileSize]} /><meshStandardMaterialdiff --git a/client/src/components/city/CityTaskFlowRiver.jsx b/client/src/components/city/CityTaskFlowRiver.jsxindex 2f74604783..a86e8e84cb 100644--- a/client/src/components/city/CityTaskFlowRiver.jsx+++ b/client/src/components/city/CityTaskFlowRiver.jsx@@ -1,7 +1,7 @@import { useMemo, useRef } from 'react';import { useFrame } from '@react-three/fiber';import { computeTaskQueue } from '../../utils/cityTaskQueue';-import { computeTaskFlowRiver } from '../../utils/cityTaskFlowRiver';+import { computeTaskFlowRiver, recentCalendarThroughput } from '../../utils/cityTaskFlowRiver';// CyberCity task-flow river (issue #817): an animated channel running from the task-queue// warehouse to the productivity district, tying queued work to completed throughput. The@@ -13,12 +13,16 @@ import { computeTaskFlowRiver } from '../../utils/cityTaskFlowRiver';export default function CityTaskFlowRiver({ cosTasks, productivityData, calendarData, settings }) {const river = useMemo(() => {const queue = computeTaskQueue(cosTasks);- // Recent throughput: prefer the calendar window total (steady multi-day signal), fall- // back to today's completed count from the quick-summary so the river still flows before- // the calendar fetch lands. Optional chaining tolerates missing/non-object payloads;+ // Recent throughput drives the current speed. Prefer today's completed count from the+ // quick-summary (the freshest "draining now" signal); fall back to a bounded last-7-days+ // total from the calendar so the river still flows before today's count is meaningful.+ // Using the calendar's full 12-week total would pin the river at max speed forever, so we+ // deliberately window it. Optional chaining tolerates missing/non-object payloads, and// computeTaskFlowRiver reads a non-number as zero.- const calendarTotal = calendarData?.summary?.totalTasks;- const throughput = typeof calendarTotal === 'number' ? calendarTotal : productivityData?.today?.completed;+ const todayCompleted = productivityData?.today?.completed;+ const throughput = typeof todayCompleted === 'number'+ ? todayCompleted+ : recentCalendarThroughput(calendarData, 7);return computeTaskFlowRiver(queue, throughput);}, [cosTasks, productivityData, calendarData]);@@ -62,7 +66,10 @@ export default function CityTaskFlowRiver({ cosTasks, productivityData, calendar/></mesh>- {/* Traveling flow nodes — brighter, faster current means more energy moving downstream */}+ {/* Traveling flow nodes — only when there's a live current to depict; on the lowest+ preset (animation off) or an idle/not-draining channel the bed alone stays drawn so+ static glowing boxes never imply movement that isn't happening. */}+ {animate && river.flowing && (<group ref={nodesRef}>{particles.map((p) => (<mesh@@ -80,6 +87,7 @@ export default function CityTaskFlowRiver({ cosTasks, productivityData, calendar</mesh>))}</group>+ )}</group>);}diff --git a/client/src/utils/cityActivityHeatmap.js b/client/src/utils/cityActivityHeatmap.jsindex db3825778f..bbe4f39f64 100644--- a/client/src/utils/cityActivityHeatmap.js+++ b/client/src/utils/cityActivityHeatmap.js@@ -81,14 +81,20 @@ export function computeActivityHeatmap(calendarData) {// Weeks run along x (columns), day-of-week runs along z (front→back rows).x: weekIndex * step,z: dow * step,+ // Animation phase derived from grid indices (not world coords) so the component's+ // shimmer reads as a coherent diagonal wave sweeping across the field rather than+ // near-random per-tile flicker.+ phase: (weekIndex + dow) * 0.18,tasks,level,isToday,- // Empty days sit dark; active days glow green, scaled by level; today gets an accent.- color: tasks === 0 ? EMPTY_COLOR : isToday ? TODAY_COLOR : ACTIVE_COLOR,- // Emissive intensity: empty tiles barely glow; active tiles ramp with level; today- // always reads clearly even on a light day.- intensity: tasks === 0 ? 0.04 : isToday ? Math.max(0.5, 0.25 + level * 0.7) : 0.18 + level * 0.6,+ // Today is always picked out in accent blue, even on a zero-task day — it's a+ // location sentinel, not an activity reading. Otherwise empty days sit dark and+ // active days glow green scaled by level.+ color: isToday ? TODAY_COLOR : tasks === 0 ? EMPTY_COLOR : ACTIVE_COLOR,+ // Emissive intensity: today always reads clearly (legible even at zero tasks); other+ // empty tiles barely glow; active tiles ramp with level.+ intensity: isToday ? Math.max(0.5, 0.25 + level * 0.7) : tasks === 0 ? 0.04 : 0.18 + level * 0.6,});});});diff --git a/client/src/utils/cityActivityHeatmap.test.js b/client/src/utils/cityActivityHeatmap.test.jsindex 8b4e0de849..26dfd5bdc3 100644--- a/client/src/utils/cityActivityHeatmap.test.js+++ b/client/src/utils/cityActivityHeatmap.test.js@@ -100,6 +100,16 @@ describe('computeActivityHeatmap', () => {expect(today.intensity).toBeGreaterThanOrEqual(0.5);});+ it('picks out a zero-task today as accent, not as a dark empty day', () => {+ // todayIndex 0 has 0 tasks — it's still the "you are here" tile, not an empty day.+ const cal = makeCalendar([[0, 3, 0, 0, 0, 0, 0]], { maxTasks: 3, todayIndex: 0 });+ const vm = computeActivityHeatmap(cal);+ const today = vm.tiles.find((t) => t.isToday);+ expect(today.tasks).toBe(0);+ expect(today.color).toBe('#3b82f6'); // accent, NOT the empty #1a2030+ expect(today.intensity).toBeGreaterThanOrEqual(0.5);+ });+it('skips future days in the trailing partial week', () => {const cal = makeCalendar([[1, 0, 0, 0, 0, 0, 0]]);cal.weeks[0][3].isFuture = true;diff --git a/client/src/utils/cityTaskFlowRiver.js b/client/src/utils/cityTaskFlowRiver.jsindex 4056b1a6be..b36b3e0155 100644--- a/client/src/utils/cityTaskFlowRiver.js+++ b/client/src/utils/cityTaskFlowRiver.js@@ -48,6 +48,26 @@ export function speedLevel(throughput, cap = RIVER.throughputCap) {return clamp01(t / c);}+// Sum completed tasks over the most recent `days` calendar days (excluding future days), as a+// bounded "recent drain" signal. The activity calendar's `summary.totalTasks` spans the whole+// 12-week window, so it would pin the river at full speed forever after a few historical+// completions; a trailing window keeps the current honest about *recent* throughput. Returns+// null when there's no usable calendar so the caller can fall back to today's count.+export function recentCalendarThroughput(calendarData, days = 7) {+ const weeks = Array.isArray(calendarData?.weeks) ? calendarData.weeks : null;+ if (!weeks) return null;+ const flat = [];+ for (const week of weeks) {+ if (!Array.isArray(week)) continue;+ for (const day of week) {+ if (day && typeof day === 'object' && !day.isFuture) flat.push(day);+ }+ }+ if (flat.length === 0) return null;+ const window = days > 0 ? flat.slice(-days) : flat;+ return window.reduce((sum, day) => sum + nonNegOrZero(day.tasks), 0);+}+// Euclidean distance on the ground plane (x/z) between the two endpoints.function groundLength(from, to) {const dx = to[0] - from[0];@@ -89,8 +109,12 @@ export function computeTaskFlowRiver(taskQueue, recentThroughput) {: IDLE_COLOR;const length = groundLength(RIVER.from, RIVER.to);- // Rotation about Y so a unit segment laid along +x points from `from` toward `to`.- const angle = Math.atan2(RIVER.to[0] - RIVER.from[0], RIVER.to[2] - RIVER.from[2]);+ // Rotation about +Y so the channel's local +x (its length axis) points from `from` toward+ // `to`. A +Y rotation by θ maps local +x (1,0,0) to world (cosθ, 0, -sinθ); aligning that+ // with the ground-plane direction (dx, dz) gives θ = atan2(-dz, dx).+ const dx = RIVER.to[0] - RIVER.from[0];+ const dz = RIVER.to[2] - RIVER.from[2];+ const angle = Math.atan2(-dz, dx);const center = [(RIVER.from[0] + RIVER.to[0]) / 2,0,diff --git a/client/src/utils/cityTaskFlowRiver.test.js b/client/src/utils/cityTaskFlowRiver.test.jsindex 8aa1ee00a2..7866a16dd5 100644--- a/client/src/utils/cityTaskFlowRiver.test.js+++ b/client/src/utils/cityTaskFlowRiver.test.js@@ -5,6 +5,7 @@ import {RIVER,widthLevel,speedLevel,+ recentCalendarThroughput,computeTaskFlowRiver,} from './cityTaskFlowRiver';@@ -47,6 +48,16 @@ describe('computeTaskFlowRiver', () => {expect(vm.length).toBeCloseTo(Math.sqrt(dx * dx + dz * dz));});+ it('yaws so the channel local +x points from warehouse to monument', () => {+ const vm = computeTaskFlowRiver({ pending: 0 }, 0);+ // A +Y rotation by `angle` maps local +x (1,0,0) to world (cos, 0, -sin); that vector,+ // scaled by length, must reconstruct the warehouse→monument displacement.+ const dirX = Math.cos(vm.angle) * vm.length;+ const dirZ = -Math.sin(vm.angle) * vm.length;+ expect(dirX).toBeCloseTo(MONUMENT.position[0] - TASK_QUEUE.position[0]);+ expect(dirZ).toBeCloseTo(MONUMENT.position[2] - TASK_QUEUE.position[2]);+ });+it('widens with backlog and quickens with throughput', () => {const empty = computeTaskFlowRiver({ pending: 0, inProgress: 0, blocked: 0 }, 0);const busy = computeTaskFlowRiver({ pending: 8, inProgress: 4, blocked: 0 }, 10);@@ -91,6 +102,50 @@ describe('computeTaskFlowRiver', () => {expect(vm.particles.every((p) => p.phase >= 0 && p.phase < 1)).toBe(true);});+});++describe('recentCalendarThroughput', () => {+ const cal = (taskRows) => ({+ weeks: taskRows.map((row) =>+ row.map((tasks, dow) => ({ date: `d${dow}`, dayOfWeek: dow, tasks, isFuture: false }))+ ),+ summary: { totalTasks: taskRows.flat().reduce((s, t) => s + t, 0) },+ });++ it('sums only the most recent N days, excluding future days', () => {+ // 14 days total (two weeks); last 7 days carry 1+2+3 = 6 tasks.+ const data = cal([+ [5, 5, 5, 5, 5, 5, 5],+ [0, 0, 0, 0, 1, 2, 3],+ ]);+ expect(recentCalendarThroughput(data, 7)).toBe(6);+ });++ it('windows away the 12-week-total saturation problem', () => {+ // A big historical total but a quiet recent week reads as low, not pinned high.+ const busyWeeks = Array.from({ length: 12 }, () => [9, 9, 9, 9, 9, 9, 9]);+ busyWeeks.push([0, 0, 0, 0, 0, 0, 0]); // quiet current week+ const data = cal(busyWeeks);+ expect(data.summary.totalTasks).toBe(12 * 7 * 9); // huge historical total+ expect(recentCalendarThroughput(data, 7)).toBe(0); // but the recent window is quiet+ });++ it('skips future days in the trailing window', () => {+ const data = cal([[1, 1, 1, 1, 1, 1, 1]]);+ data.weeks[0][5].isFuture = true;+ data.weeks[0][6].isFuture = true;+ expect(recentCalendarThroughput(data, 7)).toBe(5);+ });++ it('returns null for a missing/empty calendar so the caller can fall back', () => {+ expect(recentCalendarThroughput(null)).toBeNull();+ expect(recentCalendarThroughput({})).toBeNull();+ expect(recentCalendarThroughput({ weeks: [] })).toBeNull();+ expect(recentCalendarThroughput({ weeks: 'oops' })).toBeNull();+ });+});++describe('computeTaskFlowRiver — idle resilience', () => {it('handles missing / non-object inputs as an idle trickle without crashing', () => {for (const badQueue of [null, undefined, 'nope', 42, []]) {for (const badThroughput of [null, undefined, 'nope', -5, NaN]) {