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]): collision-safe migration placement

[._.]/ Adam Eivyaf849caad996
diff --git a/scripts/migrations/029-seed-network-exposure-widget.js b/scripts/migrations/029-seed-network-exposure-widget.js
index c2ef1b2a00..1564bb97c1 100644
--- a/scripts/migrations/029-seed-network-exposure-widget.js
+++ b/scripts/migrations/029-seed-network-exposure-widget.js
@@ -25,23 +25,50 @@ import { readFile, writeFile } from 'fs/promises';
import { join } from 'path';
const WIDGET_ID = 'network-exposure';
+const WIDGET_W = 3;
+const WIDGET_H = 5;
// 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 },
+// migrated installs will diverge — when the preferred slot is clear.
+const PREFERRED_SLOTS = {
+ default: { x: 9, y: 10 },
+ ops: { x: 3, y: 5 },
};
+function rectsOverlap(a, b) {
+ return a.x < b.x + b.w && b.x < a.x + a.w && a.y < b.y + b.h && b.y < a.y + a.h;
+}
+
+function collidesWith(grid, candidate) {
+ for (const item of grid) {
+ if (rectsOverlap(item, candidate)) return true;
+ }
+ return false;
+}
+
+// Place the widget at the preferred (x, y) when free. If a user-rearranged
+// layout already occupies that cell, fall back to appending below every
+// existing item at x=0 so the new widget never overlaps user content. The
+// user can drag it back to the preferred slot via the dashboard's
+// Arrange button.
+function pickGridEntry(grid, layoutId) {
+ const preferred = PREFERRED_SLOTS[layoutId];
+ if (preferred) {
+ const candidate = { id: WIDGET_ID, x: preferred.x, y: preferred.y, w: WIDGET_W, h: WIDGET_H };
+ if (!collidesWith(grid, candidate)) return candidate;
+ }
+ const bottom = grid.reduce((max, it) => Math.max(max, (it.y ?? 0) + (it.h ?? 0)), 0);
+ return { id: WIDGET_ID, x: 0, y: bottom, w: WIDGET_W, h: WIDGET_H };
+}
+
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 }];
+ if (Array.isArray(layout.grid)) {
+ layout.grid = [...layout.grid, pickGridEntry(layout.grid, layout.id)];
}
return true;
}
diff --git a/scripts/migrations/029-seed-network-exposure-widget.test.js b/scripts/migrations/029-seed-network-exposure-widget.test.js
index 9957ac152c..800441b053 100644
--- a/scripts/migrations/029-seed-network-exposure-widget.test.js
+++ b/scripts/migrations/029-seed-network-exposure-widget.test.js
@@ -82,6 +82,37 @@ describe('migration 029 — seed network-exposure widget into built-in layouts',
expect(result.reason).toBe('unreadable');
});
+ it('appends below existing items when the preferred slot is occupied by user rearrangement', async () => {
+ writeJson(layoutsPath, {
+ activeLayoutId: 'default',
+ layouts: [
+ {
+ id: 'default',
+ name: 'Everything',
+ builtIn: true,
+ widgets: ['system-health'],
+ grid: [{ id: 'system-health', x: 9, y: 10, w: 3, h: 5 }],
+ },
+ ],
+ });
+ const result = await migration.up({ rootDir });
+ expect(result.updated).toBe(1);
+ const after = readJson(layoutsPath);
+ const newEntry = after.layouts[0].grid.find((g) => g.id === 'network-exposure');
+ expect(newEntry).toBeDefined();
+ expect(newEntry.y).toBeGreaterThanOrEqual(15);
+ expect(newEntry.x).toBe(0);
+ expect(newEntry.w).toBe(3);
+ expect(newEntry.h).toBe(5);
+ const userHealth = after.layouts[0].grid.find((g) => g.id === 'system-health');
+ const overlaps =
+ newEntry.x < userHealth.x + userHealth.w &&
+ userHealth.x < newEntry.x + newEntry.w &&
+ newEntry.y < userHealth.y + userHealth.h &&
+ userHealth.y < newEntry.y + newEntry.h;
+ expect(overlaps).toBe(false);
+ });
+
it('skips a built-in layout that was hand-removed (single deleted built-in stays absent)', async () => {
writeJson(layoutsPath, {
activeLayoutId: 'default',