Notices when you drift from work into doomscrolling, learns from your own check-ins, and nudges you back. Everything stays on your computer.
Most focus apps block a list of sites. Attention-Guard watches behaviour instead: how often you switch, how much of the last few minutes was on video or social sites, whether you're typing or just scrolling. It learns what "drifting" looks like for you, from short check-ins where you say how focused you are.
The daily report, made from a generated demo day (open the live page). Top: what was on screen. Bottom: the distraction score, with your check-in answers as dots.
- Knows what you're looking at, not just which app. Browsers put the site in the window title ("Shorts - YouTube - Google Chrome"), so YouTube and GitHub in the same Chrome window count differently. Categories (work, video, social, news, shopping, chat) are simple keyword lists you can edit.
- Asks, doesn't guess. Every 15–25 minutes, at a random time, a small window asks "Right now, you are… Focused / Drifting / Distracted / On a break". Those answers are the training labels.
- Learns your pattern. A logistic regression on 9 behaviour features from the 5 minutes before each check-in.
- Nudges, gently. When the distraction score stays high for two checks in a row, you get a desktop notification. At most one every 10 minutes.
- Shows your day.
reportwrites a one-page HTML report: timeline, focus streaks, where the time went. - Private by design. Only counts of key presses, clicks and scrolls are stored, never which keys. Window titles are saved as a short hash unless you pass
--keep-titles. Nothing leaves your computer.
Windows, no Python needed: download AttentionGuard.exe from the latest release, double-click it, and look for the eye icon next to the clock. Windows may warn that the publisher is unknown (the app isn't code-signed): click More info → Run anyway.
Right-click the tray icon for:
- Distraction right now: the live score
- Pause: records nothing while paused
- Check in now: answer a check-in whenever you like
- Today's report: opens your day in the browser
- Train on my check-ins: once you have ~20 answers
- Start with Windows
- Open data folder, Quit
With Python (Windows, macOS, Linux):
pip install git+https://github.com/nancy6547/attention-guard.git
attention-guard app # tray icon (the normal way)
attention-guard run # same, in a terminal with live log lines
attention-guard report # today's report
attention-guard train # after a few days of check-ins
attention-guard demo # see a report without recording anythingForeground windows are read with pywin32 on Windows, osascript on macOS and xdotool on Linux. Data lives in ~/.attention_guard/; delete that folder to erase everything.
every 2 s foreground app + window title -> category, site (sensors.py, categorize.py)
key / click / scroll COUNTS (pynput, counts only)
-> one Sample row (samples.py)
every 30 s last 5 minutes of samples -> 9 features (features.py)
-> your model (or the rule baseline until you train) (guard.py)
-> nudge if high twice in a row
every 15-25 min (random) "Right now, you are...?" -> label (labels.py)
train label + features of the 5 min before it (train.py)
time-based split: earliest 70% train, latest 30% test
model must beat the rule baseline on the same test set
Features (features.py): switches per minute (app or site), distinct apps/sites, share of time on distracting categories, share on work, minutes on the current app/site, keys per minute, scrolls per minute, scroll-to-key ratio (lots of scrolling with little typing = passive consumption), idle share.
The same compute() function builds features for training and for live prediction, so the model always sees identical inputs.
Version 1 (kept in legacy/) had two mistakes worth knowing about, because they're common:
- Label leakage. v1 computed the label (focused/drifting/doomscroll) from
attention_score, which was also an input feature. The model just relearned my own thresholds, so its accuracy meant nothing. v2 gets labels from the user's check-ins, which the features can't contain. - Train/serve skew. v1's logger measured "switches in the last minute" while the live script measured "switches per second over the last 20 switches", so the model saw different numbers in production than in training. v2 has one feature function for both.
It also now evaluates with a time-based split. A random split would put two check-ins 20 minutes apart into train and test, and they look almost identical, which inflates the score.
The model needs your own check-ins, so there's no universal accuracy number. train prints precision, recall and F1 on your most recent 30% of check-ins, next to the hand-written rule baseline, plus the strongest signals it learned. I'll add my own numbers here after two weeks of use.
- Your labels are the ground truth, so the model is only as honest as your answers. Ignored check-ins are simply skipped.
- Keyword categories miss sites they don't know; they show up as "other". Edit
categorize.pyfor your habits. - Phone scrolling is invisible. It only sees this computer.
- A few dozen labels per person is small data, which is why the model is a simple, regularised logistic regression and not a deep model.
attention_guard/
sensors.py foreground window (Windows/macOS/Linux) + input counters
categorize.py app/title -> category and site
samples.py the 2-second records, CSV in/out, title hashing
features.py 9 features from the last 5 minutes (shared by training and live)
labels.py random check-ins (tkinter) and their storage
train.py time-split training, rule baseline, metrics
guard.py the live loop and nudges (pausable)
tray.py the system-tray app
report.py the daily HTML report
demo.py a generated demo day for the report
tests/ 10 tests, no hardware needed
.github/ tests on every push; Windows .exe built on every release tag
legacy/ version 1