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

fix([codex5-network-exposure-ui]): migrate existing dashboard layouts

[._.]/ Adam Eivyc0b0f34be840
diff --git a/scripts/migrations/029-seed-network-exposure-widget.js b/scripts/migrations/029-seed-network-exposure-widget.js
new file mode 100644
index 0000000000..c2ef1b2a00
--- /dev/null
+++ b/scripts/migrations/029-seed-network-exposure-widget.js
@@ -0,0 +1,84 @@
+/**
+ * Seed the new `network-exposure` dashboard widget into built-in layouts
+ * for installs that already have a persisted `data/dashboard-layouts.json`.
+ *
+ * Background:
+ * `server/services/dashboardLayouts.js#DEFAULT_LAYOUTS` lists the built-in
+ * layouts shipped with PortOS. `getState()` returns the sanitized persisted
+ * layouts whenever the file exists, so adding a new widget to a built-in
+ * layout in code only affects fresh installs — existing users never see it.
+ *
+ * This migration walks `data/dashboard-layouts.json`, finds the built-in
+ * `default` (Everything) and `ops` layouts by id, and inserts
+ * `network-exposure` into their `widgets` list + an explicit `grid` entry,
+ * matching the geometry seeded server-side. User-renamed copies and custom
+ * layouts are not touched (idempotent — re-runs detect the widget is
+ * already present and skip).
+ *
+ * Layouts that were explicitly removed from the file (e.g. user deleted
+ * the `ops` layout) stay absent — `dashboardLayouts.js` re-seeds them on
+ * read if every built-in is gone, but a single deleted built-in doesn't
+ * come back.
+ */
+
+import { readFile, writeFile } from 'fs/promises';
+import { join } from 'path';
+
+const WIDGET_ID = 'network-exposure';
+
+// Mirror of the geometry chosen in `server/services/dashboardLayouts.js`
+// DEFAULT_LAYOUTS. Edits here must match that file or fresh installs +
+// migrated installs will diverge.
+const GRID_INSERTS = {
+ default: { id: WIDGET_ID, x: 9, y: 10, w: 3, h: 5 },
+ ops: { id: WIDGET_ID, x: 3, y: 5, w: 3, h: 5 },
+};
+
+function applyToLayout(layout) {
+ if (!layout || typeof layout !== 'object') return false;
+ if (!Array.isArray(layout.widgets)) return false;
+ if (layout.widgets.includes(WIDGET_ID)) return false;
+ layout.widgets = [...layout.widgets, WIDGET_ID];
+ const gridInsert = GRID_INSERTS[layout.id];
+ if (gridInsert && Array.isArray(layout.grid)) {
+ layout.grid = [...layout.grid, { ...gridInsert }];
+ }
+ return true;
+}
+
+export default {
+ async up({ rootDir }) {
+ const path = join(rootDir, 'data', 'dashboard-layouts.json');
+ const raw = await readFile(path, 'utf-8').catch((err) => {
+ if (err.code === 'ENOENT') return null;
+ throw err;
+ });
+ if (raw == null) {
+ console.log(`📦 migration 029: no dashboard-layouts.json yet — fresh install will seed from defaults.`);
+ return { updated: 0, reason: 'no-state' };
+ }
+ let doc;
+ try { doc = JSON.parse(raw); } catch {
+ console.log(`📦 migration 029: dashboard-layouts.json unreadable — skipping.`);
+ return { updated: 0, reason: 'unreadable' };
+ }
+ if (!doc || !Array.isArray(doc.layouts)) {
+ return { updated: 0, reason: 'no-layouts-array' };
+ }
+
+ let touched = 0;
+ for (const layout of doc.layouts) {
+ if (!layout || (layout.id !== 'default' && layout.id !== 'ops')) continue;
+ if (applyToLayout(layout)) touched += 1;
+ }
+
+ if (touched === 0) {
+ console.log(`📦 migration 029: network-exposure already present in built-in layouts.`);
+ return { updated: 0, reason: 'already-applied' };
+ }
+
+ await writeFile(path, JSON.stringify(doc, null, 2));
+ console.log(`📦 migration 029: seeded network-exposure widget into ${touched} built-in layout(s).`);
+ return { updated: touched };
+ },
+};
diff --git a/scripts/migrations/029-seed-network-exposure-widget.test.js b/scripts/migrations/029-seed-network-exposure-widget.test.js
new file mode 100644
index 0000000000..9957ac152c
--- /dev/null
+++ b/scripts/migrations/029-seed-network-exposure-widget.test.js
@@ -0,0 +1,98 @@
+import { describe, it, expect, beforeEach, afterEach } from 'vitest';
+import { mkdtempSync, rmSync, writeFileSync, readFileSync, mkdirSync, existsSync } from 'fs';
+import { tmpdir } from 'os';
+import { join } from 'path';
+
+import migration from './029-seed-network-exposure-widget.js';
+
+const writeJson = (path, value) => writeFileSync(path, JSON.stringify(value, null, 2) + '\n');
+const readJson = (path) => JSON.parse(readFileSync(path, 'utf-8'));
+
+describe('migration 029 — seed network-exposure widget into built-in layouts', () => {
+ let rootDir;
+ let layoutsPath;
+
+ beforeEach(() => {
+ rootDir = mkdtempSync(join(tmpdir(), 'migration-029-'));
+ mkdirSync(join(rootDir, 'data'), { recursive: true });
+ layoutsPath = join(rootDir, 'data', 'dashboard-layouts.json');
+ });
+
+ afterEach(() => {
+ rmSync(rootDir, { recursive: true, force: true });
+ });
+
+ it('no-ops cleanly when dashboard-layouts.json is missing (fresh install)', async () => {
+ const result = await migration.up({ rootDir });
+ expect(result.updated).toBe(0);
+ expect(result.reason).toBe('no-state');
+ expect(existsSync(layoutsPath)).toBe(false);
+ });
+
+ it('inserts network-exposure into both default and ops layouts', async () => {
+ writeJson(layoutsPath, {
+ activeLayoutId: 'default',
+ layouts: [
+ { id: 'default', name: 'Everything', builtIn: true, widgets: ['quick-task', 'system-health'], grid: [{ id: 'quick-task', x: 0, y: 0, w: 6, h: 5 }] },
+ { id: 'ops', name: 'Ops', builtIn: true, widgets: ['system-health', 'cos'], grid: [{ id: 'system-health', x: 0, y: 0, w: 6, h: 5 }] },
+ ],
+ });
+ const result = await migration.up({ rootDir });
+ expect(result.updated).toBe(2);
+ const after = readJson(layoutsPath);
+ const defaultLayout = after.layouts.find((l) => l.id === 'default');
+ const opsLayout = after.layouts.find((l) => l.id === 'ops');
+ expect(defaultLayout.widgets).toContain('network-exposure');
+ expect(opsLayout.widgets).toContain('network-exposure');
+ expect(defaultLayout.grid.find((g) => g.id === 'network-exposure')).toEqual({ id: 'network-exposure', x: 9, y: 10, w: 3, h: 5 });
+ expect(opsLayout.grid.find((g) => g.id === 'network-exposure')).toEqual({ id: 'network-exposure', x: 3, y: 5, w: 3, h: 5 });
+ });
+
+ it('is idempotent — second run is a no-op', async () => {
+ writeJson(layoutsPath, {
+ activeLayoutId: 'default',
+ layouts: [
+ { id: 'default', name: 'Everything', builtIn: true, widgets: ['network-exposure'], grid: [{ id: 'network-exposure', x: 9, y: 10, w: 3, h: 5 }] },
+ ],
+ });
+ const result = await migration.up({ rootDir });
+ expect(result.updated).toBe(0);
+ expect(result.reason).toBe('already-applied');
+ });
+
+ it('preserves user-renamed layout copies — only touches built-in ids', async () => {
+ writeJson(layoutsPath, {
+ activeLayoutId: 'my-default',
+ layouts: [
+ { id: 'my-default', name: 'My Everything', builtIn: false, widgets: ['quick-task'], grid: [] },
+ { id: 'default', name: 'Everything', builtIn: true, widgets: ['quick-task'], grid: [] },
+ ],
+ });
+ const result = await migration.up({ rootDir });
+ expect(result.updated).toBe(1);
+ const after = readJson(layoutsPath);
+ expect(after.layouts.find((l) => l.id === 'my-default').widgets).toEqual(['quick-task']);
+ expect(after.layouts.find((l) => l.id === 'default').widgets).toContain('network-exposure');
+ });
+
+ it('survives an unreadable JSON file', async () => {
+ writeFileSync(layoutsPath, 'not json');
+ const result = await migration.up({ rootDir });
+ expect(result.updated).toBe(0);
+ expect(result.reason).toBe('unreadable');
+ });
+
+ it('skips a built-in layout that was hand-removed (single deleted built-in stays absent)', async () => {
+ writeJson(layoutsPath, {
+ activeLayoutId: 'default',
+ layouts: [
+ { id: 'default', name: 'Everything', builtIn: true, widgets: ['system-health'], grid: [] },
+ // ops layout deliberately absent — user deleted it
+ ],
+ });
+ const result = await migration.up({ rootDir });
+ expect(result.updated).toBe(1);
+ const after = readJson(layoutsPath);
+ expect(after.layouts.find((l) => l.id === 'ops')).toBeUndefined();
+ });
+});