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: make the goal tile able to move and stop the media tile overclaiming (#2676)
[._.]/ Adam Eivy8ad1bf0a52be
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex b72c25ebe0..004c906690 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -53,7 +53,7 @@- `[issue-2673]` **Your Character level is now your age.** The Character's level is reframed as life experience — `level = floor(age in years)`, derived on read from your canonical birth date instead of being ground out of XP thresholds (JIRA tickets + CoS tasks). XP survives as a cumulative stat but no longer drives level, and the CyberCity HUD badge now shows the age-based level with a progress bar toward your next birthday (a friendly "set birth date" prompt when no birth date is set yet). Existing character records keep loading unchanged, and the derived level is excluded from cross-machine sync so peers never fight over a stale value.- `[issue-2729]` The Character page loads faster the more you've written. Your Wordsmith skill used to be scored by loading every universe you own (plus their entire render history) and rebuilding every Writers Room work with all its drafts, just to count them — so the page got slower with each world and story you added. It now counts them directly in the database, leaving the score itself unchanged.-- `[issue-2676]` **Your Character sheet now shows a Metrics grid of your real activity.** Six tiles — POST practice streak, health-logging streak, records created, memories captured, media rendered, and goal follow-through — read straight off the stats each domain already keeps, so the sheet reads like a profile of what you actually do rather than a dice game. They're derived fresh on every page load (never stored, never synced between your machines, and no new activity tracking was added), and they cost nothing extra: the tiles share the same reads that already score your skills. A stat that can't be read says "Unavailable" and a goal follow-through with nothing resolved yet says so plainly — neither is ever passed off as a zero.+- `[issue-2676]` **Your Character sheet now shows a Metrics grid of your real activity.** Six tiles — POST practice streak, health-logging streak, records created, memories captured, media assets, and goal completion — read straight off the stats each domain already keeps, so the sheet reads like a profile of what you actually do rather than a dice game. They're derived fresh on every page load (never stored, never synced between your machines, and no new activity tracking was added), and they cost nothing extra: the tiles share the same reads that already score your skills. A stat that can't be read says "Unavailable", and a goal completion rate with no goals filed yet says so plainly — neither is ever passed off as a zero.## Creative Commissionsdiff --git a/client/src/pages/CharacterSheet.metrics.test.jsx b/client/src/pages/CharacterSheet.metrics.test.jsxindex 5172fee9ee..598d89ebe2 100644--- a/client/src/pages/CharacterSheet.metrics.test.jsx+++ b/client/src/pages/CharacterSheet.metrics.test.jsx@@ -126,12 +126,12 @@ describe('MetricsCard rendering', () => {it('renders a not-applicable ratio with its own emptyLabel, not 0% and not "Unavailable"', async () => {const grid = await renderWithMetrics([metric({- id: 'goalCompletionRate', label: 'Goal Follow-Through', unit: 'percent',- value: null, notApplicable: true, emptyLabel: 'No goals resolved yet',+ id: 'goalCompletionRate', label: 'Goal Completion', unit: 'percent',+ value: null, notApplicable: true, emptyLabel: 'No goals filed yet',}),]);- expect(grid.getByText('No goals resolved yet')).toBeInTheDocument();+ expect(grid.getByText('No goals filed yet')).toBeInTheDocument();expect(grid.getByText('—')).toBeInTheDocument();expect(grid.queryByText('0%')).not.toBeInTheDocument();// Distinct from the unavailable state — the two say different things.@@ -147,7 +147,7 @@ describe('MetricsCard rendering', () => {// One unreachable domain must not take the grid down with it.const grid = await renderWithMetrics([metric({ value: null, unavailable: true }),- metric({ id: 'mediaRendered', label: 'Media Rendered', value: 31, hint: 'Images & videos in the media index' }),+ metric({ id: 'mediaAssets', label: 'Media Assets', value: 31, hint: 'Images & videos in your media library' }),]);expect(grid.getByText('Unavailable')).toBeInTheDocument();diff --git a/server/services/characterMetrics.js b/server/services/characterMetrics.jsindex 84216a2eaa..f07a3bbf4a 100644--- a/server/services/characterMetrics.js+++ b/server/services/characterMetrics.js@@ -10,6 +10,15 @@* free to fall. The two are complementary readings of one signal set: `mentalist` says "you* have practiced 200 times"; `postStreakDays` says "you have practiced 4 days running".*+ * **A tile must be able to MOVE, and must claim only what its signal carries.** Two traps+ * worth naming, because both produced a plausible-looking tile that was really a constant or+ * an overclaim (caught in review):+ * - A ratio whose denominator no UI can populate is a decorative constant — see+ * `goalCompletionRate`, where an `abandoned` status exists in the enum but nothing writes.+ * - A tally is only as specific as its rows — see `mediaAssets`, an unfiltered count over an+ * index that deliberately holds downloads and uploads, so it cannot be called "rendered".+ * When picking a new signal, check what the UI actually records before naming the tile.+ ** **No new reads.** Every `compute()` composes signals from `characterSignals.js`, the same* context the skills fan out over — so the six tiles below add ZERO stat reads to* `GET /api/character`, and a domain the user has never touched still costs nothing extra.@@ -26,8 +35,8 @@* and a real 0 is a legitimate answer ("no memories yet")* - not applicable — `{ value: null, notApplicable: true }`: the metric is a ratio* with an empty denominator. There is no honest number, and 0 is- * NOT it — "0% follow-through" is a damning claim to make about- * someone who has simply never resolved a goal.+ * NOT it — "0% of your goals are done" is a lie to tell someone who+ * has never filed one.* - unavailable — `{ value: null, unavailable: true }`: the stat could not be read.* Collapsing any of these into a fake 0 is the exact lie the sentinels exist to prevent.* Both non-value states are distinct SYMBOLS rather than in-band `null`s, so a getter that@@ -111,35 +120,52 @@ export const METRICS = [compute: async (read) => read('memoryCount'),},{- id: 'mediaRendered',- label: 'Media Rendered',+ id: 'mediaAssets',+ label: 'Media Assets',unit: 'count',- hint: 'Images & videos in the media index',+ hint: 'Images & videos in your media library',+ // Deliberately "assets in your library", NOT "media you rendered". `countAssets()` is an+ // unfiltered COUNT(*) over `media_assets`, which by design holds every on-disk asset:+ // `reconcileMediaAssets()` upserts everything in the gallery at boot (uploads included),+ // and `videoDownload.js` routes downloads through the same index on purpose. Labelling it+ // "Media Rendered" would claim a provenance the row doesn't carry.+ //+ // Caveat this tile inherits from the index (NOT introduced here — the `auteur` skill reads+ // the same source): deletes don't decrement it until the next boot, because `removeAsset`+ // has no production callers yet ("delete hook, future slice" per mediaAssetIndex/db.js).+ // So the count can read high between a delete and a restart. Tracked as a follow-up; the+ // honest label keeps the tile from overstating what it measures in the meantime (#2738).compute: async (read) => read('assetCount'),},{id: 'goalCompletionRate',- label: 'Goal Follow-Through',+ label: 'Goal Completion',unit: 'percent',- hint: 'Of goals you resolved, the share you finished',- emptyLabel: 'No goals resolved yet',- // Denominator is RESOLVED goals (completed + abandoned), not all goals. Counting `active`- // goals as incomplete would make the rate drop the moment you file an ambitious goal and- // punish having work in flight — it would measure caution, not follow-through. With no- // resolved goals the ratio is undefined, which is NOT 0% (see the header's three states).+ hint: 'Share of your goals that are done',+ emptyLabel: 'No goals filed yet',+ // Denominator is ALL goals, not just "resolved" (completed + abandoned) ones.+ //+ // The resolved-only denominator is tempting — it reads as follow-through and doesn't+ // penalize having ambitious work in flight — but it CANNOT MOVE on this install. The+ // Goals UI (`client/src/components/digital-twin/tabs/GoalsTab.jsx`) offers exactly two+ // terminal actions: Complete (writes `status: 'completed'`) and Delete (drops the record+ // outright). Nothing in the client ever writes `status: 'abandoned'` — it exists in+ // `goalStatusEnum` and is honored by the API and the CyberCity monuments, but no UI+ // produces it. So `abandoned` is always 0, `resolved === completed`, and the tile would+ // read a self-congratulatory constant 100% forever after the first completion.+ //+ // A metric that cannot vary is worse than one with a debatable denominator, so this+ // measures what the UI actually records: of the goals you have filed, how many are done.+ // If an explicit "abandon" outcome ever ships, an abandoned goal naturally lands in the+ // denominator here without a change.compute: async (read) => {const { goals } = await read('goals');- // One pass, and the denominator is derived from the SAME predicate set as the numerator- // — so adding a third resolved status can't leave the two out of sync.- let completed = 0;- let resolved = 0;- for (const g of goals || []) {- if (g?.status !== 'completed' && g?.status !== 'abandoned') continue;- resolved += 1;- if (g.status === 'completed') completed += 1;- }- if (resolved === 0) return METRIC_NOT_APPLICABLE;- return Math.round((completed / resolved) * 100);+ const all = goals || [];+ // No goals at all → there is no rate. That is NOT 0% (see the header's three states):+ // "0% of your goals are done" is a lie to tell someone who has never filed one.+ if (all.length === 0) return METRIC_NOT_APPLICABLE;+ const completed = all.filter((g) => g?.status === 'completed').length;+ return Math.round((completed / all.length) * 100);},},];diff --git a/server/services/characterMetrics.test.js b/server/services/characterMetrics.test.jsindex 85dd5e5d49..6eb954cede 100644--- a/server/services/characterMetrics.test.js+++ b/server/services/characterMetrics.test.js@@ -205,58 +205,71 @@ describe('getCharacterMetrics — populated domains', () => {});});- it('derives memoryCount and mediaRendered from their tallies', async () => {+ it('derives memoryCount and mediaAssets from their tallies', async () => {stats.memories = 250;stats.assets = 31;const metrics = await getCharacterMetrics();expect(byId(metrics, 'memoryCount').value).toBe(250);- expect(byId(metrics, 'mediaRendered').value).toBe(31);+ expect(byId(metrics, 'mediaAssets').value).toBe(31);+ });++ it('does not claim the media tile counts only RENDERED media', async () => {+ // countAssets() is an unfiltered COUNT(*) over an index that deliberately holds downloads+ // and reconciled gallery uploads too, so the tile must not promise provenance it lacks.+ const media = byId(await getCharacterMetrics(), 'mediaAssets');+ expect(media.label).not.toMatch(/render/i);+ expect(media.hint).not.toMatch(/render/i);});});describe('getCharacterMetrics — goalCompletionRate', () => {- it('is the completed share of RESOLVED goals', async () => {- stats.goals = { goals: [goal('completed'), goal('completed'), goal('completed'), goal('abandoned')] };+ it('is the completed share of ALL goals', async () => {+ stats.goals = { goals: [goal('completed'), goal('completed'), goal('active'), goal('active')] };expect(byId(await getCharacterMetrics(), 'goalCompletionRate')).toMatchObject({- value: 75, unit: 'percent', unavailable: false, notApplicable: false,+ value: 50, unit: 'percent', unavailable: false, notApplicable: false,});});- it('does not count ACTIVE goals against you', async () => {- // Filing an ambitious goal must not drop your follow-through — the rate would then measure- // caution rather than follow-through.- stats.goals = { goals: [goal('completed'), goal('active'), goal('active'), goal('active')] };+ it('MOVES as goals are filed and completed — the reason the denominator is all goals', async () => {+ // Load-bearing: a resolved-only denominator (completed + abandoned) would be pinned at+ // 100% forever, because the Goals UI only ever writes `completed` (its other terminal+ // action deletes the record) and nothing in the client writes `abandoned`.+ stats.goals = { goals: [goal('completed')] };expect(byId(await getCharacterMetrics(), 'goalCompletionRate').value).toBe(100);- });- it('reports NOT APPLICABLE — never 0% — when no goal has been resolved', async () => {- // The load-bearing case for the third state: "0% follow-through" is a damning claim to- // make about someone who has simply never finished OR abandoned a goal.- stats.goals = { goals: [goal('active'), goal('active')] };- const rate = byId(await getCharacterMetrics(), 'goalCompletionRate');- expect(rate).toMatchObject({ value: null, unavailable: false, notApplicable: true });- expect(rate.value).not.toBe(0);- expect(rate.emptyLabel).toBeTruthy();+ stats.goals = { goals: [goal('completed'), goal('active'), goal('active'), goal('active')] };+ expect(byId(await getCharacterMetrics(), 'goalCompletionRate').value).toBe(25);});- it('reports not-applicable on a brand new install with no goals at all', async () => {- stats.goals = { goals: [] };- expect(byId(await getCharacterMetrics(), 'goalCompletionRate')).toMatchObject({- value: null, notApplicable: true, unavailable: false,- });+ it('counts an abandoned goal in the denominator if one ever appears', async () => {+ // `abandoned` is in goalStatusEnum and the API honors it; no UI writes it today. When one+ // does, it should read as an un-completed goal, not vanish from the rate.+ stats.goals = { goals: [goal('completed'), goal('abandoned')] };+ expect(byId(await getCharacterMetrics(), 'goalCompletionRate').value).toBe(50);});- it('reports a REAL 0% when every resolved goal was abandoned', async () => {- // The mirror of the case above: here 0 is the honest answer and must NOT be suppressed.- stats.goals = { goals: [goal('abandoned'), goal('abandoned')] };+ it('reports a REAL 0% when goals exist but none are done', async () => {+ // Here 0 is the honest answer and must NOT be suppressed into the not-applicable state.+ stats.goals = { goals: [goal('active'), goal('active')] };expect(byId(await getCharacterMetrics(), 'goalCompletionRate')).toMatchObject({value: 0, notApplicable: false, unavailable: false,});});+ it('reports NOT APPLICABLE — never 0% — on an install with no goals at all', async () => {+ // The load-bearing case for the third state: "0% of your goals are done" is a lie to tell+ // someone who has never filed one.+ stats.goals = { goals: [] };+ const rate = byId(await getCharacterMetrics(), 'goalCompletionRate');+ expect(rate).toMatchObject({ value: null, unavailable: false, notApplicable: true });+ expect(rate.value).not.toBe(0);+ expect(rate.emptyLabel).toBeTruthy();+ });+it('tolerates a goals payload with missing/odd entries', async () => {+ // Odd entries still count as un-completed goals rather than crashing.stats.goals = { goals: [null, undefined, {}, goal('completed')] };- expect(byId(await getCharacterMetrics(), 'goalCompletionRate').value).toBe(100);+ expect(byId(await getCharacterMetrics(), 'goalCompletionRate').value).toBe(25);});it('treats a goals payload with no goals array as not-applicable, not a crash', async () => {