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
feat([issue-919]): add client/src/utils/ barrel + README catalog with drift guard
[._.]/ Adam Eivy013f7224f90c
diff --git a/CLAUDE.md b/CLAUDE.mdindex 469cbdb6b1..af2541e535 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -191,7 +191,7 @@ If a close match exists, **extend it or use it**. Only add a new module when no### Maintenance rule (WHEN adding a public module)-Any new file added to `server/lib/`, `client/src/lib/`, `client/src/hooks/`, or a new `apiX.js` in `client/src/services/` **MUST**:+Any new file added to `server/lib/`, `client/src/lib/`, `client/src/hooks/`, `client/src/utils/`, or a new `apiX.js` in `client/src/services/` **MUST**:1. Be re-exported from the same-directory `index.js` barrel (or, for `services/`, from `api.js`).2. Get a one-line row in the same-directory `README.md`.diff --git a/client/src/utils/README.md b/client/src/utils/README.mdnew file mode 100644index 0000000000..b21326fa66--- /dev/null+++ b/client/src/utils/README.md@@ -0,0 +1,90 @@+# client/src/utils/ — pure formatting & compute helpers++Pure, side-effect-free helpers used by pages, components, and hooks: formatters, time math,+small functional utilities, and the CyberCity scene-compute functions. **Before writing a+helper here, grep this catalog first** — many domain patterns already have one. When you add+a new module, add it to `index.js` AND add a row here.++State + lifecycle hooks live in `client/src/hooks/`. Shared client helpers with prompt/canon+logic (and server mirrors) live in `client/src/lib/`. HTTP/socket clients live in+`client/src/services/`.++## Discovery rule++```+grep -i "what you want to do" client/src/utils/README.md+```++---++## Formatting & time++| Module | Purpose |+|---|---|+| `formatters` | Date/time/duration/byte/word formatters (`formatBytes`, `timeAgo`, `formatTimecode`, `formatDurationMs`, `formatDateShort`, `parseTimeoutMs`, …) plus timeout-input bounds and `getAppName`. Do not re-define formatters inside components. |+| `cronHelpers` | Cron preset list, `isCronExpression` detection, and `describeCron` human-readable rendering. |+| `timeWindow` | Time-of-day window math (`isInTimeWindow`, `timeStringToMinutes`) and morning-layout auto-switch helpers (`pickActiveLayoutId`, `recordManualLayoutPick`). |++## General pure helpers++| Module | Purpose |+|---|---|+| `coalesce` | Trailing-edge coalescer: wraps a function so rapid calls collapse into one deferred invocation. |+| `easing` | `smoothstep` interpolation easing curve. |+| `hashString` | Deterministic string → 32-bit hash (stable colors, keys, seeds). |+| `urlNormalize` | `isUrl` detection and `normalizeUrl` (optional git/`requireDot` modes). |+| `platform` | `isMac` detection and `modKey` (⌘/Ctrl) for keyboard-shortcut display. |+| `navWorkingSet` | Recent/pinned nav persistence in localStorage (`recordVisit`, `togglePin`, `isPinned`). |+| `providers` | AI-provider type predicates and helpers (`isCliProvider`, `isApiProvider`, `filterSelectableModels`, `getProviderTimeout`, configured-default sentinels). |++## Module loading / resilience++| Module | Purpose |+|---|---|+| `lazyWithReload` | `React.lazy` wrapper that auto-reloads once on a stale-chunk import error (post-deploy hash mismatch). |+| `staleChunkReload` | Detects stale dynamic-import chunk errors (`isStaleChunkError`) and triggers a one-time reload guard. |++## File handling++| Module | Purpose |+|---|---|+| `fileUpload` | Screenshot/attachment upload helpers: base64 read plus `processScreenshotUploads` / `processAttachmentUploads` and their single-file variants. |++## CyberCity — character & avatar++| Module | Purpose |+|---|---|+| `characterXp` | Avatar XP/level math: `levelFromXP`, `computeXpView`, `diffXp`, and the XP threshold table. |++## CyberCity — scene compute helpers++Pure `compute*` functions that turn PortOS state into 3D-scene descriptors for the City+districts. One module per district/feature; each exports a `compute<Feature>` entry point plus+its tunable constants and placement helpers.++| Module | Purpose |+|---|---|+| `cityActivityHeatmap` | Calendar activity → per-tile heat levels (`computeActivityHeatmap`, `tileLevel`). |+| `cityAgentMotion` | Agent orbit/trail motion math (`computeAgentOrbit`, `computeAgentTrailPoints`, trail colors). |+| `cityAiCore` | AI-ops core: model tiers, beam thickness, and `computeAiCore` / `computeAiCoreBeams` from live AI status events. |+| `cityArtifacts` | Earned-artifact milestones (level/goal/streak) → placed artifact descriptors (`computeArtifacts`). |+| `cityBackupVault` | Backup-vault health/alerting state and color (`computeBackupVault`, `vaultHealth`). |+| `cityChronotype` | Chronotype energy curve by hour → brightness/tempo modifiers (`computeChronotypeEnergy`). |+| `cityDistrictLayout` | Shared district layout math: auto-columns, grid placement, tallying, metric→height scaling. |+| `cityEasterEggs` | Unlockable easter eggs from context (date/character/goals) → placements (`computeEasterEggs`). |+| `cityFederation` | Sync-peer reachability horizon: status color/opacity, bridge state, peer placement (`computeFederationHorizon`). |+| `cityFilter` | Status-filter definitions and app-filtering result (`computeFilterResult`). |+| `cityFlowLines` | Inter-building flow-line connections between active/agent nodes (`computeFlowConnections`). |+| `cityGoalMonuments` | Goal monuments & forest: stall detection, milestone segments, placement (`computeGoalMonuments`, `computeGoalForest`). |+| `cityHealthTower` | Health-metric tower segments from the latest health entry (`computeHealthTower`). |+| `cityJiraDistrict` | Jira ticket district: ticket state, sprint structures, placement (`computeJiraDistrict`). |+| `cityMemoryDistrict` | Brain-graph memory district: category clustering, bridges, placement (`computeMemoryDistrict`). |+| `cityMiniMap` | Mini-map projection of building positions into 2D bounds (`computeMiniMap`, `projectPoint`). |+| `cityPhotoMode` | Photo-mode camera presets, postcard stats, and screenshot filename (`getPreset`, `cyclePreset`). |+| `cityProductivity` | Productivity monument from streak/velocity tiers (`computeProductivityMonument`). |+| `citySeasonalDecor` | Season/holiday resolution → seasonal decoration placements (`computeSeasonalDecor`). |+| `citySoundscape` | Ambient soundscape: mood/energy classification and chord selection (`computeSoundscape`). |+| `cityTaskFlowRiver` | Task-flow river width/speed from backlog & throughput (`computeTaskFlowRiver`). |+| `cityTaskQueue` | Task-queue state/color from status counts (`computeTaskQueue`). |+| `cityTimeline` | Activity-log density bins and timeline buckets (`computeActivityDensity`, `buildTimelineBuckets`). |+| `cityVoiceMarker` | Voice-agent marker state/color/label from voice status (`computeVoiceMarker`). |diff --git a/client/src/utils/index.js b/client/src/utils/index.jsnew file mode 100644index 0000000000..c2262c513c--- /dev/null+++ b/client/src/utils/index.js@@ -0,0 +1,60 @@+// Barrel for client/src/utils/ — discovery surface, not a forced import path.+// See client/src/utils/README.md for the human-readable catalog and+// CLAUDE.md "Module organization" for the maintenance convention.+//+// Every module here exports named (no defaults), so a flat `export * from`+// surfaces each helper under its own name. The barrel exists so helpers are+// discoverable and the drift test (index.test.js) can enforce that every new+// utils module gets registered here AND documented in the README. Existing+// deep imports (`import { formatBytes } from '../utils/formatters'`) keep+// working — the barrel is for discovery, not to force a re-import.++// === Formatting & time ===+export * from './formatters.js';+export * from './cronHelpers.js';+export * from './timeWindow.js';++// === General pure helpers ===+export * from './coalesce.js';+export * from './easing.js';+export * from './hashString.js';+export * from './urlNormalize.js';+export * from './platform.js';+export * from './navWorkingSet.js';+export * from './providers.js';++// === Module loading / resilience ===+export * from './lazyWithReload.js';+export * from './staleChunkReload.js';++// === File handling ===+export * from './fileUpload.js';++// === CyberCity — character & avatar ===+export * from './characterXp.js';++// === CyberCity — scene compute helpers (one per district / feature) ===+export * from './cityActivityHeatmap.js';+export * from './cityAgentMotion.js';+export * from './cityAiCore.js';+export * from './cityArtifacts.js';+export * from './cityBackupVault.js';+export * from './cityChronotype.js';+export * from './cityDistrictLayout.js';+export * from './cityEasterEggs.js';+export * from './cityFederation.js';+export * from './cityFilter.js';+export * from './cityFlowLines.js';+export * from './cityGoalMonuments.js';+export * from './cityHealthTower.js';+export * from './cityJiraDistrict.js';+export * from './cityMemoryDistrict.js';+export * from './cityMiniMap.js';+export * from './cityPhotoMode.js';+export * from './cityProductivity.js';+export * from './citySeasonalDecor.js';+export * from './citySoundscape.js';+export * from './cityTaskFlowRiver.js';+export * from './cityTaskQueue.js';+export * from './cityTimeline.js';+export * from './cityVoiceMarker.js';diff --git a/client/src/utils/index.test.js b/client/src/utils/index.test.jsnew file mode 100644index 0000000000..9880e3db65--- /dev/null+++ b/client/src/utils/index.test.js@@ -0,0 +1,64 @@+import { describe, it, expect } from 'vitest';+import { readdirSync, readFileSync } from 'node:fs';+import { fileURLToPath } from 'node:url';+import { dirname, join } from 'node:path';+import * as barrel from './index.js';++const HERE = dirname(fileURLToPath(import.meta.url));+const BARREL_SRC = readFileSync(join(HERE, 'index.js'), 'utf8');+const README_SRC = readFileSync(join(HERE, 'README.md'), 'utf8');++const sourceFiles = readdirSync(HERE).filter(+ (f) => f.endsWith('.js') && !f.endsWith('.test.js') && f !== 'index.js',+);++// Collect every top-level named export per module so we can prove no two flat+// `export * from` modules collide (a collision would silently shadow under the+// barrel — see CLAUDE.md "Name collisions").+const EXPORT_RE = /^export\s+(?:const|let|function|async function|class)\s+([A-Za-z0-9_$]+)/gm;+const exportsByName = new Map();+for (const f of sourceFiles) {+ const src = readFileSync(join(HERE, f), 'utf8');+ for (const m of src.matchAll(EXPORT_RE)) {+ const name = m[1];+ if (!exportsByName.has(name)) exportsByName.set(name, []);+ exportsByName.get(name).push(f);+ }+}++describe('client/src/utils/ barrel', () => {+ it('resolves every re-export', () => {+ expect(Object.keys(barrel).length).toBeGreaterThan(0);+ });++ it('exposes a representative sample of helpers', () => {+ expect(typeof barrel.formatBytes).toBe('function');+ expect(typeof barrel.timeAgo).toBe('function');+ expect(typeof barrel.describeCron).toBe('function');+ expect(typeof barrel.hashString).toBe('function');+ expect(typeof barrel.normalizeUrl).toBe('function');+ expect(typeof barrel.levelFromXP).toBe('function');+ expect(typeof barrel.computeAiCore).toBe('function');+ expect(typeof barrel.computeGoalMonuments).toBe('function');+ });++ it('re-exports every non-test .js file from index.js', () => {+ for (const f of sourceFiles) {+ expect(BARREL_SRC, `missing barrel re-export for ${f}`).toContain(`'./${f}'`);+ }+ });++ it('every non-test .js file has a README row', () => {+ for (const f of sourceFiles) {+ const base = f.replace(/\.js$/, '');+ expect(README_SRC, `missing README entry for ${f}`).toContain(base);+ }+ });++ it('no two flat export-* modules share an identifier', () => {+ const collisions = [...exportsByName.entries()]+ .filter(([, files]) => files.length > 1)+ .map(([name, files]) => `${name}: ${files.join(', ')}`);+ expect(collisions, `colliding exports would silently shadow under the barrel:\n${collisions.join('\n')}`).toEqual([]);+ });+});