🐛 don't record unless we're actually working.
This commit is contained in:
27
scripts/fix-ghost-sessions.mjs
Normal file
27
scripts/fix-ghost-sessions.mjs
Normal file
@@ -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}).`)
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user