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
pass httpsEnabled/port to the agent key boot hook so runBootSequence keeps its io wiring visible to the source guard
[._.]/ Adam Eivy46921a28daab
diff --git a/server/services/agentKey.js b/server/services/agentKey.jsindex 2f46b5ba52..b55c641a4c 100644--- a/server/services/agentKey.js+++ b/server/services/agentKey.js@@ -49,7 +49,7 @@ let apiUrl = null;let timer = null;let listening = false;-const defaultApiUrl = () => `http://127.0.0.1:${Number(process.env.PORT) || PORTS.API}`;+const defaultApiUrl = () => localApiUrlFor();const isKeyEnabled = async () => (await getSettings())?.secrets?.agentKey?.enabled === true;@@ -150,11 +150,16 @@ const reconcileInBackground = (reason) => {};/**- * Boot hook. `localApiUrl` is the loopback origin this process serves the API- * on (the HTTP mirror when HTTPS is on), written into the file for the CLI.+ * The loopback origin a local CLI reaches this API on: the HTTP mirror when+ * :5555 speaks TLS (see announceListening in bootstrap.js), else :5555 itself.*/-export const initAgentKey = ({ localApiUrl } = {}) => {- apiUrl = localApiUrl || defaultApiUrl();+export const localApiUrlFor = ({ httpsEnabled = false, port = null } = {}) => (httpsEnabled+ ? `http://127.0.0.1:${Number(process.env.PORTOS_HTTP_PORT) || PORTS.API_LOCAL}`+ : `http://127.0.0.1:${port || Number(process.env.PORT) || PORTS.API}`);++/** Boot hook; `httpsEnabled` and `port` pick the URL written into the file. */+export const initAgentKey = ({ httpsEnabled = false, port = null } = {}) => {+ apiUrl = localApiUrlFor({ httpsEnabled, port });if (!listening) {listening = true;// Covers the flag itself, and a password being set or cleared.diff --git a/server/services/agentKey.test.js b/server/services/agentKey.test.jsindex 6413a93bae..fd8f1f52f9 100644--- a/server/services/agentKey.test.js+++ b/server/services/agentKey.test.js@@ -60,7 +60,7 @@ describe('agent API key', () => {authEnabled = true;settings = {};__testing.reset();- initAgentKey({ localApiUrl: 'http://127.0.0.1:5553' });+ initAgentKey({ httpsEnabled: true, port: 5555 });await __testing.reconcile();});diff --git a/server/services/bootstrap.hostedSessionSweep.test.js b/server/services/bootstrap.hostedSessionSweep.test.jsindex e338ac6efc..50a65875a7 100644--- a/server/services/bootstrap.hostedSessionSweep.test.js+++ b/server/services/bootstrap.hostedSessionSweep.test.js@@ -37,7 +37,8 @@ describe('hosted-session sweeper boot wiring (#5660)', () => {it('passes io down from runBootSequence, which is where the Socket.IO server lives', () => {const bootBody = stripCommentsAndNormalize(extractDeclaration(SRC, 'runBootSequence') || '');- expect(bootBody).toContain('startBackgroundServices({ spawnerReady, io })');+ // Other boot facts may ride along in the same object; `io` must be one.+ expect(bootBody).toMatch(/startBackgroundServices\(\{ spawnerReady, io[,\s}]/);});it('disarms the sweeper during graceful shutdown', () => {diff --git a/server/services/bootstrap.js b/server/services/bootstrap.jsindex 07a00e3504..d9648c04e2 100644--- a/server/services/bootstrap.js+++ b/server/services/bootstrap.js@@ -401,12 +401,12 @@ export const bootstrapServices = async ({ io, dataDir, dataReferenceDir, serverD* Fire-and-forget service inits + scheduler arming. None of these block the* server from listening; each logs its own failure and the boot continues.*/-const startBackgroundServices = ({ spawnerReady, io, localApiUrl }) => {+const startBackgroundServices = ({ spawnerReady, io, httpsEnabled, port }) => {// Keep the opt-in agent API key file current (Settings > Security). A no-op// beyond one settings read while the key is off. Disabled under smoke boot// with the rest of this function, so a smoke run never writes to $HOME.import('./agentKey.js')- .then(({ initAgentKey }) => initAgentKey({ localApiUrl }))+ .then(({ initAgentKey }) => initAgentKey({ httpsEnabled, port })).catch((err) => logBootstrapFailure('❌ Agent API key init failed', err));// Put npm's global bin directory on PATH before anything spawns a provider@@ -919,13 +919,7 @@ const announceListening = ({ io, httpServer, localHttpServer, httpsEnabled, port*/export const runBootSequence = ({ io, httpServer, localHttpServer, httpsEnabled, port, host, spawnerReady }) =>runPostRouteSequence(gateStepsForSmokeBoot({- startBackgroundServices: () => startBackgroundServices({- spawnerReady,- io,- // Where a local CLI reaches this API: the loopback HTTP mirror when- // :5555 speaks TLS (see announceListening), else :5555 itself.- localApiUrl: `http://127.0.0.1:${httpsEnabled ? (Number(process.env.PORTOS_HTTP_PORT) || PORTS.API_LOCAL) : port}`,- }),+ startBackgroundServices: () => startBackgroundServices({ spawnerReady, io, httpsEnabled, port }),// Instance identity + sync log come up before requests are accepted, so a// brain mutation can't arrive before the sync log is ready.