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: erase imported Timeline data per source with typed confirmation (#12987)
[._.]/ Adam Eivyb4bfc44a0750
diff --git a/client/src/components/timeline/ManageImportedDataPanel.jsx b/client/src/components/timeline/ManageImportedDataPanel.jsxnew file mode 100644index 0000000000..0290bf9fd3--- /dev/null+++ b/client/src/components/timeline/ManageImportedDataPanel.jsx@@ -0,0 +1,82 @@+import { useEffect, useState } from 'react';+import { Trash2, Loader2 } from 'lucide-react';+import * as api from '../../services/api';+import toast from '../ui/Toast';+import { formatCount, formatDateNumeric } from '../../utils/formatters';++// Per-source counts with a typed-confirmation erase (#12987). Deleting is+// irreversible locally, but importers are idempotent so re-importing the same+// export restores the rows. `onChanged` lets the page refresh the day view.+export default function ManageImportedDataPanel({ reloadKey, onChanged }) {+ const [sources, setSources] = useState([]);+ const [target, setTarget] = useState(null);+ const [typed, setTyped] = useState('');+ const [busy, setBusy] = useState(false);++ useEffect(() => {+ api.getTimelineSources({ silent: true }).then((r) => setSources(r?.sources || [])).catch(() => {});+ }, [reloadKey]);++ const cancel = () => { setTarget(null); setTyped(''); };++ const erase = async () => {+ setBusy(true);+ const result = await api.eraseTimelineSource(target).catch(() => null);+ setBusy(false);+ if (!result) return;+ toast.success(`Deleted ${formatCount(result.deleted)} ${target} event(s)`);+ setSources((list) => list.filter((s) => s.source !== target));+ cancel();+ onChanged?.();+ };++ if (sources.length === 0) return null;++ return (+ <div className="rounded border border-port-border bg-port-card p-3 text-xs">+ <div className="mb-2 font-medium text-gray-300">Manage imported data</div>+ <ul className="space-y-2">+ {sources.map((s) => (+ <li key={s.source}>+ <div className="flex flex-wrap items-center gap-2">+ <span className="font-mono text-gray-200">{s.source}</span>+ <span className="text-gray-400">+ {formatCount(s.eventCount)} events+ {s.earliestAt && ` · ${formatDateNumeric(s.earliestAt)} – ${formatDateNumeric(s.latestAt)}`}+ </span>+ <button+ type="button"+ onClick={() => { setTarget(s.source); setTyped(''); }}+ className="ml-auto inline-flex items-center gap-1 rounded border border-port-border px-2 py-1 text-port-error hover:border-port-error"+ >+ <Trash2 size={12} /> Delete+ </button>+ </div>+ {target === s.source && (+ <div className="mt-2 flex flex-wrap items-center gap-2">+ <label htmlFor={`erase-${s.source}`} className="text-gray-400">+ Type <span className="font-mono text-gray-200">{s.source}</span> to delete all {formatCount(s.eventCount)} events+ </label>+ <input+ id={`erase-${s.source}`}+ value={typed}+ onChange={(e) => setTyped(e.target.value)}+ className="rounded border border-port-border bg-port-bg px-2 py-1 text-gray-200"+ />+ <button+ type="button"+ disabled={typed !== s.source || busy}+ onClick={erase}+ className="inline-flex items-center gap-1 rounded bg-port-error px-2 py-1 text-white disabled:opacity-40"+ >+ {busy && <Loader2 size={12} className="animate-spin" />} Confirm delete+ </button>+ <button type="button" onClick={cancel} className="px-2 py-1 text-gray-400 hover:text-gray-200">Cancel</button>+ </div>+ )}+ </li>+ ))}+ </ul>+ </div>+ );+}diff --git a/client/src/components/timeline/TimelineImportPanels.jsx b/client/src/components/timeline/TimelineImportPanels.jsxindex 48f3120fb4..021a0479a5 100644--- a/client/src/components/timeline/TimelineImportPanels.jsx+++ b/client/src/components/timeline/TimelineImportPanels.jsx@@ -5,6 +5,7 @@ import WhatsappImportPanel from './WhatsappImportPanel';import BrowserHistoryImportPanel from './BrowserHistoryImportPanel';import YoutubeImportPanel from './YoutubeImportPanel';import GmailMboxImportPanel from './GmailMboxImportPanel';+import ManageImportedDataPanel from './ManageImportedDataPanel';// The one-time bulk-backfill importers (#2160), grouped behind a single// disclosure on /timeline (#3789). They used to render permanently at full@@ -26,10 +27,13 @@ const PANELS = [// says how much is behind it.export const IMPORT_SOURCE_COUNT = PANELS.length;-export default function TimelineImportPanels({ onImported }) {+export default function TimelineImportPanels({ onImported, reloadKey }) {return (- <div className="grid gap-2 sm:grid-cols-2">- {PANELS.map(({ id, Component }) => <Component key={id} onImported={onImported} />)}+ <div className="space-y-2">+ <div className="grid gap-2 sm:grid-cols-2">+ {PANELS.map(({ id, Component }) => <Component key={id} onImported={onImported} />)}+ </div>+ <ManageImportedDataPanel reloadKey={reloadKey} onChanged={onImported} /></div>);}diff --git a/client/src/pages/Timeline.jsx b/client/src/pages/Timeline.jsxindex 856e212041..0907a21f9b 100644--- a/client/src/pages/Timeline.jsx+++ b/client/src/pages/Timeline.jsx@@ -237,7 +237,7 @@ export default function Timeline() {own) keeps the panels mounted while collapsed — a Tailwind `hidden`class on the grid itself would fight the grid display utility. */}<div id="timeline-import-panels" ref={importsRef} hidden={!showImports}>- <TimelineImportPanels onImported={() => setReloadKey((k) => k + 1)} />+ <TimelineImportPanels reloadKey={reloadKey} onImported={() => setReloadKey((k) => k + 1)} /></div><Histogram histogram={histogram} />diff --git a/client/src/pages/Timeline.test.jsx b/client/src/pages/Timeline.test.jsxindex 87119f09a8..2d3de66593 100644--- a/client/src/pages/Timeline.test.jsx+++ b/client/src/pages/Timeline.test.jsx@@ -10,6 +10,8 @@ vi.mock('../services/api', () => ({counts: { total: 0, bySource: {}, byKind: {} },histogram: Array.from({ length: 24 }, (_, hour) => ({ hour, count: 0 })),})),+ getTimelineSources: vi.fn(() => Promise.resolve({ sources: [] })),+ eraseTimelineSource: vi.fn(),importSpotifyHistory: vi.fn(),importTakeoutLocationHistory: vi.fn(),importDiscordHistory: vi.fn(),diff --git a/client/src/services/apiTimeline.js b/client/src/services/apiTimeline.jsindex d151deb1a7..8285a4f8c8 100644--- a/client/src/services/apiTimeline.js+++ b/client/src/services/apiTimeline.js@@ -76,3 +76,15 @@ export const importGmailMbox = ({ path, preview = false, yourEmail, ...options }}),...options,});++// Per-source event counts + date range, and user-driven erasure of one source.+export const getTimelineSources = (options = {}) =>+ request('/timeline/sources', { silent: options.silent });++export const eraseTimelineSource = (source, { from, to, kind } = {}) => {+ const params = new URLSearchParams({ source });+ if (from) params.set('from', from);+ if (to) params.set('to', to);+ if (kind) params.set('kind', kind);+ return request(`/timeline/events?${params}`, { method: 'DELETE' });+};diff --git a/server/routes/timeline.js b/server/routes/timeline.jsindex 32387195d5..b954b493cd 100644--- a/server/routes/timeline.js+++ b/server/routes/timeline.js@@ -103,6 +103,20 @@ const eventsQuerySchema = z.object({limit: z.coerce.number().int().min(1).max(2000).optional(),});+// Sources the Timeline store can hold; erasure is limited to these so a typo+// 400s instead of reporting a successful zero-row delete.+export const ERASABLE_SOURCES = [+ 'browser', 'calendar', 'discord', 'gmail', 'google-calendar', 'imessage',+ 'location', 'outlook', 'outlook-calendar', 'signal', 'spotify', 'whatsapp', 'youtube',+];++const eraseQuerySchema = z.object({+ source: z.enum(ERASABLE_SOURCES),+ kind: z.string().max(64).optional(),+ from: z.string().datetime().optional(),+ to: z.string().datetime().optional(),+});+// Day view — all activity on a local calendar day plus an hourly histogram and// source/kind tallies. `date` (YYYY-MM-DD) defaults to today in the user's tz;// the URL is the source of truth for the selected day on the /timeline page.@@ -119,6 +133,18 @@ router.get('/events', asyncHandler(async (req, res) => {res.json({ events });}));+// Per-source counts and date range — what "Manage imported data" shows before a delete.+router.get('/sources', asyncHandler(async (req, res) => {+ res.json({ sources: await humanActivity.listSourceCounts() });+}));++// Erase one source's events (optionally a kind / from–to range). `source` is+// required; there is no way to wipe every source in one call.+router.delete('/events', asyncHandler(async (req, res) => {+ const filters = validateRequest(eraseQuerySchema, req.query);+ res.json(await humanActivity.eraseEvents(filters));+}));+// Shared handler for the bulk-backfill importers (#2160). Each accepts a ZIP or// single JSON via multipart upload; `preview=true` parses + summarizes without// writing; a real import is idempotent (dedupe key per source), so re-importsdiff --git a/server/routes/timeline.test.js b/server/routes/timeline.test.jsindex 13cd4560e8..d774a09888 100644--- a/server/routes/timeline.test.js+++ b/server/routes/timeline.test.js@@ -74,6 +74,8 @@ vi.mock('../services/gmailMboxImport.js', () => ({vi.mock('../services/humanActivity.js', () => ({getDaySummary: vi.fn(async () => ({ date: '2026-07-07', events: [] })),listEvents: vi.fn(async () => []),+ eraseEvents: vi.fn(async () => ({ deleted: 4 })),+ listSourceCounts: vi.fn(async () => [{ source: 'location', eventCount: 4, earliestAt: null, latestAt: null }]),}));import { importSpotifyHistory } from '../services/spotifyImport.js';@@ -82,6 +84,7 @@ import { importDiscordHistory } from '../services/discordImport.js';import { importWhatsappHistory } from '../services/whatsappImport.js';import { importBrowserHistory } from '../services/browserHistoryImport.js';import { importGmailMbox } from '../services/gmailMboxImport.js';+import * as humanActivity from '../services/humanActivity.js';import timelineRoutes from './timeline.js';function makeApp() {@@ -444,3 +447,27 @@ describe('timeline import routes', () => {expect(importGmailMbox).not.toHaveBeenCalled();});});++describe('timeline erase routes (#12987)', () => {+ let app;+ beforeEach(() => { app = makeApp(); vi.clearAllMocks(); });++ it('DELETE /events erases one source with its range and returns the count', async () => {+ const r = await request(app).delete('/api/timeline/events?source=location&from=2026-01-01T00:00:00.000Z');+ expect(r.status).toBe(200);+ expect(r.body).toEqual({ deleted: 4 });+ expect(humanActivity.eraseEvents).toHaveBeenCalledWith({ source: 'location', from: '2026-01-01T00:00:00.000Z' });+ });++ it('rejects a missing or unknown source without deleting', async () => {+ expect((await request(app).delete('/api/timeline/events')).status).toBe(400);+ expect((await request(app).delete('/api/timeline/events?source=nope')).status).toBe(400);+ expect(humanActivity.eraseEvents).not.toHaveBeenCalled();+ });++ it('GET /sources lists per-source counts', async () => {+ const r = await request(app).get('/api/timeline/sources');+ expect(r.status).toBe(200);+ expect(r.body.sources[0].source).toBe('location');+ });+});diff --git a/server/services/humanActivity.db.test.js b/server/services/humanActivity.db.test.jsindex 3f9bee4dfe..9fe5a017d0 100644--- a/server/services/humanActivity.db.test.js+++ b/server/services/humanActivity.db.test.js@@ -18,7 +18,7 @@ import { requireDbOrSkip } from '../lib/dbTestGate.js';const tzState = vi.hoisted(() => ({ tz: 'UTC' }));vi.mock('./userTimezone.js', () => ({ getUserTimezone: async () => tzState.tz }));-import { recordEvents, listEvents, getDaySummary, stripParticipantsForAccount, countEventsByHandle } from './humanActivity.js';+import { recordEvents, listEvents, getDaySummary, stripParticipantsForAccount, countEventsByHandle, eraseEvents, listSourceCounts } from './humanActivity.js';let dbReady = false;let skipReason = '';@@ -393,3 +393,34 @@ describe.skipIf(!runDb)('countEventsByHandle — SQL-aggregated handle frequencyexpect(rows).toEqual([]);});});++describe.skipIf(!runDb)('eraseEvents — user-driven source erasure (#12987)', () => {+ const ERASE_SOURCE = `test-${nonce}-erase`;+ const KEEP_SOURCE = `test-${nonce}-keep`;+ afterAll(async () => {+ if (dbReady) await query('DELETE FROM human_activity_events WHERE source = ANY($1::text[])', [[ERASE_SOURCE, KEEP_SOURCE]]).catch(() => {});+ });++ it('erases only the named source, honors a range, refuses a missing source, and re-import restores', async () => {+ const rows = [+ mk({ source: ERASE_SOURCE, dedupeKey: 'e-1', happenedAt: '2026-01-01T10:00:00Z' }),+ mk({ source: ERASE_SOURCE, dedupeKey: 'e-2', happenedAt: '2026-03-01T10:00:00Z' }),+ mk({ source: KEEP_SOURCE, dedupeKey: 'k-1' }),+ ];+ await recordEvents(rows);++ expect(await eraseEvents({})).toEqual({ deleted: 0 });+ expect((await listSourceCounts()).find((s) => s.source === ERASE_SOURCE).eventCount).toBe(2);++ const ranged = await eraseEvents({ source: ERASE_SOURCE, to: '2026-02-01T00:00:00Z' });+ expect(ranged.deleted).toBe(1);+ expect(await listEvents({ source: ERASE_SOURCE })).toHaveLength(1);++ const all = await eraseEvents({ source: ERASE_SOURCE });+ expect(all.deleted).toBe(1);+ expect(await listEvents({ source: KEEP_SOURCE })).toHaveLength(1);++ const again = await recordEvents(rows.slice(0, 2));+ expect(again.recorded).toBe(2);+ });+});diff --git a/server/services/humanActivity.js b/server/services/humanActivity.jsindex 838041c343..2388bd2619 100644--- a/server/services/humanActivity.js+++ b/server/services/humanActivity.js@@ -534,6 +534,47 @@ export async function deleteEvents({ ids, source, chatGuid, handle, accountId }return { deleted };}+/**+ * User-driven erasure of one source's events (#12987), optionally limited to a+ * `kind` and a `from` (inclusive) / `to` (exclusive) range. `source` is+ * required so a single call can never wipe the whole table. Importers are+ * idempotent, so re-importing the same export restores erased rows.+ */+export async function eraseEvents({ source, kind, from, to } = {}) {+ if (!source) return { deleted: 0 };+ await ensureReady();+ const params = [String(source)];+ const clauses = ['source = $1'];+ if (kind) { params.push(String(kind)); clauses.push(`kind = ${params.length}`); }+ if (from) { params.push(new Date(from).toISOString()); clauses.push(`happened_at >= ${params.length}`); }+ if (to) { params.push(new Date(to).toISOString()); clauses.push(`happened_at < ${params.length}`); }+ const result = await query(+ `DELETE FROM human_activity_events WHERE ${clauses.join(' AND ')}`,+ params,+ );+ const deleted = result.rowCount || 0;+ console.log(`🗓️ Erased ${deleted} activity event(s) (source=${source})`);+ return { deleted };+}++/** Per-source event counts and date range, for the "Manage imported data" panel. */+export async function listSourceCounts() {+ await ensureReady();+ const result = await query(+ `SELECT source, COUNT(*)::int AS event_count, MIN(happened_at) AS earliest_at, MAX(happened_at) AS latest_at+ FROM human_activity_events+ GROUP BY source+ ORDER BY source`,+ );+ const iso = (v) => (v instanceof Date ? v.toISOString() : (v || null));+ return result.rows.map((row) => ({+ source: row.source,+ eventCount: Number(row.event_count) || 0,+ earliestAt: iso(row.earliest_at),+ latestAt: iso(row.latest_at),+ }));+}+/*** Aggregate conversations for a single source (iMessage, Signal, …) grouped by* `metadata.chatGuid`. Newest activity first. Optional free-text `q` filters