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: preserve local dates across touchpoint reloads (#4919)
[._.]/ Adam Eivy409d5b803650
diff --git a/client/src/components/calendar/ReviewTab.jsx b/client/src/components/calendar/ReviewTab.jsxindex 051aa1b5e8..caa820cb34 100644--- a/client/src/components/calendar/ReviewTab.jsx+++ b/client/src/components/calendar/ReviewTab.jsx@@ -28,7 +28,7 @@ export default function ReviewTab() {const changeDate = (delta) => {const d = new Date(date + 'T12:00:00');d.setDate(d.getDate() + delta);- setDate(d.toISOString().slice(0, 10));+ setDate(localDateStr(d));};const handleConfirm = async (event, happened) => {diff --git a/client/src/components/calendar/ReviewTab.test.jsx b/client/src/components/calendar/ReviewTab.test.jsxindex 0fd8c6c70d..638302b31d 100644--- a/client/src/components/calendar/ReviewTab.test.jsx+++ b/client/src/components/calendar/ReviewTab.test.jsx@@ -1,4 +1,4 @@-import { render, screen, waitFor } from '@testing-library/react';+import { fireEvent, render, screen, waitFor } from '@testing-library/react';import { afterEach, describe, expect, it, vi } from 'vitest';vi.mock('../../services/api', () => ({@@ -15,6 +15,7 @@ import ReviewTab from './ReviewTab';describe('ReviewTab', () => {afterEach(() => {vi.useRealTimers();+ process.env.TZ = 'UTC';});it('defaults to the local calendar date', async () => {@@ -26,4 +27,17 @@ describe('ReviewTab', () => {expect(screen.getByLabelText('Review date').value).toBe('2026-01-01');expect(screen.queryByRole('button', { name: 'Today' })).toBeNull();});++ it('navigates by local calendar day in positive UTC offsets', async () => {+ process.env.TZ = 'Pacific/Kiritimati';+ vi.setSystemTime(new Date(2026, 0, 1, 20));++ render(<ReviewTab />);+ await waitFor(() => expect(api.getDailyReview).toHaveBeenCalledWith('2026-01-01'));++ fireEvent.click(screen.getByRole('button', { name: 'Next' }));++ await waitFor(() => expect(api.getDailyReview).toHaveBeenCalledWith('2026-01-02'));+ expect(screen.getByLabelText('Review date').value).toBe('2026-01-02');+ });});diff --git a/client/src/pages/Tribe.jsx b/client/src/pages/Tribe.jsxindex dce5da7a25..6510ed6b44 100644--- a/client/src/pages/Tribe.jsx+++ b/client/src/pages/Tribe.jsx@@ -1111,9 +1111,11 @@ export default function Tribe() {};const logTouch = async (id) => {- const date = localDateStr();+ const now = new Date();+ const date = localDateStr(now);const result = await api.createTribeTouchpoint(id, {- happenedAt: new Date().toISOString(),+ happenedAt: now.toISOString(),+ localDate: date,channel: contacts.find((contact) => contact.id === id)?.channel || '',summary: 'Manual touchpoint',source: 'user',diff --git a/client/src/pages/Tribe.test.jsx b/client/src/pages/Tribe.test.jsxindex b370432479..17fe8800be 100644--- a/client/src/pages/Tribe.test.jsx+++ b/client/src/pages/Tribe.test.jsx@@ -156,7 +156,11 @@ describe('Tribe care filter', () => {await screen.findByText('Example Person');fireEvent.click(screen.getAllByRole('button', { name: 'Touch' })[0]);- await waitFor(() => expect(api.createTribeTouchpoint).toHaveBeenCalled());+ await waitFor(() => expect(api.createTribeTouchpoint).toHaveBeenCalledWith(+ 'p1',+ expect.objectContaining({ localDate: '2026-01-01' }),+ { silent: true },+ ));expect(screen.getByText('Last 2026-01-01')).toBeTruthy();});});diff --git a/server/routes/tribe.js b/server/routes/tribe.jsindex 95afca5ffe..4517c078fe 100644--- a/server/routes/tribe.js+++ b/server/routes/tribe.js@@ -40,6 +40,7 @@ const personUpdateSchema = partialWithoutDefaults(personSchema).extend({const touchpointSchema = z.object({happenedAt: z.string().datetime().optional(),+ localDate: z.string().regex(/^\d{4}-\d{2}-\d{2}$/).optional(),channel: z.string().max(200).optional().default(''),summary: z.string().max(2000).optional().default(''),source: z.enum(['user', 'calendar', 'message', 'import']).optional().default('user'),diff --git a/server/routes/tribe.test.js b/server/routes/tribe.test.jsindex 9a23b29cca..57e58c4cce 100644--- a/server/routes/tribe.test.js+++ b/server/routes/tribe.test.js@@ -125,6 +125,7 @@ describe('Tribe Routes', () => {.post(`/api/tribe/people/${PERSON_ID}/touchpoints`).send({happenedAt: '2026-06-18T15:00:00.000Z',+ localDate: '2026-06-19',source: 'calendar',calendarAccountId: ACCOUNT_ID,calendarEventId: 'event-1',@@ -135,12 +136,22 @@ describe('Tribe Routes', () => {expect(response.body.calendarEventId).toBe('event-1');expect(tribe.createTouchpoint).toHaveBeenCalledWith(PERSON_ID, expect.objectContaining({source: 'calendar',+ localDate: '2026-06-19',calendarAccountId: ACCOUNT_ID,calendarEventId: 'event-1',metadata: { title: 'Walk' },}));});+ it('rejects an invalid local date on a manual touchpoint', async () => {+ const response = await request(app)+ .post(`/api/tribe/people/${PERSON_ID}/touchpoints`)+ .send({ localDate: '06/19/2026' });++ expect(response.status).toBe(400);+ expect(tribe.createTouchpoint).not.toHaveBeenCalled();+ });+it('creates touchpoints from calendar events', async () => {tribe.createCalendarTouchpoint.mockResolvedValue({id: 'touch-2',diff --git a/server/services/tribe.js b/server/services/tribe.jsindex 51408f7659..7e9efc73c8 100644--- a/server/services/tribe.js+++ b/server/services/tribe.js@@ -335,6 +335,8 @@ export async function createTouchpoint(personId, data = {}) {await ensureReady();const person = await getPerson(personId);if (!person) throw new ServerError('Person not found', { status: 404 });+ const happenedAt = data.happenedAt || new Date().toISOString();+ const contactDate = data.localDate || happenedAt;return withTransaction(async (client) => {const result = await client.query(@@ -346,7 +348,7 @@ export async function createTouchpoint(personId, data = {}) {[data.id || uuidv4(),personId,- data.happenedAt || new Date().toISOString(),+ happenedAt,data.channel || '',data.summary || '',data.source || 'user',@@ -362,7 +364,7 @@ export async function createTouchpoint(personId, data = {}) {channel = CASE WHEN $3::text = '' THEN channel ELSE $3::text END,updated_at = NOW()WHERE id = $1`,- [personId, data.happenedAt || new Date().toISOString(), data.channel || ''],+ [personId, contactDate, data.channel || ''],);return rowToTouchpoint(result.rows[0]);});diff --git a/server/services/tribe.test.js b/server/services/tribe.test.jsindex 837d3bdcbc..37f32debcd 100644--- a/server/services/tribe.test.js+++ b/server/services/tribe.test.js@@ -13,6 +13,7 @@ import { query, withTransaction } from '../lib/db.js';import {listPeople,createPerson,+ createTouchpoint,normalizeTags,normalizeEmails,isoDate,@@ -167,6 +168,32 @@ describe('tribe service — listPeople query builder', () => {});});+describe('tribe service — createTouchpoint', () => {+ beforeEach(() => {+ query.mockReset();+ withTransaction.mockReset();+ });++ it('persists the browser-local date independently from the UTC timestamp', async () => {+ query.mockResolvedValue({ rows: [{ id: 'person-1', name: 'Example Person', ring: 'tribe', cadence_days: 45 }] });+ const clientQuery = vi.fn()+ .mockResolvedValueOnce({ rows: [{ id: 'touch-1', person_id: 'person-1', happened_at: '2026-01-02T04:00:00.000Z' }] })+ .mockResolvedValueOnce({ rows: [] });+ withTransaction.mockImplementation(async (fn) => fn({ query: clientQuery }));++ await createTouchpoint('person-1', {+ happenedAt: '2026-01-02T04:00:00.000Z',+ localDate: '2026-01-01',+ });++ expect(clientQuery).toHaveBeenNthCalledWith(+ 2,+ expect.stringContaining('SET last_contact_on'),+ ['person-1', '2026-01-01', ''],+ );+ });+});+describe('tribe service — personCadenceStatus', () => {it('external people are never overdue', () => {expect(personCadenceStatus({ ring: 'external', lastContact: daysAgo(999), cadenceDays: 7 }))