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

address review: extract shared getInstanceId to instances.js

Adam Eivy5cefe31e5934
diff --git a/server/services/brainStorage.js b/server/services/brainStorage.js
index b3297ac729..7c9fa950aa 100644
--- a/server/services/brainStorage.js
+++ b/server/services/brainStorage.js
@@ -15,20 +15,10 @@ import { v4 as uuidv4 } from 'uuid';
import EventEmitter from 'events';
import { readJSONFile, safeJSONParse } from '../lib/fileUtils.js';
import { createMutex } from '../lib/asyncMutex.js';
-import { getSelf } from './instances.js';
+import { getInstanceId } from './instances.js';
import * as brainSyncLog from './brainSyncLog.js';
const withRemoteLock = createMutex();
-let cachedInstanceId = null;
-
-async function getInstanceId() {
- if (!cachedInstanceId) {
- const id = (await getSelf())?.instanceId;
- if (id) cachedInstanceId = id;
- return id ?? 'unknown';
- }
- return cachedInstanceId;
-}
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
diff --git a/server/services/instances.js b/server/services/instances.js
index 1be9dcdf7f..7d3e8444cf 100644
--- a/server/services/instances.js
+++ b/server/services/instances.js
@@ -70,6 +70,16 @@ export async function getSelf() {
return data.self;
}
+let cachedInstanceId = null;
+export async function getInstanceId() {
+ if (!cachedInstanceId) {
+ const id = (await getSelf())?.instanceId;
+ if (id) cachedInstanceId = id;
+ return id ?? 'unknown';
+ }
+ return cachedInstanceId;
+}
+
export async function updateSelf(name) {
return withData(async (data) => {
if (!data.self) return null;
diff --git a/server/services/memoryDB.js b/server/services/memoryDB.js
index 917452371f..03edd34483 100644
--- a/server/services/memoryDB.js
+++ b/server/services/memoryDB.js
@@ -12,18 +12,7 @@ import { query, withTransaction, pgvectorToArray, arrayToPgvector } from '../lib
import { cosEvents } from './cos.js';
import * as notifications from './notifications.js';
import { DEFAULT_MEMORY_CONFIG, generateSummary, decrementAgentPendingApproval } from './memoryConfig.js';
-import { getSelf } from './instances.js';
-
-let cachedInstanceId = null;
-
-async function getInstanceId() {
- if (!cachedInstanceId) {
- const id = (await getSelf())?.instanceId;
- if (id) cachedInstanceId = id;
- return id ?? 'unknown';
- }
- return cachedInstanceId;
-}
+import { getInstanceId } from './instances.js';
/**
* Convert a database row to the memory object format matching the file-based API