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
fix([issue-711]): address codex review — migration for existing installs, localStorage hardening, honest changelog wording
Adam Eivy2b8191cd0cd9
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex af77f6eb87..27e553b256 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -3,7 +3,7 @@## Added- **[issue-708] Digital Twin "Voice" tab — spoken vs. written style** — Paste a transcript of yourself speaking and the Digital Twin compares it against how you write (a pasted sample, or your existing twin documents), surfacing where your spoken voice differs from your writing — formality, verbosity, sentence length, directness, filler words — and suggesting a communication profile for voice contexts that you can apply in one click.-- **[issue-711] "While You Were Away" dashboard card** — A new dashboard widget recaps what your agents did since your last visit: a count of completed runs, success/failure tally, total time worked, and the most recent wins plus anything that failed and needs a look. Each item links straight to the agent, and a "Mark as seen" button resets the window to now. It appears on the Everything and Agent Watch layouts and can be added to any layout via Arrange.+- **[issue-711] "While You Were Away" dashboard card** — A new dashboard widget recaps what your agents did since your last visit: a count of completed runs, success/failure tally, total time worked, and the most recent wins plus anything that failed and needs a look. Each item opens the agents view, and a "Mark as seen" button resets the window to now. It appears on the Everything and Agent Watch layouts and can be added to any layout via Arrange.## Changeddiff --git a/client/src/components/WhileAwayWidget.jsx b/client/src/components/WhileAwayWidget.jsxindex 205ee41ddf..4660ef1203 100644--- a/client/src/components/WhileAwayWidget.jsx+++ b/client/src/components/WhileAwayWidget.jsx@@ -20,7 +20,13 @@ import { timeAgo } from '../utils/formatters';const LAST_SEEN_KEY = 'portos.whileAway.lastSeen';const readLastSeen = () => {- const raw = localStorage.getItem(LAST_SEEN_KEY);+ // localStorage access can throw in private-mode / storage-disabled /+ // security-error contexts — never let that crash the dashboard render.+ // (Same guard idiom as utils/timeWindow.js.)+ if (typeof window === 'undefined' || !window.localStorage) return null;+ let raw = null;+ try { raw = window.localStorage.getItem(LAST_SEEN_KEY); }+ catch { return null; }// A finite, non-future ISO string is the only valid marker; anything else// (absent, garbage, clock-skewed) means "no marker" → server applies its// own 24h fallback so the card still renders.@@ -31,7 +37,11 @@ const readLastSeen = () => {};const writeLastSeen = (iso) => {- localStorage.setItem(LAST_SEEN_KEY, iso);+ // A write failure (quota / disabled) must not break "Mark as seen" — the+ // subsequent refetch still runs; the window just isn't persisted this time.+ if (typeof window === 'undefined' || !window.localStorage) return;+ try { window.localStorage.setItem(LAST_SEEN_KEY, iso); }+ catch { /* private mode / quota — graceful no-op */ }};function ActivityRow({ item, kind }) {diff --git a/scripts/migrations/070-seed-while-away-widget.js b/scripts/migrations/070-seed-while-away-widget.jsnew file mode 100644index 0000000000..9e00118ea9--- /dev/null+++ b/scripts/migrations/070-seed-while-away-widget.js@@ -0,0 +1,100 @@+/**+ * Seed the new `while-away` dashboard widget ("While You Were Away") into the+ * built-in `default` (Everything) and `agent-watch` layouts for installs that+ * already have a persisted `data/dashboard-layouts.json`.+ *+ * Background:+ * `server/services/dashboardLayouts.js#DEFAULT_LAYOUTS` only seeds when the+ * file is missing. Adding a widget to those layouts in code alone won't reach+ * existing users — this migration walks the file, finds each target built-in+ * layout, and inserts `while-away` into its `widgets` list + `grid` if+ * missing. User-renamed copies and other layouts are not touched. Re-runs+ * detect the widget is already present and skip. Mirrors migration 033.+ */++import { readLayoutsDoc, writeLayoutsDoc } from './_lib.js';++const WIDGET_ID = 'while-away';+const WIDGET_W = 3;+const WIDGET_H = 5;++// Mirror of the geometry in `server/services/dashboardLayouts.js`+// DEFAULT_LAYOUTS — edits here must match that file or fresh installs ++// migrated installs diverge. `agent-watch` gives the card a wider slot.+const PREFERRED_SLOTS = {+ default: { x: 9, y: 14, w: WIDGET_W, h: WIDGET_H },+ 'agent-watch': { x: 6, y: 3, w: 6, h: WIDGET_H },+};+const TARGET_LAYOUT_IDS = Object.keys(PREFERRED_SLOTS);++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;+}++function pickGridEntry(grid, layoutId) {+ const preferred = PREFERRED_SLOTS[layoutId];+ if (preferred) {+ const candidate = { id: WIDGET_ID, x: preferred.x, y: preferred.y, w: preferred.w, h: preferred.h };+ if (!collidesWith(grid, candidate)) return candidate;+ }+ // Fall back to a clean row below everything else if the preferred slot is+ // occupied (a user rearranged the layout but kept the built-in id).+ 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;++ let changed = false;+ // 1) Insert into widgets if absent.+ if (!layout.widgets.includes(WIDGET_ID)) {+ layout.widgets = [...layout.widgets, WIDGET_ID];+ changed = true;+ }+ // 2) Heal the grid entry independently — the widget id can be present in+ // `widgets` but missing from `grid` (e.g. a widgets-only edit landed without+ // an arrange-and-save pass). Treat a non-array grid as [] (the shape the+ // client's `synthesizeGrid` would auto-create at render time).+ const existingGrid = Array.isArray(layout.grid) ? layout.grid : [];+ const hasGridEntry = existingGrid.some((it) => it?.id === WIDGET_ID);+ if (!hasGridEntry) {+ layout.grid = [...existingGrid, pickGridEntry(existingGrid, layout.id)];+ changed = true;+ } else if (!Array.isArray(layout.grid)) {+ layout.grid = existingGrid;+ changed = true;+ }+ return changed;+}++export default {+ async up({ rootDir }) {+ const result = await readLayoutsDoc({ rootDir, label: 'migration 070' });+ if (!result.ok) return { updated: 0, reason: result.reason };+ const { doc, path } = result;++ let touched = 0;+ for (const layout of doc.layouts) {+ if (!layout || !TARGET_LAYOUT_IDS.includes(layout.id)) continue;+ if (applyToLayout(layout)) touched += 1;+ }++ if (touched === 0) {+ console.log(`📦 migration 070: while-away already present in target layouts.`);+ return { updated: 0, reason: 'already-applied' };+ }++ await writeLayoutsDoc(path, doc);+ console.log(`📦 migration 070: seeded while-away widget into ${touched} built-in layout(s).`);+ return { updated: touched };+ },+};diff --git a/scripts/migrations/070-seed-while-away-widget.test.js b/scripts/migrations/070-seed-while-away-widget.test.jsnew file mode 100644index 0000000000..f5d8da2009--- /dev/null+++ b/scripts/migrations/070-seed-while-away-widget.test.js@@ -0,0 +1,145 @@+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 './070-seed-while-away-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 070 — seed while-away widget into default + agent-watch layouts', () => {+ let rootDir;+ let layoutsPath;++ beforeEach(() => {+ rootDir = mkdtempSync(join(tmpdir(), 'migration-070-'));+ 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 while-away into both target layouts at their preferred slots', async () => {+ writeJson(layoutsPath, {+ activeLayoutId: 'default',+ layouts: [+ {+ id: 'default',+ name: 'Everything',+ builtIn: true,+ widgets: ['cos'],+ grid: [{ id: 'cos', x: 4, y: 14, w: 5, h: 4 }],+ },+ {+ id: 'agent-watch',+ name: 'Agent Watch',+ builtIn: true,+ widgets: ['cos'],+ grid: [{ id: 'cos', x: 0, y: 0, w: 6, h: 5 }],+ },+ ],+ });+ const result = await migration.up({ rootDir });+ expect(result.updated).toBe(2);+ const after = readJson(layoutsPath);++ const def = after.layouts.find((l) => l.id === 'default');+ expect(def.widgets).toContain('while-away');+ expect(def.grid.find((g) => g.id === 'while-away')).toEqual({ id: 'while-away', x: 9, y: 14, w: 3, h: 5 });++ const watch = after.layouts.find((l) => l.id === 'agent-watch');+ expect(watch.widgets).toContain('while-away');+ expect(watch.grid.find((g) => g.id === 'while-away')).toEqual({ id: 'while-away', x: 6, y: 3, w: 6, h: 5 });+ });++ it('is idempotent — second run is a no-op', async () => {+ writeJson(layoutsPath, {+ activeLayoutId: 'default',+ layouts: [+ { id: 'default', name: 'Everything', builtIn: true, widgets: ['while-away'], grid: [{ id: 'while-away', x: 9, y: 14, w: 3, h: 5 }] },+ { id: 'agent-watch', name: 'Agent Watch', builtIn: true, widgets: ['while-away'], grid: [{ id: 'while-away', x: 6, y: 3, w: 6, h: 5 }] },+ ],+ });+ const result = await migration.up({ rootDir });+ expect(result.updated).toBe(0);+ expect(result.reason).toBe('already-applied');+ });++ it('only touches the default + agent-watch ids, not other or renamed layouts', async () => {+ writeJson(layoutsPath, {+ activeLayoutId: 'focus',+ layouts: [+ { id: 'focus', name: 'Focus', builtIn: true, widgets: ['cos'], grid: [] },+ { id: 'my-watch', name: 'My Watch', builtIn: false, widgets: ['cos'], grid: [] },+ { id: 'agent-watch', name: 'Agent Watch', builtIn: true, widgets: ['cos'], grid: [] },+ ],+ });+ const result = await migration.up({ rootDir });+ expect(result.updated).toBe(1);+ const after = readJson(layoutsPath);+ expect(after.layouts.find((l) => l.id === 'focus').widgets).toEqual(['cos']);+ expect(after.layouts.find((l) => l.id === 'my-watch').widgets).toEqual(['cos']);+ expect(after.layouts.find((l) => l.id === 'agent-watch').widgets).toContain('while-away');+ });++ 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('heals legacy state where widget id is in widgets[] but missing from grid[]', async () => {+ writeJson(layoutsPath, {+ activeLayoutId: 'default',+ layouts: [+ {+ id: 'default',+ name: 'Everything',+ builtIn: true,+ widgets: ['cos', 'while-away'],+ grid: [{ id: 'cos', x: 4, y: 14, w: 5, h: 4 }],+ },+ ],+ });+ const result = await migration.up({ rootDir });+ expect(result.updated).toBe(1);+ const after = readJson(layoutsPath);+ const entry = after.layouts[0].grid.find((g) => g.id === 'while-away');+ expect(entry).toBeDefined();+ expect(after.layouts[0].widgets.filter((w) => w === 'while-away')).toHaveLength(1);+ });++ it('appends below existing items when the preferred slot is occupied', async () => {+ writeJson(layoutsPath, {+ activeLayoutId: 'default',+ layouts: [+ {+ id: 'default',+ name: 'Everything',+ builtIn: true,+ widgets: ['cos'],+ // Something already sits in the preferred slot (x:9,y:14).+ grid: [{ id: 'cos', x: 9, y: 14, 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 === 'while-away');+ expect(newEntry).toBeDefined();+ expect(newEntry.x).toBe(0);+ expect(newEntry.y).toBeGreaterThanOrEqual(19);+ });+});