From 3644885b396cea70a1c3cf0adc4582b1fabef111 Mon Sep 17 00:00:00 2001 From: Alice Hernandez Date: Mon, 15 Jun 2026 22:43:15 +1000 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20don't=20record=20unless=20we're?= =?UTF-8?q?=20actually=20working.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/fix-ghost-sessions.mjs | 27 +++++++++++++++++++ .../components/Editor/MarkdownEditor.tsx | 4 +-- 2 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 scripts/fix-ghost-sessions.mjs diff --git a/scripts/fix-ghost-sessions.mjs b/scripts/fix-ghost-sessions.mjs new file mode 100644 index 0000000..d994e12 --- /dev/null +++ b/scripts/fix-ghost-sessions.mjs @@ -0,0 +1,27 @@ +#!/usr/bin/env node +// One-time migration: remove ghost sessions created by clicking into a document +// without typing. These have activeMs === 0 (no keystrokes recorded). + +import { readFileSync, writeFileSync, copyFileSync } from 'fs' + +const TELEMETRY = `${process.env.HOME}/Library/Application Support/Borges/.borges/telemetry.json` +const BACKUP = TELEMETRY + '.ghost-bak' + +const sessions = JSON.parse(readFileSync(TELEMETRY, 'utf-8')) + +const ghosts = sessions.filter(s => s.activeMs === 0) +const cleaned = sessions.filter(s => s.activeMs > 0) + +if (ghosts.length === 0) { + console.log('No ghost sessions found.') + process.exit(0) +} + +for (const s of ghosts) { + console.log(`Removing ghost session ${s.id} (${s.storyId}) date=${s.date} words ${s.wordsStart}→${s.wordsEnd}`) +} + +copyFileSync(TELEMETRY, BACKUP) +console.log(`\nBacked up to ${BACKUP}`) +writeFileSync(TELEMETRY, JSON.stringify(cleaned, null, 2), 'utf-8') +console.log(`Done. Removed ${ghosts.length} ghost session(s) → ${cleaned.length} total (was ${sessions.length}).`) diff --git a/src/renderer/components/Editor/MarkdownEditor.tsx b/src/renderer/components/Editor/MarkdownEditor.tsx index f03183e..74be477 100644 --- a/src/renderer/components/Editor/MarkdownEditor.tsx +++ b/src/renderer/components/Editor/MarkdownEditor.tsx @@ -128,8 +128,8 @@ export function MarkdownEditor(): JSX.Element { const wpm = activeMs > 0 ? Math.round(Math.max(0, typedWords) / (activeMs / 60_000)) : 0 sessionRef.current = null if (flushTimerRef.current) { clearTimeout(flushTimerRef.current); flushTimerRef.current = null } - // Only persist if something was actually written - if (wordsEnd - s.wordsStart <= 0 && durationMs < 5000) return + // Only persist if the user actually typed something + if (activeMs === 0) return window.api.appendTelemetrySession({ id: shortId(), storyId: s.storyId,