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

feat(eidoverse): let a hosted world name its PortOS host and describe itself (#6246)

Adam Eivy21e96c206fd3
diff --git a/server/lib/eidoverseWorldDesign.js b/server/lib/eidoverseWorldDesign.js
index 800272be69..ea54fba666 100644
--- a/server/lib/eidoverseWorldDesign.js
+++ b/server/lib/eidoverseWorldDesign.js
@@ -16,6 +16,11 @@ export const EIDOVERSE_MAX_LIVE_ENTITIES = 48;
export const EIDOVERSE_LIBRARY_MODEL_ROOT = 'eidoverse/assets/models/';
export const EIDOVERSE_MANAGED_PREFIX = 'portos-design-v2-';
export const EIDOVERSE_PROJECTION_PREFIX = `${EIDOVERSE_MANAGED_PREFIX}signal-`;
+// The world's self-description rides on one managed convention entity rather
+// than a world-scope singleton: a `meta` slot on WorldState would be a protocol
+// amendment, while this replays, forks, and degrades gracefully on a host that
+// has never heard of PortOS.
+export const EIDOVERSE_META_ENTITY_ID = `${EIDOVERSE_MANAGED_PREFIX}meta`;
export const EIDOVERSE_SOURCE_KEYS = Object.freeze([
'apps',
diff --git a/server/services/eidoverseHost.js b/server/services/eidoverseHost.js
index ec8935d321..67ddec883b 100644
--- a/server/services/eidoverseHost.js
+++ b/server/services/eidoverseHost.js
@@ -8,6 +8,7 @@ import { ServerError } from '../lib/errorHandler.js';
import { EIDOVERSE_PORT } from './eidoverse.js';
const BAD_GATEWAY_BODY = 'Eidoverse Worlds is not running.';
+const HOST_DESCRIPTOR_PATH = '/host';
// Where a conflicting listener would sit. A local squatter almost always claims
// loopback — Docker publishes to 127.0.0.1, dev servers bind localhost — and
@@ -26,6 +27,48 @@ const forwardedHeaders = (req, protocol, targetHost, targetPort) => ({
'x-forwarded-proto': protocol,
});
+const requestPathname = (url) => String(url || '').split('?')[0].replace(/\/+$/, '') || '/';
+
+const writePlainText = (res, status, body) => {
+ res.writeHead(status, {
+ 'content-type': 'text/plain; charset=utf-8',
+ 'content-length': Buffer.byteLength(body),
+ });
+ res.end(body);
+};
+
+/**
+ * Terminate `GET /host` at the bridge. Runs outside the Express lifecycle, so a
+ * rejected read is caught here rather than crashing the process.
+ */
+const serveHostDescriptor = async (req, res) => {
+ if (req.method !== 'GET' && req.method !== 'HEAD') {
+ writePlainText(res, 405, 'The PortOS host descriptor is read-only.');
+ return;
+ }
+ // Deferred import: this bridge is constructed from the always-loaded settings
+ // route, while `/host` is a rare request. A static edge would drag the world
+ // config graph into every suite that reaches this module (server/AGENTS.md,
+ // "Import scoping").
+ const descriptor = await import('./eidoverseWorld.js')
+ .then(({ readEidoverseHostDescriptor }) => readEidoverseHostDescriptor())
+ .catch((error) => {
+ console.error(`❌ Eidoverse host descriptor failed: ${error.message}`);
+ return null;
+ });
+ if (!descriptor) {
+ writePlainText(res, 503, 'The PortOS host descriptor is unavailable.');
+ return;
+ }
+ const body = JSON.stringify(descriptor);
+ res.writeHead(200, {
+ 'content-type': 'application/json; charset=utf-8',
+ 'content-length': Buffer.byteLength(body),
+ 'cache-control': 'no-store',
+ });
+ res.end(req.method === 'HEAD' ? undefined : body);
+};
+
const writeBadGateway = (res) => {
if (res.headersSent) {
res.destroy();
@@ -89,6 +132,15 @@ export function createEidoverseHost({
};
const handleHttp = (req, res) => {
+ if (requestPathname(req.url) === HOST_DESCRIPTOR_PATH) {
+ // Nothing holds this promise, and a client that hung up mid-write makes
+ // `res` throw — so own the rejection here rather than killing the process.
+ serveHostDescriptor(req, res).catch((error) => {
+ console.error(`❌ Eidoverse host descriptor response failed: ${error.message}`);
+ res.destroy();
+ });
+ return;
+ }
const upstream = httpRequest({
hostname: targetHost,
port: targetPort,
diff --git a/server/services/eidoverseHost.test.js b/server/services/eidoverseHost.test.js
index 21728f4484..933e9e11f6 100644
--- a/server/services/eidoverseHost.test.js
+++ b/server/services/eidoverseHost.test.js
@@ -1,9 +1,23 @@
import { once } from 'node:events';
import { createServer } from 'node:http';
-import { afterEach, describe, expect, it } from 'vitest';
+import { afterEach, describe, expect, it, vi } from 'vitest';
import { WebSocket, WebSocketServer } from 'ws';
import { createEidoverseHost } from './eidoverseHost.js';
+// The bridge reaches the world config through a deferred `await import()`, so
+// the stub stands in for the whole config graph without loading it here.
+const HOST_DESCRIPTOR = Object.freeze({
+ id: 'hst_0123456789ab',
+ kind: 'portos',
+ label: 'Luminous Systems Garden',
+ version: '9.9.9',
+ caps: { eido: false },
+});
+const readEidoverseHostDescriptor = vi.fn(async () => HOST_DESCRIPTOR);
+vi.mock('./eidoverseWorld.js', () => ({
+ readEidoverseHostDescriptor: (...args) => readEidoverseHostDescriptor(...args),
+}));
+
const bridges = [];
const upstreamServers = [];
const webSocketServers = [];
@@ -110,6 +124,58 @@ describe('Eidoverse host bridge', () => {
webSocketClients.pop();
});
+ it('answers GET /host itself, so the descriptor never reaches the sequencer', async () => {
+ const upstreamRequests = [];
+ const upstreamPort = await listen(createServer((req, res) => {
+ upstreamRequests.push(req.url);
+ res.writeHead(200);
+ res.end('sequencer');
+ }));
+ const bridge = createEidoverseHost({
+ targetPort: upstreamPort,
+ listenHost: '127.0.0.1',
+ listenPort: 0,
+ certDir: null,
+ });
+ bridges.push(bridge);
+
+ const host = await bridge.start();
+ const response = await fetch(`http://127.0.0.1:${host.port}/host?probe=1`);
+
+ expect(response.status).toBe(200);
+ expect(response.headers.get('content-type')).toBe('application/json; charset=utf-8');
+ expect(await response.json()).toEqual(HOST_DESCRIPTOR);
+ // A forwarded request would have shown up here; the whole point is that it
+ // does not, so the upstream checkout needs no change to serve this.
+ expect(upstreamRequests).toEqual([]);
+ });
+
+ it('refuses to write through the descriptor path, and reports an unreadable descriptor honestly', async () => {
+ const upstreamRequests = [];
+ const upstreamPort = await listen(createServer((req, res) => {
+ upstreamRequests.push(req.url);
+ res.writeHead(200);
+ res.end('sequencer');
+ }));
+ const bridge = createEidoverseHost({
+ targetPort: upstreamPort,
+ listenHost: '127.0.0.1',
+ listenPort: 0,
+ certDir: null,
+ });
+ bridges.push(bridge);
+
+ const host = await bridge.start();
+ const posted = await fetch(`http://127.0.0.1:${host.port}/host`, { method: 'POST' });
+ expect(posted.status).toBe(405);
+
+ readEidoverseHostDescriptor.mockRejectedValueOnce(new Error('config unreadable'));
+ const failed = await fetch(`http://127.0.0.1:${host.port}/host`);
+ expect(failed.status).toBe(503);
+ // Neither the refusal nor the failure may fall through to the sequencer.
+ expect(upstreamRequests).toEqual([]);
+ });
+
// A managed app on PortOS's reserved :5563 bound 127.0.0.1 explicitly while
// this bridge bound the wildcard. macOS/BSD allow both, and the specific bind
// wins every connection — so the bridge logged "listening", served nothing,
diff --git a/server/services/eidoverseWorld.js b/server/services/eidoverseWorld.js
index deeca86e8c..0024fa6825 100644
--- a/server/services/eidoverseWorld.js
+++ b/server/services/eidoverseWorld.js
@@ -15,9 +15,10 @@ import { atomicWrite, dataPath, ensureDir, readJSONFile } from '../lib/fileUtils
import { createMutex } from '../lib/asyncMutex.js';
import { ServerError } from '../lib/errorHandler.js';
import { canonicalStringify } from '../lib/objects.js';
-import { getSelf, ensureSelf } from './instances.js';
+import { getSelf, ensureSelf, getInstanceId } from './instances.js';
import { getInstanceFeatures } from './instanceFeatures.js';
import { getEidoverseStatus, EIDOVERSE_PORT } from './eidoverse.js';
+import { getCurrentVersion } from './updateChecker.js';
import {
EIDOVERSE_ASSET_SLOTS_BY_DISTRICT,
EIDOVERSE_ASSET_RECIPE_VERSION,
@@ -37,6 +38,7 @@ import {
} from './eidoverseWorldProjection.js';
import {
collectEidoverseWorldSources,
+ eidoverseHostId,
projectedJiraTickets,
projectedStorage,
} from './eidoverseWorldSources.js';
@@ -440,6 +442,33 @@ export async function ensureEidoverseWorldConfig() {
});
}
+/**
+ * Who hosts this world? Answered by the PortOS bridge on `GET /host`, so the
+ * upstream Eidoverse checkout stays untouched — and hung on the world's own
+ * meta entity, so a fork of the log carries it too.
+ *
+ * Anyone who can reach the door reads this, so it carries a non-reversible
+ * install digest and the operator-chosen world title only — never a hostname,
+ * tailnet/MagicDNS name, LAN or public address, OS username, or home path.
+ * Config reads only: the bridge must not have to open a world connection.
+ */
+export async function readEidoverseHostDescriptor() {
+ const [state, instanceId, version] = await Promise.all([
+ loadState(),
+ getInstanceId(),
+ getCurrentVersion(),
+ ]);
+ return {
+ id: eidoverseHostId(instanceId),
+ kind: 'portos',
+ label: safeText(state.recipe?.name, DEFAULT_EIDOVERSE_PROJECTION_RECIPE.name, 120),
+ version,
+ // The `eido:` resolver/export path is unimplemented upstream, so a visiting
+ // client must not assume this host can serve one.
+ caps: { eido: false },
+ };
+}
+
export async function updateEidoverseWorldConfig(patch) {
return worldLock(async () => {
const self = await ensureSelf();
@@ -1603,11 +1632,13 @@ export async function projectEidoverseWorld({ signal } = {}) {
const lockedConfig = await resolveAndLockAssets(config, { signal });
const presence = await ensureCosPresenceInternal({ fresh: true, signal });
const source = await collectEidoverseWorldSources({ signal });
+ const hostId = eidoverseHostId(await getInstanceId());
throwIfAborted(signal);
const plan = buildProjectionPlan({
source,
recipe: lockedConfig.recipe,
currentState: presence.snapshot?.state || {},
+ meta: { title: lockedConfig.design.name, hostId },
});
await applyProjectionPlan(presence, plan, {
signal,
diff --git a/server/services/eidoverseWorld.runtime.test.js b/server/services/eidoverseWorld.runtime.test.js
index 4640bd17fe..0031c33910 100644
--- a/server/services/eidoverseWorld.runtime.test.js
+++ b/server/services/eidoverseWorld.runtime.test.js
@@ -46,6 +46,7 @@ vi.mock('../lib/fileUtils.js', async (importActual) => {
vi.mock('./instances.js', () => ({
getSelf: vi.fn(async () => mocks.self),
ensureSelf: vi.fn(async () => mocks.self),
+ getInstanceId: vi.fn(async () => mocks.self?.instanceId ?? 'unknown-instance'),
getPeers: vi.fn(async () => []),
}));
@@ -636,6 +637,24 @@ describe('Eidoverse private-world lifecycle', () => {
resolveAppStatuses([]);
});
+ // The world says who hosts it. A live projection has to actually supply that
+ // meta, or the reconciliation sweep deletes the carrier on the next run.
+ it('plants the world meta entity, naming its host opaquely and never by machine', async () => {
+ await world.projectEidoverseWorld();
+
+ const metaComp = mocks.sent.find(({ verb, args }) => (
+ verb === 'comp' && args?.id === 'portos-design-v2-meta' && args?.type === 'portos'
+ ));
+ expect(metaComp?.args.data).toMatchObject({
+ kind: 'world-meta',
+ managedBy: 'portos',
+ designVersion: 2,
+ meta: { title: expect.any(String), hostId: expect.stringMatching(/^hst_[0-9a-f]{12}$/) },
+ });
+ expect(JSON.stringify(metaComp.args.data)).not.toContain(mocks.self.instanceId);
+ expect(JSON.stringify(metaComp.args.data)).not.toContain(mocks.self.name);
+ });
+
it('preflights and locks recipe assets before completing a V2 reconciliation', async () => {
const result = await world.projectEidoverseWorld();
diff --git a/server/services/eidoverseWorld.test.js b/server/services/eidoverseWorld.test.js
index 24bde42ee2..25960920e6 100644
--- a/server/services/eidoverseWorld.test.js
+++ b/server/services/eidoverseWorld.test.js
@@ -1,11 +1,25 @@
-import { describe, expect, it } from 'vitest';
-import {
+import { homedir, hostname, userInfo } from 'node:os';
+import { afterAll, describe, expect, it, vi } from 'vitest';
+import { cleanupTempDataRoots, lazyTempDataRoot, makePathsProxy } from '../lib/mockPathsDataRoot.js';
+
+// `readEidoverseHostDescriptor` reads world config and the local identity off
+// disk. Re-root both at a scratch tree so the descriptor under test is the
+// shipped default rather than whatever this machine happens to hold.
+vi.mock('../lib/fileUtils.js', async (importOriginal) => makePathsProxy(await importOriginal(), {
+ dataRoot: () => lazyTempDataRoot('portos-eidoverse-world-'),
+}));
+
+const {
buildProjectionPlan,
DEFAULT_EIDOVERSE_PROJECTION_RECIPE,
projectedJiraTickets,
projectedStorage,
-} from './eidoverseWorld.js';
-import { eidoverseProjectionRecipeSchema } from '../lib/validation.js';
+ readEidoverseHostDescriptor,
+} = await import('./eidoverseWorld.js');
+const { eidoverseProjectionRecipeSchema } = await import('../lib/validation.js');
+const { EIDOVERSE_META_ENTITY_ID } = await import('../lib/eidoverseWorldDesign.js');
+
+afterAll(cleanupTempDataRoots);
const APP_FALLBACK = DEFAULT_EIDOVERSE_PROJECTION_RECIPE.assetRecipe.slots.app.fallback;
@@ -748,3 +762,96 @@ describe('Eidoverse PortOS projection plan', () => {
}));
});
});
+
+describe('Eidoverse world self-description', () => {
+ it('hangs the world title, host id, and design version on one managed meta entity', () => {
+ const meta = { title: 'Example Garden', hostId: 'hst_0123456789ab' };
+ const plan = buildProjectionPlan({ source: emptySources(), meta });
+ const state = snapshotFromPlan(plan);
+ const entity = state.entities[EIDOVERSE_META_ENTITY_ID];
+
+ expect(entity.comp.portos).toMatchObject({
+ managedBy: 'portos',
+ kind: 'world-meta',
+ designVersion: DEFAULT_EIDOVERSE_PROJECTION_RECIPE.version,
+ meta: { title: 'Example Garden', hostId: 'hst_0123456789ab' },
+ });
+ // No record contents ride along — the payload is identity, not data.
+ expect(Object.keys(entity.comp.portos.meta).sort()).toEqual(['hostId', 'title']);
+ expect(plan.summary.infrastructureCount)
+ .toBe(buildProjectionPlan({ source: emptySources() }).summary.infrastructureCount + 1);
+ });
+
+ it('creates the meta entity once and reconciles it like every other managed entity', () => {
+ const meta = { title: 'Example Garden', hostId: 'hst_0123456789ab' };
+ const first = buildProjectionPlan({ source: emptySources(), meta });
+ const currentState = snapshotFromPlan(first, { foldModelDefaults: true });
+
+ const second = buildProjectionPlan({ source: emptySources(), meta, currentState });
+ expect(second.operations.filter(({ args }) => args?.id === EIDOVERSE_META_ENTITY_ID)).toEqual([]);
+
+ const renamed = buildProjectionPlan({
+ source: emptySources(),
+ meta: { ...meta, title: 'Renamed Garden' },
+ currentState,
+ });
+ expect(renamed.operations.filter(({ args }) => args?.id === EIDOVERSE_META_ENTITY_ID))
+ .toEqual([{
+ layer: 'infrastructure',
+ verb: 'comp',
+ args: {
+ id: EIDOVERSE_META_ENTITY_ID,
+ type: 'portos',
+ data: expect.objectContaining({ meta: { title: 'Renamed Garden', hostId: meta.hostId } }),
+ },
+ }]);
+ });
+
+ // A managed entity the plan no longer wants is swept by the reconciliation
+ // pass — which is what makes a world reset take the meta carrier with it.
+ it('sweeps the meta entity away when the world no longer declares one', () => {
+ const withMeta = buildProjectionPlan({
+ source: emptySources(),
+ meta: { title: 'Example Garden', hostId: 'hst_0123456789ab' },
+ });
+ const plan = buildProjectionPlan({
+ source: emptySources(),
+ currentState: snapshotFromPlan(withMeta, { foldModelDefaults: true }),
+ });
+
+ expect(plan.operations).toContainEqual({
+ layer: 'reconciliation',
+ verb: 'remove',
+ args: { id: EIDOVERSE_META_ENTITY_ID },
+ });
+ });
+});
+
+describe('Eidoverse host descriptor', () => {
+ // Anyone who can reach the door reads this payload, so a field naming the
+ // machine, its network, or its operator would leak on every join.
+ it('names the host opaquely and carries no machine, network, or account identity', async () => {
+ const descriptor = await readEidoverseHostDescriptor();
+
+ expect(Object.keys(descriptor).sort()).toEqual(['caps', 'id', 'kind', 'label', 'version']);
+ expect(descriptor.id).toMatch(/^hst_[0-9a-f]{12}$/);
+ expect(descriptor.kind).toBe('portos');
+ expect(descriptor.label).toBe(DEFAULT_EIDOVERSE_PROJECTION_RECIPE.name);
+ expect(descriptor.caps).toEqual({ eido: false });
+ expect(typeof descriptor.version).toBe('string');
+
+ const serialized = JSON.stringify(descriptor);
+ for (const identity of [hostname(), hostname().split('.')[0], homedir(), userInfo().username]) {
+ if (identity) expect(serialized).not.toContain(identity);
+ }
+ expect(serialized).not.toMatch(/\d{1,3}(?:\.\d{1,3}){3}|\.ts\.net|\/Users\/|\/home\//);
+ });
+
+ it('gives the same install the same opaque id on every read', async () => {
+ const [first, second] = await Promise.all([
+ readEidoverseHostDescriptor(),
+ readEidoverseHostDescriptor(),
+ ]);
+ expect(second.id).toBe(first.id);
+ });
+});
diff --git a/server/services/eidoverseWorldProjection.js b/server/services/eidoverseWorldProjection.js
index ea853658bb..14a2939994 100644
--- a/server/services/eidoverseWorldProjection.js
+++ b/server/services/eidoverseWorldProjection.js
@@ -11,6 +11,7 @@ import {
EIDOVERSE_DISTRICTS_V2,
EIDOVERSE_MANAGED_PREFIX,
EIDOVERSE_MAX_LIVE_ENTITIES,
+ EIDOVERSE_META_ENTITY_ID,
EIDOVERSE_PROJECTION_PREFIX,
EIDOVERSE_WORLD_DESIGN_V1,
EIDOVERSE_WORLD_DESIGN_V2,
@@ -51,6 +52,9 @@ const DISTRICT_ASSET_SLOT = Object.freeze({
federation: 'peer',
activity: 'activity',
});
+// Just off the nexus and clear of every nexus->district path lane, whose first
+// node sits at 27% of the district anchor.
+const META_ENTITY_POS = Object.freeze([2.4, 0.08, 2.4]);
const DISTRICT_SCALE = Object.freeze({
nexus: 1.15,
apps: 1.1,
@@ -308,7 +312,7 @@ function equal(valueA, valueB) {
* intentionally exported so recipe changes can be tested without a live
* Eidoverse process and so future renderers can reuse the same projection.
*/
-export function buildProjectionPlan({ source = {}, recipe = DEFAULT_EIDOVERSE_PROJECTION_RECIPE, currentState = {} }) {
+export function buildProjectionPlan({ source = {}, recipe = DEFAULT_EIDOVERSE_PROJECTION_RECIPE, currentState = {}, meta = null }) {
const effectiveRecipe = mergeRecipe(recipe);
const stateEntities = currentState?.entities && typeof currentState.entities === 'object'
? currentState.entities
@@ -459,6 +463,44 @@ export function buildProjectionPlan({ source = {}, recipe = DEFAULT_EIDOVERSE_PR
});
}
+ // The world's own title, its host, and the design it was built from. Placed
+ // in the managed set so reconciliation keeps it and a world reset sweeps it
+ // away with every other `portos-design-v2-` entity.
+ let metaEntityCount = 0;
+ if (meta) {
+ const delta = upsertModel({
+ operations,
+ stateEntities,
+ desiredIds,
+ id: EIDOVERSE_META_ENTITY_ID,
+ lib: assetPathFor(effectiveRecipe, null, 'district'),
+ pos: META_ENTITY_POS,
+ yaw: 0,
+ scale: 0.2,
+ collide: null,
+ component: {
+ schemaVersion: 1,
+ managedBy: 'portos',
+ designVersion: EIDOVERSE_WORLD_DESIGN_VERSION,
+ kind: 'world-meta',
+ label: 'World identity',
+ route: '/eidoverse',
+ status: 'active',
+ // World title and host identity only — never a record, a machine name,
+ // an address, or a filesystem path.
+ meta: {
+ title: safeText(meta.title, 'PortOS world', 120),
+ hostId: safeText(meta.hostId, '', 64) || null,
+ },
+ },
+ layer: 'infrastructure',
+ });
+ created += delta.created;
+ updated += delta.updated;
+ removed += delta.removed;
+ metaEntityCount = 1;
+ }
+
const liveEntityLimit = Math.min(
effectiveRecipe.maxEntities ?? EIDOVERSE_MAX_LIVE_ENTITIES,
EIDOVERSE_MAX_LIVE_ENTITIES,
@@ -639,7 +681,7 @@ export function buildProjectionPlan({ source = {}, recipe = DEFAULT_EIDOVERSE_PR
designVersion: EIDOVERSE_WORLD_DESIGN_VERSION,
liveEntityCount,
maxLiveEntities: liveEntityLimit,
- infrastructureCount: districts.length + pathNodeCount,
+ infrastructureCount: districts.length + pathNodeCount + metaEntityCount,
districtCounts,
sourceAvailability,
truncated: Object.keys(droppedBySource).length > 0,
diff --git a/server/services/eidoverseWorldSources.js b/server/services/eidoverseWorldSources.js
index 4878d35be4..a94106209c 100644
--- a/server/services/eidoverseWorldSources.js
+++ b/server/services/eidoverseWorldSources.js
@@ -31,11 +31,20 @@ const safeText = (value, fallback = '', max = 160) => {
return clean ? clean.slice(0, max) : fallback;
};
-const opaqueId = (namespace, value, fallback) => {
+const opaqueDigest = (namespace, value, fallback) => {
const source = safeText(value, fallback, 256);
- return `${namespace}-${createHash('sha256').update(`${namespace}:${source}`).digest('hex').slice(0, 12)}`;
+ return createHash('sha256').update(`${namespace}:${source}`).digest('hex').slice(0, 12);
};
+const opaqueId = (namespace, value, fallback) => `${namespace}-${opaqueDigest(namespace, value, fallback)}`;
+
+/**
+ * The install's public host identity. Anyone who can reach the Eidoverse door
+ * reads this, so it is a one-way digest of the federation instance id — never
+ * the hostname, tailnet name, address, OS user, or a filesystem path.
+ */
+export const eidoverseHostId = (instanceId) => `hst_${opaqueDigest('hst', instanceId, 'unknown-instance')}`;
+
const coarseStatus = (value) => {
const status = String(value || '').toLowerCase();
if (/error|failed|unhealthy|offline|crash|blocked/.test(status)) return 'error';