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
feat: report Tribe emails/phones shared by more than one person
Bryandero98890440b401ef
diff --git a/client/src/pages/Tribe.jsx b/client/src/pages/Tribe.jsxindex 23e31a1c55..a693a4c86e 100644--- a/client/src/pages/Tribe.jsx+++ b/client/src/pages/Tribe.jsx@@ -1,6 +1,7 @@import { useEffect, useMemo, useRef, useState } from 'react';import { useSearchParams } from 'react-router';import {+ AlertTriangle,Calendar,Clock,Copy,@@ -24,6 +25,7 @@ import {import * as api from '../services/api';import socket from '../services/socket';import BrailleSpinner from '../components/BrailleSpinner';+import Banner from '../components/ui/Banner';import PageHeader from '../components/PageHeader';import { localDateStr } from '../components/meatspace/constants';import toast from '../components/ui/Toast';@@ -931,6 +933,10 @@ export default function Tribe() {// record a pending request and let the effect retry once the form mounts// instead of consuming the tick against an unmounted form.const pendingFocusRef = useRef(false);+ // Non-blocking duplicate-identifier report (#5908) — `null` until the first+ // fetch resolves, so "nothing yet" never briefly renders as "confirmed clean".+ const [duplicates, setDuplicates] = useState(null);+ const [duplicatesDismissed, setDuplicatesDismissed] = useState(false);const selectedId = draft.id;@@ -981,10 +987,14 @@ export default function Tribe() {let cancelled = false;const isCancelled = () => cancelled;loadContacts(isCancelled);+ const loadDuplicates = () => api.getTribeDuplicateIdentifiers({ silent: true })+ .then((report) => { if (!isCancelled()) setDuplicates(report); })+ .catch(() => { if (!isCancelled()) setDuplicates({ emails: [], phones: [] }); });+ loadDuplicates();// Mutations broadcast `tribe:changed` from the server; reconcile against// server truth (covers other tabs/devices and the GREATEST last-contact// merge that optimistic updates can't predict).- const handleChanged = () => loadContacts(isCancelled);+ const handleChanged = () => { loadContacts(isCancelled); loadDuplicates(); };socket.on('tribe:changed', handleChanged);return () => {cancelled = true;@@ -1136,6 +1146,8 @@ export default function Tribe() {setStatusFilter(DEFAULT_STATUS);};+ const duplicateGroups = [...(duplicates?.emails || []), ...(duplicates?.phones || [])];+const actions = (<buttontype="button"@@ -1188,6 +1200,35 @@ export default function Tribe() {<StatTile icon={Heart} label="Capacity" value={`${tribeCount}/150`} detail="village horizon" /></div>+ {duplicateGroups.length > 0 && !duplicatesDismissed && (+ <Banner+ tone="warning"+ icon={AlertTriangle}+ title="Shared contact info"+ actions={(+ <button+ type="button"+ onClick={() => setDuplicatesDismissed(true)}+ aria-label="Dismiss shared contact info notice"+ className="rounded p-1 text-port-warning/70 hover:text-port-warning"+ >+ <X size={14} aria-hidden="true" />+ </button>+ )}+ >+ {/* Non-blocking report (#5908): the same email/phone is on file for more+ than one person, so a routine sync can silently re-target every later+ touchpoint from one to the other. Naming it is the whole feature — this+ never merges or edits anyone automatically. */}+ {duplicateGroups.map((group) => (+ <div key={group.identifier}>+ <span className="font-mono">{group.identifier}</span> is on file for{' '}+ {group.people.map((p) => p.name).join(' and ')}.+ </div>+ ))}+ </Banner>+ )}+{activeTab === 'circle' && (<div className="grid gap-4 xl:grid-cols-[310px_minmax(0,1fr)_minmax(330px,420px)]">{/* Five ring meters are a dashboard, not the task — below xl theydiff --git a/client/src/pages/Tribe.test.jsx b/client/src/pages/Tribe.test.jsxindex 987c1b54f1..e1ca41698e 100644--- a/client/src/pages/Tribe.test.jsx+++ b/client/src/pages/Tribe.test.jsx@@ -7,6 +7,9 @@ vi.mock('../services/api', () => ({// OutreachQueue (care tab) fetches unanswered threads on mount (#2158).getTribeOutreach: vi.fn(() => Promise.resolve({ threads: [] })),createTribeTouchpoint: vi.fn(),+ // Non-blocking duplicate-identifier report (#5908); defaults to clean so+ // tests unrelated to it never see the banner.+ getTribeDuplicateIdentifiers: vi.fn(() => Promise.resolve({ emails: [], phones: [] })),}));vi.mock('../services/socket', () => ({@@ -164,3 +167,43 @@ describe('Tribe care filter', () => {expect(await screen.findByText('Last 2026-01-01')).toBeTruthy();});});++describe('Tribe shared-identifier banner (#5908)', () => {+ beforeEach(() => {+ api.getTribePeople.mockClear();+ api.getTribePeople.mockResolvedValue({ people: PEOPLE });+ api.getTribeDuplicateIdentifiers.mockReset();+ window.localStorage.clear();+ });++ it('renders nothing when the report comes back clean', async () => {+ api.getTribeDuplicateIdentifiers.mockResolvedValue({ emails: [], phones: [] });+ renderAt('/tribe');+ await screen.findByText('Example Person');+ expect(screen.queryByText(/shared contact info/i)).toBeNull();+ });++ it('names the colliding people for a shared email', async () => {+ api.getTribeDuplicateIdentifiers.mockResolvedValue({+ emails: [{ identifier: '[email protected]', people: [{ id: 'p1', name: 'Example Person' }, { id: 'p2', name: 'Sample Neighbor' }] }],+ phones: [],+ });+ renderAt('/tribe');++ expect(await screen.findByText(/shared contact info/i)).toBeTruthy();+ expect(screen.getByText('[email protected]')).toBeTruthy();+ expect(screen.getByText(/Example Person and Sample Neighbor/)).toBeTruthy();+ });++ it('dismisses on click and does not reappear until the next fetch', async () => {+ api.getTribeDuplicateIdentifiers.mockResolvedValue({+ emails: [{ identifier: '[email protected]', people: [{ id: 'p1', name: 'Example Person' }, { id: 'p2', name: 'Sample Neighbor' }] }],+ phones: [],+ });+ renderAt('/tribe');+ await screen.findByText(/shared contact info/i);++ fireEvent.click(screen.getByRole('button', { name: /dismiss shared contact info/i }));+ expect(screen.queryByText(/shared contact info/i)).toBeNull();+ });+});diff --git a/client/src/services/README.md b/client/src/services/README.mdindex 41494b1cca..659307605f 100644--- a/client/src/services/README.md+++ b/client/src/services/README.md@@ -82,7 +82,7 @@ toasts on throw). **Custom catch ⇒ `silent: true`** — otherwise toasts fire| `apiMeatspace.js` | MeatSpace health, genome, POST, memory-practice, and atomic POST training-run APIs. || `apiMortalLoom.js` | Mortality tracking. || `apiMoodBoard.js` | Mood boards (inspiration canvas + items). |-| `apiTribe.js` | Tribe people (relationship rings + contacts). |+| `apiTribe.js` | Tribe people (relationship rings + contacts), plus `getTribeDuplicateIdentifiers()` (`GET /tribe/duplicate-identifiers`): a non-blocking report of emails/phones shared by more than one person. || `apiTimeline.js` | Human-activity timeline: `/timeline/day`. || `apiCalendar.js` | Calendar events. || `apiMessages.js` | Messages / notifications + iMessage manager (#2413). |diff --git a/client/src/services/apiTribe.js b/client/src/services/apiTribe.jsindex 25628ce220..75bec21ba8 100644--- a/client/src/services/apiTribe.js+++ b/client/src/services/apiTribe.js@@ -8,6 +8,11 @@ export const getTribePeople = (options = {}) => {return request(`/tribe/people${qs ? `?${qs}` : ''}`, { silent: options.silent });};+// Emails/phones shared by more than one person (#5908) — a non-blocking report,+// never a merge. Read-only and cheap: safe to call on every Tribe page load.+export const getTribeDuplicateIdentifiers = (options = {}) =>+ request('/tribe/duplicate-identifiers', { silent: options.silent });+export const getTribeCareSummary = (options = {}) => {const params = new URLSearchParams();if (options.limit) params.set('limit', String(options.limit));diff --git a/server/routes/tribe.js b/server/routes/tribe.jsindex 4517c078fe..d31010b75f 100644--- a/server/routes/tribe.js+++ b/server/routes/tribe.js@@ -117,6 +117,13 @@ router.get('/care', asyncHandler(async (req, res) => {res.json(summary);}));+// Report of emails/phones shared by more than one person (#5908). `tribe_people` has+// no uniqueness on those columns, so a routine sync can silently re-target a shared+// identifier from one person to the other. Detection only — never merges or writes.+router.get('/duplicate-identifiers', asyncHandler(async (req, res) => {+ res.json(await tribe.checkDuplicateTribeIdentifiers());+}));+// Unanswered inbound threads from Tribe people, detected from the activity// timeline (#2158). Detection only — NO LLM. Feeds the Tribe Outreach panel and// mirrors the `tribe_unanswered` proactive alert.diff --git a/server/routes/tribe.test.js b/server/routes/tribe.test.jsindex 57e58c4cce..4850839688 100644--- a/server/routes/tribe.test.js+++ b/server/routes/tribe.test.js@@ -12,6 +12,7 @@ errorEvents.on('error', () => {});vi.mock('../services/tribe.js', () => ({listPeople: vi.fn(),getCareSummary: vi.fn(),+ checkDuplicateTribeIdentifiers: vi.fn(),getPerson: vi.fn(),createPerson: vi.fn(),updatePerson: vi.fn(),@@ -69,6 +70,16 @@ describe('Tribe Routes', () => {expect(tribe.getCareSummary).toHaveBeenCalledWith(50); // clamped from 999});+ it('returns the duplicate-identifiers report', async () => {+ const report = { emails: [{ identifier: '[email protected]', people: [{ id: 'p1', name: 'Ada' }, { id: 'p2', name: 'Bea' }] }], phones: [] };+ tribe.checkDuplicateTribeIdentifiers.mockResolvedValue(report);++ const response = await request(app).get('/api/tribe/duplicate-identifiers');++ expect(response.status).toBe(200);+ expect(response.body).toEqual(report);+ });+it('creates a person and emits tribe changes', async () => {tribe.createPerson.mockResolvedValue({ id: PERSON_ID, name: 'Ada', ring: 'core' });diff --git a/server/services/tribe.js b/server/services/tribe.jsindex f1c88eda04..0ead628b74 100644--- a/server/services/tribe.js+++ b/server/services/tribe.js@@ -206,6 +206,53 @@ export async function getCareSummary(limit = 5) {};}+/**+ * Identifiers (emails/phones) held by more than one tracked person, using the SAME+ * normalization the matcher uses — so a case-only email variant or a formatting-only+ * phone variant collides here exactly as it would during identity matching.+ *+ * Pure and non-blocking by design (#5908): `tribe_people` has no uniqueness on+ * `emails[]`/`phones[]`, and nothing checks across rows, so two people can end up+ * sharing one. When that happens, `buildPersonMatchIndex` (`lib/tribeMatch.js`) keeps+ * whichever person it sees first — and `listPeople`'s sort key includes+ * `last_contact_on`, which routine auto-logging advances, so a shared identifier can+ * silently re-target from one person to the other on a later sync. This is a report+ * only: it never merges, writes, or blocks a save.+ *+ * @param {Array<{id: string, name: string, emails?: string[], phones?: string[]}>} people+ * Already-loaded, non-deleted people — `listPeople()` already filters `deleted = FALSE`.+ */+export function findDuplicateTribeIdentifiers(people) {+ const collect = (getRaw, normalize) => {+ const owners = new Map(); // normalized identifier -> [{id, name}]+ for (const person of people || []) {+ // One hit per person per identifier — a person listing the same email twice in+ // different casings must not count as two "owners" of it.+ const seen = new Set();+ for (const raw of getRaw(person) || []) {+ const key = normalize(raw);+ if (!key || seen.has(key)) continue;+ seen.add(key);+ if (!owners.has(key)) owners.set(key, []);+ owners.get(key).push({ id: person.id, name: person.name });+ }+ }+ return [...owners.entries()]+ .filter(([, owned]) => owned.length > 1)+ .map(([identifier, owned]) => ({ identifier, people: owned }));+ };+ return {+ emails: collect((p) => p.emails, normalizeIdentifier),+ phones: collect((p) => p.phones, normalizePhone),+ };+}++/** DB-backed wrapper for the route: loads every tracked person and runs the pure+ * detector above. */+export async function checkDuplicateTribeIdentifiers() {+ return findDuplicateTribeIdentifiers(await listPeople());+}+export async function listPeople(options = {}) {await ensureReady();const conditions = ['deleted = FALSE'];diff --git a/server/services/tribe.test.js b/server/services/tribe.test.jsindex 046e20790b..ded07539a2 100644--- a/server/services/tribe.test.js+++ b/server/services/tribe.test.js@@ -25,6 +25,8 @@ import {getCareSummary,autoLogTouchpoints,DEFAULT_RING_CADENCE,+ findDuplicateTribeIdentifiers,+ checkDuplicateTribeIdentifiers,} from './tribe.js';// ISO date (YYYY-MM-DD) `n` whole days before local today.@@ -449,3 +451,65 @@ describe('tribe service — autoLogTouchpoints', () => {expect(query).not.toHaveBeenCalled();});});++describe('tribe service — findDuplicateTribeIdentifiers (#5908)', () => {+ it('flags an email shared by two people, case-insensitively', () => {+ const report = findDuplicateTribeIdentifiers([+ { id: 'p1', name: 'Ada', emails: ['[email protected]'], phones: [] },+ { id: 'p2', name: 'Bea', emails: ['[email protected]'], phones: [] },+ ]);+ expect(report.emails).toEqual([+ { identifier: '[email protected]', people: [{ id: 'p1', name: 'Ada' }, { id: 'p2', name: 'Bea' }] },+ ]);+ expect(report.phones).toEqual([]);+ });++ it('flags a phone shared by two people despite different formatting', () => {+ const report = findDuplicateTribeIdentifiers([+ { id: 'p1', name: 'Ada', emails: [], phones: ['(555) 010-0199'] },+ { id: 'p2', name: 'Bea', emails: [], phones: ['+15550100199'] },+ ]);+ expect(report.phones).toEqual([+ { identifier: '+15550100199', people: [{ id: 'p1', name: 'Ada' }, { id: 'p2', name: 'Bea' }] },+ ]);+ });++ it('does not flag a person against themself, even with a near-duplicate raw value', () => {+ const report = findDuplicateTribeIdentifiers([+ { id: 'p1', name: 'Ada', emails: ['[email protected]', '[email protected]'], phones: [] },+ ]);+ expect(report.emails).toEqual([]);+ });++ it('reports nothing for a unique roster', () => {+ const report = findDuplicateTribeIdentifiers([+ { id: 'p1', name: 'Ada', emails: ['[email protected]'], phones: ['+15551234567'] },+ { id: 'p2', name: 'Bea', emails: ['[email protected]'], phones: ['+15557654321'] },+ ]);+ expect(report).toEqual({ emails: [], phones: [] });+ });++ it('handles an empty roster', () => {+ expect(findDuplicateTribeIdentifiers([])).toEqual({ emails: [], phones: [] });+ expect(findDuplicateTribeIdentifiers(undefined)).toEqual({ emails: [], phones: [] });+ });+});++describe('tribe service — checkDuplicateTribeIdentifiers', () => {+ beforeEach(() => {+ query.mockReset();+ });++ it('loads through listPeople (soft-deleted people already excluded) and reduces to a report', async () => {+ query.mockResolvedValue({ rows: [+ { id: 'p1', name: 'Ada', ring: 'core', cadence_days: 21, emails: ['[email protected]'] },+ { id: 'p2', name: 'Bea', ring: 'core', cadence_days: 21, emails: ['[email protected]'] },+ ] });+ const report = await checkDuplicateTribeIdentifiers();+ const [sql] = query.mock.calls[0];+ expect(sql).toContain('deleted = FALSE');+ expect(report.emails).toEqual([+ { identifier: '[email protected]', people: [{ id: 'p1', name: 'Ada' }, { id: 'p2', name: 'Bea' }] },+ ]);+ });+});