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
refactor: consolidate brain entity-types list to one canonical export
Adam Eivy08b66ec1695c
diff --git a/scripts/migrations/080-brain-tombstone-and-synclog-cleanup.js b/scripts/migrations/080-brain-tombstone-and-synclog-cleanup.jsindex 2e3960a5f3..cdfe5f349d 100644--- a/scripts/migrations/080-brain-tombstone-and-synclog-cleanup.js+++ b/scripts/migrations/080-brain-tombstone-and-synclog-cleanup.js@@ -31,6 +31,9 @@ import { readFile, writeFile } from 'fs/promises';import { existsSync } from 'fs';import { join } from 'path';+// Deliberately a standalone copy of brainStorage.BRAIN_ENTITY_TYPES: migrations+// run in the boot-time runner BEFORE the service layer is wired up, so this file+// must not import from server/services. Keep in sync with that canonical list.const ENTITY_TYPES = ['people', 'projects', 'ideas', 'admin', 'memories', 'links', 'buckets'];function parseLog(content) {diff --git a/server/services/brainStorage.js b/server/services/brainStorage.jsindex a531b57de5..2e6206c9f3 100644--- a/server/services/brainStorage.js+++ b/server/services/brainStorage.js@@ -21,6 +21,15 @@ const withRemoteLock = createMutex();const DATA_DIR = PATHS.brain;+// The JSON entity stores that participate in peer sync (have records with IDs).+// Canonical list — sync, tombstone GC, and origin backfill all derive from it+// so adding an 8th type can't silently drop out of one of those paths. (The+// boot-time migration keeps its own copy by necessity — migrations run before+// the service layer is wired up — see scripts/migrations/080-*.js.)+export const BRAIN_ENTITY_TYPES = Object.freeze([+ 'people', 'projects', 'ideas', 'admin', 'memories', 'links', 'buckets',+]);+// A tombstone is a deleted-record marker kept IN PLACE in `data.records[id]`// (rather than removing the key) so the last-writer-wins guard in// applyRemoteRecord can reject a stale `create` echoed back from a peer.@@ -745,10 +754,9 @@ export async function pruneTombstones(type, cutoffMs) {*/export async function backfillOriginInstanceId() {const instanceId = await getInstanceId();- const entityTypes = ['people', 'projects', 'ideas', 'admin', 'memories', 'links', 'buckets'];let totalBackfilled = 0;- for (const type of entityTypes) {+ for (const type of BRAIN_ENTITY_TYPES) {const data = await loadJsonStore(type);let changed = false;diff --git a/server/services/brainSync.js b/server/services/brainSync.jsindex db6767c820..80de2ef95e 100644--- a/server/services/brainSync.js+++ b/server/services/brainSync.js@@ -10,11 +10,9 @@*/import * as brainStorage from './brainStorage.js';+import { BRAIN_ENTITY_TYPES } from './brainStorage.js';import * as brainSyncLog from './brainSyncLog.js';-// Entity types stored as JSON (have records with IDs)-const ENTITY_TYPES = ['people', 'projects', 'ideas', 'admin', 'memories', 'links', 'buckets'];-/*** Apply remote changes from a peer instance.* Batches relay sync-log appends to reduce lock contention and fs calls.@@ -28,7 +26,7 @@ export async function applyRemoteChanges(changes) {for (const change of changes) {let { op, type, id, record, originInstanceId } = change;- if (!ENTITY_TYPES.includes(type)) {+ if (!BRAIN_ENTITY_TYPES.includes(type)) {skipped++;continue;}diff --git a/server/services/brainSync.test.js b/server/services/brainSync.test.jsindex e036da25ca..4fca8519e6 100644--- a/server/services/brainSync.test.js+++ b/server/services/brainSync.test.js@@ -1,7 +1,8 @@import { describe, it, expect, vi, beforeEach } from 'vitest';vi.mock('./brainStorage.js', () => ({- applyRemoteRecord: vi.fn()+ applyRemoteRecord: vi.fn(),+ BRAIN_ENTITY_TYPES: ['people', 'projects', 'ideas', 'admin', 'memories', 'links', 'buckets'],}));vi.mock('./brainSyncLog.js', () => ({diff --git a/server/services/brainTombstoneGc.js b/server/services/brainTombstoneGc.jsindex 50bdde0c16..e21e255477 100644--- a/server/services/brainTombstoneGc.js+++ b/server/services/brainTombstoneGc.js@@ -19,8 +19,6 @@import * as brainStorage from './brainStorage.js';-const ENTITY_TYPES = ['people', 'projects', 'ideas', 'admin', 'memories', 'links', 'buckets'];-/*** Prune brain tombstones older than the grace period.* @param {{ now?: number, graceMs?: number }} [opts]@@ -29,7 +27,7 @@ const ENTITY_TYPES = ['people', 'projects', 'ideas', 'admin', 'memories', 'linksexport async function sweepBrainTombstones({ now = Date.now(), graceMs = brainStorage.BRAIN_TOMBSTONE_GRACE_MS } = {}) {const cutoff = now - graceMs;let pruned = 0;- for (const type of ENTITY_TYPES) {+ for (const type of brainStorage.BRAIN_ENTITY_TYPES) {pruned += await brainStorage.pruneTombstones(type, cutoff);}return { pruned };diff --git a/server/services/brainTombstoneGc.test.js b/server/services/brainTombstoneGc.test.jsindex 94ce03c0c0..fd61bc3caf 100644--- a/server/services/brainTombstoneGc.test.js+++ b/server/services/brainTombstoneGc.test.js@@ -1,15 +1,16 @@import { describe, it, expect, vi, beforeEach } from 'vitest';+const ENTITY_TYPES = ['people', 'projects', 'ideas', 'admin', 'memories', 'links', 'buckets'];+const pruneTombstones = vi.fn();vi.mock('./brainStorage.js', () => ({pruneTombstones: (...args) => pruneTombstones(...args),BRAIN_TOMBSTONE_GRACE_MS: 30 * 24 * 60 * 60 * 1000,+ BRAIN_ENTITY_TYPES: ['people', 'projects', 'ideas', 'admin', 'memories', 'links', 'buckets'],}));import { sweepBrainTombstones } from './brainTombstoneGc.js';-const ENTITY_TYPES = ['people', 'projects', 'ideas', 'admin', 'memories', 'links', 'buckets'];-describe('brainTombstoneGc', () => {beforeEach(() => {vi.clearAllMocks();