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

11.1 KB
Raw Blame

Plan — CyberCity timeline scrubber (playback mode) — issue #967

Context

Follow-up to #877. The snapshot-capture pipeline shipped (PR #966): the City records a compact state frame every ~5 min to a rolling capped store, readable via GET /api/city/snapshots. This issue is the scrubber slice — the 3D HUD that replays that history: a playback mode on /city where dragging a timeline drives the scene from a past frame instead of live data, with buildings appearing/disappearing via construction/ teardown animations and recoloring on status change (roadmap 3.6).

Scope decided with the user:

  • Landmark data: playback drives everything the snapshot can feed (buildings, agent assignments, counts/HUD, health tower, backup vault, task queue, federation, character). Landmarks the snapshot can't feed (memory district, goal monuments, jira, activity heatmap, productivity) keep their live data, visually static during scrub — the scrubber HUD notes which readouts are time-accurate vs. live.
  • Animations: buildings scale-in from 0 on appear (construction), scale-out to 0 on disappear (teardown), and recolor with a brief transition on status change.
  • Control: full transport — draggable timeline, play/pause, speed (1×/2×/4×), ←/→ step, Esc exit. Mirrors the existing photo-mode overlay pattern.

This completes roadmap 3.6 and closes #967.

Approach

Mirror the photoMode structure in CyberCity.jsx (an established "special mode" with a toggle, keyboard handling, and an overlay rendered alongside CityHud). In playback mode the page substitutes a derived snapshot frame for the live props it passes to CityScene, leaving the live data hook untouched. Buildings gain a small scale-animation layer keyed off a per-app transition signal. The snapshot series is fetched once via a new client API wrapper.

New files

  • client/src/services/apiCity.js — wrappers over the shipped endpoints: getCitySnapshots({ since, limit, silent }) → GET /api/city/snapshots, getCitySnapshotConfig(opts) → GET /api/city/snapshots/config, captureCitySnapshot(opts) → POST /api/city/snapshots/capture. Use the request() helper from apiCore.js with an options param (silent-capable), per the services convention. Maintenance rule: re-export from client/src/services/api.js barrel + add a row to client/src/services/README.md (enforced by the services barrel test).

  • client/src/hooks/useCityPlayback.js — owns playback state + transport, so CyberCity.jsx stays lean. Returns { active, enter, exit, snapshots, frameIndex, currentFrame, setFrameIndex, playing, togglePlay, speed, cycleSpeed, loading, frameTimestamps }. Fetches the series on enter() via apiCity.getCitySnapshots({ limit: <cap> }) (reuse useAutoRefetch for the fetch + last-good semantics, or a one-shot fetch in enter). Auto-advance uses a setInterval driven by speed, guarded by a mountedRef + cleared on pause/exit/unmount (per CLAUDE.md deferred-work rule). useCityPlayback.js → barrel + README row in client/src/hooks/ (enforced).

  • client/src/lib/cityPlaybackFrame.js — pure helper mergeFrameIntoCityProps(frame, live) that maps a snapshot frame onto the prop shape CityScene consumes:

    • apps: take each frame.apps[] {id,name,status}, look up the live app by id to recover render-only fields (processes, repoPath, type, archived), and override overallStatus with the frame's status. Apps absent from the frame are dropped (they'll teardown-animate out); apps present in the frame but not live render from the compact fields with sane defaults. Honor frame.apps === null (source failed) → fall back to live apps, not an empty city.
    • agentMap: rebuild from frame.assignments[] ({agentId, appId, status}) as Map<appId, { app, agents: [{agentId, status}] }>. null assignments → empty map.
    • cosStatus/backupStatus/counts-derived HUD values/character/health: map from frame.cos, frame.backup, frame.counts, frame.character, frame.health. A null field means "unavailable at capture" → pass null/omit so the component shows its empty state, never a fabricated zero.
    • Returns ONLY the snapshot-backed props; the page spreads these over the live ones, so unfed landmark props (memoryGraph, goals, jira, activityCalendar, productivityData) pass through live untouched (the "freeze at live" decision).
    • Pure + unit-tested → client/src/lib/ barrel + README row (enforced).
  • client/src/components/city/CityPlaybackOverlay.jsx — the transport HUD, mirroring CityPhotoOverlay.jsx's bottom control bar. A bottom strip with: play/pause button, speed cycle (1×/2×/4×), a range-input timeline slider bound to frameIndex, ←/→ step buttons, the current frame's timestamp (formatDateTime) + timeAgo, a small legend noting which readouts are historical vs. live (frozen), and an [ EXIT ] button. Uses the same font-pixel / cyan token styling. active prop gates render (like the photo overlay).

