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: reuse journal summaries across Brain graph views
Adam Eivy13b7f8d3a52c
diff --git a/server/services/brainGraph.js b/server/services/brainGraph.jsindex 19af5f429b..8cca12e238 100644--- a/server/services/brainGraph.js+++ b/server/services/brainGraph.js@@ -22,10 +22,9 @@* (issue #3507).*/-import * as brainStorage from './brainStorage.js';import * as memoryBackend from './memoryBackend.js';import { loadBridgeMap, bridgeKey } from './brainMemoryBridge.js';-import { getBrainProjections, journalHasBody } from './brainSearchIndex.js';+import { getBrainProjections } from './brainSearchIndex.js';import { getGoals } from './identity.js';const ENTITY_TYPES = ['people', 'projects', 'ideas', 'admin', 'memories', 'songs', 'threads'];@@ -120,16 +119,16 @@ async function loadNodes() {}// Journals (Daily Log): non-empty dated entries as graph nodes- const journals = await brainStorage.getAll('journals').catch(() => []);+ const journals = await getBrainProjections('journals', { ranked: false }).catch(() => []);for (const entry of journals) {- if (!journalHasBody(entry)) continue;+ if (!entry.hasBody) continue;const date = journalDate(entry);if (!date) continue;nodes.push({id: date,brainType: 'journals',label: date,- summary: entry.content ? entry.content.slice(0, 120) : '',+ summary: entry.summary,tags: [],importance: 0.4});@@ -141,13 +140,9 @@ async function loadNodes() {/*** Lightweight index for the client-side search box — every node, no edges.*- * Deliberately does NOT go through `loadNodes()`: that reads the full body of- * every entity record and Daily Log entry only to throw the summaries and tags- * away here. Instead it reads `brainSearchIndex`'s cached field projections, so- * the endpoint costs an in-memory scan after the first call and never parses a- * record body it doesn't render. Node set, labels, and order are identical to- * the `loadNodes()` derivation — the label/skip rules are the shared helpers- * above, and `ranked: false` keeps each store's natural order.+ * Reads the same cached projections as `loadNodes()`, retaining only the+ * search fields. Node set, labels, and order are identical — the label/skip+ * rules are shared above, and `ranked: false` keeps each store's natural order.** Goals still come from `getGoals()`: identity keeps them in ONE file, so* there is no per-record walk to avoid.diff --git a/server/services/brainGraph.test.js b/server/services/brainGraph.test.jsindex 72c5f71bb3..2f4d28ec05 100644--- a/server/services/brainGraph.test.js+++ b/server/services/brainGraph.test.js@@ -125,14 +125,33 @@ describe('getBrainGraphSearchIndex', () => {});it('reads each store once and serves repeat requests from the projections', async () => {- onlyType('people', [{ id: 'p1', name: 'A' }]);+ let journals = [{ id: '2026-01-01', content: 'x'.repeat(5000) },+ { id: '2026-01-02', content: '', segments: [{ text: 'Voice note' }] },+ { id: '2026-01-03', content: '', segments: [] }];+ brainStorage.getAll.mockImplementation(async type => type === 'journals' ? journals : []);- await getBrainGraphSearchIndex();+ const [index, overview] = await Promise.all([getBrainGraphSearchIndex(), getBrainGraphOverview()]);// 7 entity types (incl. songs and threads) + journals, one scan each.expect(brainStorage.getAll).toHaveBeenCalledTimes(8);+ expect(index.nodes.map(node => node.id)).toEqual(['2026-01-01', '2026-01-02']);+ expect(overview.nodes.map(node => node.summary)).toEqual(['x'.repeat(120), '']);- await getBrainGraphSearchIndex();+ const focused = await getBrainGraphNeighborhood({ focusId: '2026-01-01' });+ expect(focused.nodes[0].summary).toBe('x'.repeat(120));expect(brainStorage.getAll).toHaveBeenCalledTimes(8);++ journals = [{ id: '2026-01-01', content: 'Edited journal' }];+ // Daily Log writes and peer applies use the silent-write invalidation.+ brainStorage.brainEvents.emit('record:changed', { type: 'journals', id: '2026-01-01' });+ const edited = await getBrainGraphOverview();+ expect(edited.nodes.map(node => node.summary)).toEqual(['Edited journal']);+ expect(brainStorage.getAll).toHaveBeenCalledTimes(9);++ brainStorage.brainEvents.emit('journals:upserted', { record: { id: '2026-01-01', content: 'Updated again' } });+ expect((await getBrainGraphNeighborhood({ focusId: '2026-01-01' })).nodes[0].summary).toBe('Updated again');+ brainStorage.brainEvents.emit('journals:deleted', { id: '2026-01-01' });+ expect((await getBrainGraphOverview()).nodes).toEqual([]);+ expect(brainStorage.getAll).toHaveBeenCalledTimes(9);});it('keeps unrendered payloads and journal bodies out of the projections it reads', async () => {@@ -166,10 +185,9 @@ describe('getBrainGraphSearchIndex', () => {const [song] = await getBrainProjections('songs', { ranked: false });expect(song.content).toBeUndefined();- // The Daily Log body is the biggest record in the brain — the graph only- // needs "is this day non-empty?", so the text must never reach the cache.+ // Keep the graph tooltip, not the full Daily Log body or voice segments.expect(await getBrainProjections('journals', { ranked: false })).toEqual([- { id: '2026-01-01', date: undefined, hasBody: true }+ { id: '2026-01-01', date: undefined, hasBody: true, summary: 'z'.repeat(120) }]);});});diff --git a/server/services/brainSearchIndex.js b/server/services/brainSearchIndex.jsindex d96c2fef26..407c348550 100644--- a/server/services/brainSearchIndex.js+++ b/server/services/brainSearchIndex.js@@ -18,9 +18,8 @@** Only the fields a consumer actually reads (plus the ordering key) are* projected — the index holds no attachments, embeddings, or classification- * payloads. A consumer that needs a *predicate* over a large body (the Daily- * Log's `content`/`segments`) gets a derived boolean instead, so the body never- * enters the cache.+ * payloads. The Daily Log projects a body-presence predicate and a bounded+ * summary, so full `content`/`segments` never enter the cache.** FRESHNESS — three signal classes, all of them covered:* 1. `${type}:upserted` / `${type}:deleted` — the per-record events every@@ -51,7 +50,7 @@ import { safeDate } from '../lib/fileUtils.js';* node's label from `name || title` and drops archived records, while the* edge-bearing graph views also need tags, status, and summary fields.* `journals` is graph-only (the Daily Log is not a unified-search source), and- * projects no body — see `journalHasBody` below. `songs` (SongBook) is+ * keeps only body presence and a 120-character summary. `songs` (SongBook) is* graph-only too, and its sheet body lives in `content.text` (up to 200k* chars of tab/ChordPro per song). The graph projection keeps only a string* `content` value, so the SongBook object never reaches the cache.@@ -82,10 +81,8 @@ const PROJECTED_FIELDS = Object.freeze({});/**- * Is this Daily Log entry non-empty? The graph only asks the question — it- * never renders the answer's source — and a journal body is the largest record- * in the brain, so the predicate is projected and `content`/`segments` are not.- * Exported so `brainGraph`'s journal path applies the identical rule.+ * Is this Daily Log entry non-empty? Segment-only entries belong in the graph+ * even when their text summary is empty.*/export const journalHasBody = (record) => !!(record?.content || record?.segments?.length);@@ -100,7 +97,14 @@ const DERIVED_FIELDS = Object.freeze({admin: GRAPH_DERIVED_FIELDS,memories: GRAPH_DERIVED_FIELDS,songs: GRAPH_DERIVED_FIELDS,- journals: Object.freeze({ hasBody: journalHasBody }),+ journals: Object.freeze({+ hasBody: journalHasBody,+ summary: record => {+ const summary = stringContent(record)?.slice(0, 120) ?? '';+ // A V8 substring can retain the entire journal body in this long-lived cache.+ return summary.split('').join('');+ },+ }),});/**diff --git a/server/services/brainSearchIndex.test.js b/server/services/brainSearchIndex.test.jsindex f14bae558a..59e708aa42 100644--- a/server/services/brainSearchIndex.test.js+++ b/server/services/brainSearchIndex.test.js@@ -94,7 +94,7 @@ describe('brainSearchIndex', () => {expect(song.content).toBeUndefined()})- it('projects a journal entry as a body predicate, never the body', async () => {+ it('projects journal presence and a bounded summary, never the body', async () => {getAll.mockResolvedValue([{ id: '2026-01-01', content: 'x'.repeat(500), segments: [{ text: 'x' }] },{ id: '2026-01-02', content: '', segments: [] },@@ -102,9 +102,9 @@ describe('brainSearchIndex', () => {])expect(await getBrainProjections('journals')).toEqual([- { id: '2026-01-01', date: undefined, hasBody: true },- { id: '2026-01-02', date: undefined, hasBody: false },- { id: '2026-01-03', date: undefined, hasBody: true }+ { id: '2026-01-01', date: undefined, hasBody: true, summary: 'x'.repeat(120) },+ { id: '2026-01-02', date: undefined, hasBody: false, summary: '' },+ { id: '2026-01-03', date: undefined, hasBody: true, summary: '' }])})