SelfObserver is a multi-surface activity tracker that blends desktop sensors, a lightweight browser bridge, and local AI models to build a timeline of what you are doing on your machine. The project is designed to run fully locally and feed its results into a simple Flask dashboard or your own Obsidian vault.
- Desktop watcher (
self_observer.py): Windows-focused agent that samples the foreground window, captures a screenshot, fuses text + vision classification via local Ollama models, and appends JSONL entries to a per-day file such aslogs/screen_log_2024-09-30.jsonl. - Vision-only loop (
SelfObserver_Vision.py): Periodically screenshots the display withmssand asks a vision model for structured activity summaries, writing results tovision_logs.jsonl. - Behavior embedding & clustering (
behavior_model.py): Builds a 768-dimension embedding per activity (intent, context, cognitive load, emotional tone, dopamine vs. goal orientation, app semantics) and clusters them with HDBSCAN/DBSCAN/K-Means to surface emergent behaviors beyond fixed modes. - Time-series forecasting (
time_series_forecasting.py): Uses behavior embeddings, temporal features, and productivity signals to predict the next-hour behavior cluster, productivity, and distraction likelihood via LSTM/TCN/Prophet or a rolling baseline. - Behavior digital twin (
behavior_digital_twin.py): Maintains a probabilistic, incrementally updated mirror of the user's habits with Markov-style transitions, contextual factors, and short/long-horizon goal alignment signals. - Daily report generator (
daily_report.py): Reads the newestlogs/screen_log_*.jsonl(or the legacyscreen_log.jsonl) and writes Markdown summaries toSelfObserverDailyinside your Obsidian vault, with time distributions and suggested optimizations. - Dashboard (
ui/server.py): Simple Flask app that exposes recent events and time-distribution stats via JSON APIs and renders them with the templates inui/templates. - Browser bridge (
service_worker.js+browser-extension-manifest.json): Chrome extension service worker that periodically posts the active tab's title and URL tohttp://127.0.0.1:8765/ingestso desktop context includes browser activity.
self_observer.pyremains the single entry point; it now delegates to theselfobserver/package for configuration, screen capture, heuristics, classification, logging, and daily reporting.selfobserver/config.pycentralizes constants and filesystem paths, whileselfobserver/capture.py,selfobserver/classifier.py, andselfobserver/logger.pykeep the watcher loop small and readable.
- Python 3.10+
- Windows-only dependencies for the desktop watcher:
pywin32,psutil,pywinauto,Pillow. - For the vision loop:
mssand network access to your local Ollama server with vision models available. - An Ollama installation with models referenced in
self_observer.py(defaults toqwen2.5:7bandqwen2.5vl:7b). Adjust theOLLAMApath if Ollama is not on yourPATH.
- Install dependencies (example):
pip install pywin32 psutil pywinauto Pillow requests
- Ensure Chrome remote debugging is available on port
9222if you want URLs captured: start Chrome with--remote-debugging-port=9222. - Start the watcher:
A background thread will generate a daily report at 22:00, and log entries will stream into a daily
python self_observer.py
logs/screen_log_<date>.jsonlfile that rolls over automatically at midnight.
- Install the UI dependency bundle (includes Flask):
pip install -r requirements.txt
- From the repository root, launch the server:
python ui/server.py
- Open
http://localhost:5010/to view the latest 50 events and simple stats endpoints.
- Load an unpacked extension in Chrome and point it to this folder containing
browser-extension-manifest.jsonandservice_worker.js. - Keep the desktop watcher listening on
http://127.0.0.1:8765/ingestto receive tab updates (implement your own handler for ingestion if needed). - The service worker automatically posts the active tab on navigation, activation, and every 5 seconds.
If you want to render a report outside the scheduled time:
python daily_report.pyThe Markdown file will be placed under SelfObserverDaily in your Obsidian vault path configured in daily_report.py.
- Screen activity logs: rolling
logs/screen_log_<date>.jsonlfiles (withscreen_log.jsonlsupported as a legacy fallback) - Vision summaries:
vision_logs.jsonl - Temporary screenshot for the watcher:
screen_shot_tmp.jpg - Temporary screenshot for the vision loop:
screen.png - Behavior embeddings + cluster assignments are stored alongside each log entry under
behavior_embedding,behavior_cluster, andbehavior_label. - Time-series forecasts and digital-twin state are derived on the fly from the recorded embeddings and temporal features; daily reports summarize the latest insights.
- Embedding: Every captured activity is transformed into a dense 768-d vector by
behavior_model.build_embedding. Signals include intent tokens, app/window context, cognitive load, emotional tone, and dopamine-vs-goal cues. - Clustering:
behavior_model.cluster_behaviorsgroups embeddings with HDBSCAN when available (falling back to DBSCAN/K-Means). The top clusters, transition patterns, flow likelihood, and anomalies appear in the daily report. - Forecasting:
time_series_forecasting.predict_next_houringests embeddings, timestamps (with cyclical features), prior clusters/labels, and productivity to estimate next-hour behavior probabilities, expected productivity, and distraction risk. - Digital twin:
behavior_digital_twin.update_stateincrementally tracks Markov-style transitions and contextual productivity/distraction signals to infer productivity windows, procrastination triggers, stress/cognitive load cues, and short-term behavior transitions. - Reporting:
daily_report.pystitches the above outputs into Markdown—behavior clusters, transitions, flow/anomaly summaries, forecasting distributions, and digital-twin insights (goal alignment, risky periods, recommended deep-work windows).
The watcher uses a small, ordered list of heuristics before falling back to the text/vision models. To keep labels future-proof
as new apps or window titles appear, you can add or override rules in heuristics.json without touching the code. The file
accepts a list of rule objects, checked from top to bottom:
[
{
"mode": "writing",
"confidence": 0.8,
"exe_contains": ["joplin", "logseq"],
"title_contains": ["notes"]
},
{
"mode": "coding",
"confidence": 0.75,
"exe_exact": ["code.exe"],
"url_contains": ["github.com"]
}
]Supported keys per rule: exe_exact, exe_contains, title_contains, url_contains, and label_contains (for UI Automation
labels). Rules are sanitized automatically, and the watcher hot-reloads them whenever heuristics.json changes.
- The project currently targets Windows APIs for foreground window detection and may need adaptation for other platforms.
- The Ollama invocations rely on JSON-only responses; if you customize prompts, ensure they remain strictly machine-readable.