Modified files

  • client/src/pages/CyberCity.jsx — add playback alongside photoMode:

    • const playback = useCityPlayback();
    • Compute the scene props once: when playback.active && playback.currentFrame, derive mergeFrameIntoCityProps(currentFrame, liveProps) and spread over the live values passed to CityScene; otherwise pass live as today. Pass a playbackFrame/transitionSignal so the scene/buildings can animate (see below).
    • Render {!photoMode && !playback.active && <CityHud … onEnterPlayback={playback.enter} />} and <CityPlaybackOverlay active={playback.active} … /> next to CityPhotoOverlay.
    • Keyboard handler mirroring photo mode (Esc exit, Space play/pause, ←/→ step) bound only while playback.active, ignoring INPUT/TEXTAREA.
    • Photo mode and playback are mutually exclusive (entering one exits the other).
  • client/src/components/city/CityHud.jsx — add an entry button in the existing bottom-left control stack (next to the photo-mode button), onEnterPlayback prop, e.g. "⟲ HISTORY". Gate it out when no snapshots exist yet (optional: always show; overlay shows an empty-state).

  • client/src/components/city/Building.jsx — add the construction/teardown + recolor animation layer on the existing outer <group> (it already runs a useFrame):

    • Track a mountScaleRef that lerps group.scale 0→1 on mount (construction) using the existing clock-driven useFrame (damp toward target). This makes any newly-appearing building rise in during scrub, with no per-frame React churn.
    • Teardown: a building leaving the apps array unmounts immediately in React today. To animate out, the cluster must keep it mounted briefly — handle teardown in BuildingCluster.jsx (below) by retaining "exiting" apps for one animation beat with a transitionState: 'exiting' prop; Building lerps scale→0 then signals removal.
    • Status recolor: getBuildingColor is currently computed once; lerp the body/edge material color toward the new status color when app.overallStatus changes (damp in useFrame), rather than snapping. Keep it cheap — reuse THREE.MathUtils.damp/Color.lerp.
  • client/src/components/city/BuildingCluster.jsx — own the enter/exit lifecycle so teardown can animate: track previous app id set; when an app id disappears between frames, keep rendering its Borough with transitionState='exiting' for one beat (a short timer or an onExited callback from Building), then drop it. New ids render with transitionState='entering'. This is the only place that needs the diff; Borough just forwards the flag to Building. Keep keyed by app.id so React reuse still holds.

Reuse (don't re-implement)

  • request (client/src/services/apiCore.js) — API wrappers; { silent: true } to suppress toasts.
  • useAutoRefetch (client/src/hooks/useAutoRefetch.js) — series fetch with last-good semantics.
  • formatDateTime / formatClockTime / timeAgo (client/src/utils/formatters.js) — timeline labels.
  • Photo-mode structure in CyberCity.jsx + CityPhotoOverlay.jsx — the overlay/keyboard template.
  • cityDayMix, getBuildingColor, getBuildingHeight, getAccentColor (cityConstants.js) — reuse for recolor lerp targets.
  • The dimmed/isProximity per-app prop-forwarding path (BuildingCluster→Borough→Building) — the exact seam for the new transitionState prop.

Animation strategy note (kept contained)

All animation rides the existing useFrame clock loop in Building.jsx — no new animation library, no React re-render per frame. Scrubbing changes the apps array (React diff handles enter/recolor); teardown is the one case needing a retain-for-one-beat in the cluster. Scene stays on frameloop='always' so the slider feels live (photo mode's 'demand' freeze does NOT apply here).

Migration / compat / changelog obligations

  • No NAV_COMMANDS entry — playback lives inside the existing /city route (no new page), per the issue. (Confirmed: photo mode added none either.)
  • No server change, no migration — read-only consumer of the shipped GET /api/city/snapshots. Honor schemaVersion on each frame: if frame.schemaVersion !== SNAPSHOT_SCHEMA_VERSION, skip/ flag that frame in the overlay rather than mis-rendering (forward-compat for a future bump).
  • Barrel + README — every new apiCity.js / useCityPlayback.js / cityPlaybackFrame.js gets its barrel re-export + README row (server/client barrel tests enforce this; boot/test fails loudly otherwise).
  • Changelog — one user-facing entry under [issue-967] in .changelog/NEXT.md.

Verification

  1. Unit tests:
    • client/src/lib/cityPlaybackFrame.test.js — frame→props mapping: status override, agentMap rebuild from assignments, null-field fallthrough (failed source → live, not fabricated 0), apps added/removed between frames, schemaVersion mismatch handling.
    • client/src/services/api.test.* / hooks test — apiCity wrappers hit the right paths with since/limit; useCityPlayback transport (enter loads series, step clamps at ends, play advances + pauses, exit clears the timer).
  2. Suite: cd client && npm test (Vitest/jsdom) green; cd server && npm test still green (no server change, but the barrel/README enforcement tests run there too — confirm clean). npm run build --prefix client succeeds (lint + bundle).
  3. Manual end-to-end: start the app, open /city, click "⟲ HISTORY". Confirm: the slider scrubs through frames; buildings appear/teardown and recolor as status changes between frames; play/pause auto-advances at the selected speed; ←/→ step; Esc exits back to live; frozen landmarks are labeled as live. Seed history quickly by lowering intervalMinutes (or POST /api/city/snapshots/capture a few times) so there are several frames to scrub.
  4. Review: /simplify, then the claude+codex dual-review loop (per the --review-with flag), converge to mutual CLEAN before merge.