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
address review (local-gate): PromptManager edit-loss, message-touchpoint local day, tribe-care migration seed
Adam Eivycd4cbee39b8f
diff --git a/client/src/pages/PromptManager.jsx b/client/src/pages/PromptManager.jsxindex 2c8dfb7a6a..53100be25a 100644--- a/client/src/pages/PromptManager.jsx+++ b/client/src/pages/PromptManager.jsx@@ -1,4 +1,4 @@-import { useState, useEffect } from 'react';+import { useState, useEffect, useRef } from 'react';import { useSearchParams } from 'react-router-dom';import { FileText, Variable, RefreshCw, Save, Plus, Trash2, Eye, Briefcase } from 'lucide-react';import toast from '../components/ui/Toast';@@ -160,14 +160,23 @@ export default function PromptManager() {setPreview(data.preview);};- // Hydrate the variable editor from the URL-selected key. Keyed on selectedVar- // (+ variables so it fills in once the list loads) — no param means create mode.+ // Hydrate the variable editor from the URL-selected key. Depends on `variables`+ // so it fills in once the list loads, but a `varHydratedRef` guard keyed on the+ // selected key ensures a later `variables` refresh (Reload, or deleting a+ // *different* variable) does NOT re-hydrate — which would silently discard the+ // open key's in-progress edits. Mirrors the hydratedRef pattern the Authors /+ // Artists editors use. No param means create mode.+ const varHydratedRef = useRef(null);useEffect(() => {- if (selectedVar && variables[selectedVar]) {+ if (!selectedVar) {+ varHydratedRef.current = null;+ setVarForm({ key: '', name: '', category: '', content: '' });+ return;+ }+ if (variables[selectedVar] && varHydratedRef.current !== selectedVar) {const v = variables[selectedVar];setVarForm({ key: selectedVar, name: v.name || '', category: v.category || '', content: v.content || '' });- } else if (!selectedVar) {- setVarForm({ key: '', name: '', category: '', content: '' });+ varHydratedRef.current = selectedVar;}}, [selectedVar, variables]);diff --git a/scripts/migrations/156-seed-feeds-and-meatspace-streak-widgets.js b/scripts/migrations/156-seed-feeds-and-meatspace-streak-widgets.jsindex 37583f294f..e92774dd52 100644--- a/scripts/migrations/156-seed-feeds-and-meatspace-streak-widgets.js+++ b/scripts/migrations/156-seed-feeds-and-meatspace-streak-widgets.js@@ -12,9 +12,10 @@* are untouched. Re-runs detect the widget is already present and skip.* Mirrors migrations 070 / 145.*- * `feeds` → `default` ("Everything") layout; `meatspace-streak` → `health`.- * Both widgets are gated client-side (hidden until feeds/logs exist), so a- * fresh-but-persisted install seeing the id costs nothing until it has data.+ * `feeds` + `tribe-care` → `default` ("Everything") layout;+ * `meatspace-streak` → `health`. All three widgets are gated client-side+ * (hidden until feeds/tribe-people/logs exist), so a fresh-but-persisted+ * install seeing the id costs nothing until it has data.*/import { readLayoutsDoc, writeLayoutsDoc } from './_lib.js';@@ -24,6 +25,7 @@ import { readLayoutsDoc, writeLayoutsDoc } from './_lib.js';// must match that file or fresh installs + migrated installs diverge.const SEEDS = [{ widgetId: 'feeds', layoutId: 'default', slot: { x: 8, y: 29, w: 3, h: 4 } },+ { widgetId: 'tribe-care', layoutId: 'default', slot: { x: 4, y: 29, w: 4, h: 4 } },{ widgetId: 'meatspace-streak', layoutId: 'health', slot: { x: 0, y: 9, w: 4, h: 4 } },];@@ -83,12 +85,12 @@ export default {}if (touched === 0) {- console.log(`📦 migration 156: feeds + meatspace-streak already present in target layouts.`);+ console.log(`📦 migration 156: feeds + tribe-care + meatspace-streak already present in target layouts.`);return { updated: 0, reason: 'already-applied' };}await writeLayoutsDoc(path, doc);- console.log(`📦 migration 156: seeded feeds/meatspace-streak into ${touched} built-in layout(s).`);+ console.log(`📦 migration 156: seeded feeds/tribe-care/meatspace-streak widget(s) into ${touched} built-in layout slot(s).`);return { updated: touched };},};diff --git a/scripts/migrations/156-seed-feeds-and-meatspace-streak-widgets.test.js b/scripts/migrations/156-seed-feeds-and-meatspace-streak-widgets.test.jsindex 043a3c972e..f74664fc30 100644--- a/scripts/migrations/156-seed-feeds-and-meatspace-streak-widgets.test.js+++ b/scripts/migrations/156-seed-feeds-and-meatspace-streak-widgets.test.js@@ -38,12 +38,14 @@ describe('migration 156 — seed feeds + meatspace-streak widgets', () => {],});const result = await migration.up({ rootDir });- expect(result.updated).toBe(2);+ expect(result.updated).toBe(3);const after = readJson(layoutsPath);const def = after.layouts.find((l) => l.id === 'default');expect(def.widgets).toContain('feeds');expect(def.grid.find((g) => g.id === 'feeds')).toEqual({ id: 'feeds', x: 8, y: 29, w: 3, h: 4 });+ expect(def.widgets).toContain('tribe-care');+ expect(def.grid.find((g) => g.id === 'tribe-care')).toEqual({ id: 'tribe-care', x: 4, y: 29, w: 4, h: 4 });const health = after.layouts.find((l) => l.id === 'health');expect(health.widgets).toContain('meatspace-streak');@@ -54,7 +56,7 @@ describe('migration 156 — seed feeds + meatspace-streak widgets', () => {writeJson(layoutsPath, {activeLayoutId: 'default',layouts: [- { id: 'default', name: 'Everything', builtIn: true, widgets: ['feeds'], grid: [{ id: 'feeds', x: 8, y: 29, w: 3, h: 4 }] },+ { id: 'default', name: 'Everything', builtIn: true, widgets: ['feeds', 'tribe-care'], grid: [{ id: 'feeds', x: 8, y: 29, w: 3, h: 4 }, { id: 'tribe-care', x: 4, y: 29, w: 4, h: 4 }] },{ id: 'health', name: 'Health', builtIn: true, widgets: ['meatspace-streak'], grid: [{ id: 'meatspace-streak', x: 0, y: 9, w: 4, h: 4 }] },],});@@ -73,11 +75,13 @@ describe('migration 156 — seed feeds + meatspace-streak widgets', () => {],});const result = await migration.up({ rootDir });- expect(result.updated).toBe(1);+ // Two widgets seed into the built-in `default` layout (feeds + tribe-care).+ expect(result.updated).toBe(2);const after = readJson(layoutsPath);expect(after.layouts.find((l) => l.id === 'focus').widgets).toEqual(['cos']);expect(after.layouts.find((l) => l.id === 'my-default').widgets).toEqual(['cos']);expect(after.layouts.find((l) => l.id === 'default').widgets).toContain('feeds');+ expect(after.layouts.find((l) => l.id === 'default').widgets).toContain('tribe-care');});it('survives an unreadable JSON file', async () => {diff --git a/server/services/messageSync.js b/server/services/messageSync.jsindex 4c09e87e94..e9984a8085 100644--- a/server/services/messageSync.js+++ b/server/services/messageSync.js@@ -3,6 +3,7 @@ import { createHash } from 'crypto';import { join } from 'path';import { atomicWrite, ensureDir, filterBySearch as genericFilterBySearch, PATHS, safeDate, safeJSONParse, UUID_RE, tryReadFile } from '../lib/fileUtils.js';import { getAccount, updateSyncStatus } from './messageAccounts.js';+import { getUserTimezone, getLocalParts } from '../lib/timezone.js';import { v4 as uuidv4 } from '../lib/uuid.js';const CACHE_DIR = join(PATHS.messages, 'cache');@@ -348,6 +349,15 @@ function toIdentity(participant) {// a static import cycle. A no-op when nothing is tracked.export async function logMessageTouchpoints(account, messages = []) {const selfEmail = String(account?.email || '').trim().toLowerCase();+ // Derive the dedupe "calendar day" in the user's LOCAL timezone (matching the+ // Tribe cadence math in tribeCadence.daysSinceDate). Using the UTC day here+ // would split one local evening of contact across two days whenever a thread+ // straddles UTC midnight (common in the Americas), double-logging touchpoints.+ const timezone = await getUserTimezone();+ const localDay = (when) => {+ const p = getLocalParts(new Date(safeDate(when)), timezone);+ return `${p.year}-${String(p.month).padStart(2, '0')}-${String(p.day).padStart(2, '0')}`;+ };const candidates = [];for (const message of messages) {const participants = [message.from, ...(message.to || []), ...(message.cc || [])];@@ -363,7 +373,7 @@ export async function logMessageTouchpoints(account, messages = []) {});if (identities.length === 0) continue;const when = message.date || new Date().toISOString();- const day = new Date(safeDate(when)).toISOString().slice(0, 10);+ const day = localDay(when);const threadKey = message.threadId || message.id;candidates.push({identities,diff --git a/server/services/messageSync.test.js b/server/services/messageSync.test.jsindex 27b8a6cbcb..7bb7b0fe72 100644--- a/server/services/messageSync.test.js+++ b/server/services/messageSync.test.js@@ -52,6 +52,28 @@ vi.mock('./tribe.js', () => ({autoLogTouchpoints: vi.fn().mockResolvedValue({ created: 0, matched: 0 }),}));+// The dedupe day is derived in the user's LOCAL timezone. Mock the tz module+// self-contained (getUserTimezone → mockTimezone, default UTC so the existing+// UTC-day assertions hold; getLocalParts is a faithful Intl-based re-impl of the+// real one) — importActual would load the real module against the mocked+// fileUtils and fail on its settings read.+let mockTimezone = 'UTC';+vi.mock('../lib/timezone.js', () => ({+ getUserTimezone: vi.fn(async () => mockTimezone),+ getLocalParts: (utcDate, timezone) => {+ const parts = {};+ const fmt = new Intl.DateTimeFormat('en-US', {+ timeZone: timezone, year: 'numeric', month: '2-digit', day: '2-digit',+ hour: '2-digit', minute: '2-digit', hour12: false,+ });+ for (const { type, value } of fmt.formatToParts(utcDate)) parts[type] = value;+ return {+ year: parseInt(parts.year), month: parseInt(parts.month), day: parseInt(parts.day),+ hour: parts.hour === '24' ? 0 : parseInt(parts.hour), minute: parseInt(parts.minute),+ };+ },+}));+import { readdir, unlink } from 'fs/promises';import { tryReadFile as readFile, atomicWrite } from '../lib/fileUtils.js';import { getMessages, getMessage, syncAccount, deleteCache, getSyncStatus, refreshMessage, logMessageTouchpoints } from './messageSync.js';@@ -580,6 +602,7 @@ describe('logMessageTouchpoints — candidate building (#2033)', () => {beforeEach(() => {autoLogTouchpoints.mockClear();autoLogTouchpoints.mockResolvedValue({ created: 1, matched: 1 });+ mockTimezone = 'UTC';});it('builds a message candidate keyed per thread + day, excluding the account owner', async () => {@@ -631,4 +654,18 @@ describe('logMessageTouchpoints — candidate building (#2033)', () => {}]);expect(autoLogTouchpoints).not.toHaveBeenCalled();});++ it('derives the dedupe day in the user local timezone, not UTC', async () => {+ // 03:00Z on Jun 2 is still Jun 1 (20:00) in America/Los_Angeles. The dedupe+ // day must be the LOCAL day (2026-06-01) so a same-local-evening thread that+ // straddles UTC midnight collapses to one touchpoint, matching cadence math.+ mockTimezone = 'America/Los_Angeles';+ await logMessageTouchpoints(account, [{+ id: 'm5', threadId: 'thread-tz', subject: 'Evening',+ date: '2026-06-02T03:00:00Z',+ from: { name: 'Ada', email: '[email protected]' }, to: [], cc: [],+ }]);+ const [candidates] = autoLogTouchpoints.mock.calls[0];+ expect(candidates[0].dedupeKey).toBe(`msg:${VALID_UUID}:thread-tz:2026-06-01`);+ });});