YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context
Rust agentsagiaiai-memoryaudio-recordingcomputer-visionhermeshermes-agentllmlocal-ailocal-firstmachine-learningmcpmultimodalopenclawprivacyrewindscreen-recordingspeech-to-textycombinator
feat: add screenpipe-analytics skill for raw SQL usage analytics
Louis Beaumont011470969c60
diff --git a/apps/screenpipe-app-tauri/src-tauri/assets/skills/screenpipe-analytics/SKILL.md b/apps/screenpipe-app-tauri/src-tauri/assets/skills/screenpipe-analytics/SKILL.mdnew file mode 100644index 000000000..27bfcca71--- /dev/null+++ b/apps/screenpipe-app-tauri/src-tauri/assets/skills/screenpipe-analytics/SKILL.md@@ -0,0 +1,348 @@+---+name: screenpipe-analytics+description: Analyze the user's computer usage patterns using raw SQL queries on their local Screenpipe database. Use when the user asks about their most used apps, websites, screen time, productivity, meeting time, typing habits, context switching, or any aggregate statistics about their activity.+---++# Screenpipe Analytics++Run raw SQL queries against the user's local Screenpipe database to answer questions about their computer usage patterns, productivity, and habits.++The API runs at `http://localhost:3030`.++## Shell: pick the right one for the OS++- **macOS/Linux** → `bash`, `curl`+- **Windows** → `powershell`, `curl.exe` (not the alias)++All examples below use bash. On Windows, adapt: use `powershell`, replace `curl` with `curl.exe`.++## Raw SQL API++```bash+curl -X POST http://localhost:3030/raw_sql \+ -H "Content-Type: application/json" \+ -d '{"query": "SELECT ... LIMIT 100"}'+```++Returns a JSON array of row objects.++## CRITICAL RULES++1. **Every SELECT must have a LIMIT** — the API rejects queries without one. Use `LIMIT 100` or less.+2. **Always filter by time** — use `WHERE timestamp > datetime('now', '-24 hours')` or similar. The database can have millions of rows.+3. **Read-only** — only SELECT queries are allowed. No INSERT, UPDATE, DELETE, DROP, etc.+4. **Use datetime() for time math** — SQLite syntax: `datetime('now', '-1 hours')`, `datetime('now', '-7 days')`, `date('now')`.+5. **Default to last 24 hours** unless the user asks for a different range.+6. **"today"** = `date(timestamp) = date('now')`. **"yesterday"** = `date(timestamp) = date('now', '-1 day')`. **"this week"** = `timestamp > datetime('now', '-7 days')`.++## Database Schema++### frames — Screen captures (1 row per screenshot, ~0.5 fps)++```sql+CREATE TABLE frames (+ id INTEGER PRIMARY KEY,+ video_chunk_id INTEGER,+ offset_index INTEGER,+ timestamp TIMESTAMP NOT NULL,+ app_name TEXT, -- e.g. "Google Chrome", "VS Code", "Slack"+ window_name TEXT, -- window title+ focused BOOLEAN,+ browser_url TEXT, -- URL if browser window+ device_name TEXT -- monitor name+);+```++**Key facts:**+- ~0.5 fps capture rate → approximate screen time: `COUNT(*) * 2 / 60` = minutes+- `app_name` is the focused application+- `browser_url` is populated for browser windows+- `window_name` contains document/tab titles++### audio_transcriptions — Speech-to-text segments++```sql+CREATE TABLE audio_transcriptions (+ id INTEGER PRIMARY KEY,+ audio_chunk_id INTEGER,+ timestamp TIMESTAMP NOT NULL,+ transcription TEXT NOT NULL,+ device TEXT, -- device name (e.g. "MacBook Pro Microphone")+ is_input_device BOOLEAN, -- true = microphone, false = system audio+ speaker_id INTEGER,+ transcription_engine TEXT+);+```++### audio_chunks — Audio recording files (~30s each)++```sql+CREATE TABLE audio_chunks (+ id INTEGER PRIMARY KEY,+ file_path TEXT NOT NULL,+ timestamp TIMESTAMP+);+```++### speakers — Known speakers++```sql+CREATE TABLE speakers (+ id INTEGER PRIMARY KEY,+ name TEXT,+ metadata JSON+);+```++### ui_events — User interactions (clicks, keystrokes, app switches)++```sql+CREATE TABLE ui_events (+ id INTEGER PRIMARY KEY,+ timestamp DATETIME NOT NULL,+ event_type TEXT NOT NULL, -- 'click', 'key', 'scroll', 'app_switch', 'window_focus', 'text'+ app_name TEXT,+ window_title TEXT,+ browser_url TEXT,+ element_role TEXT, -- accessibility role of clicked element+ element_name TEXT, -- accessibility name of clicked element+ text_content TEXT,+ text_length INTEGER+);+```++### accessibility — Accessibility tree snapshots++```sql+CREATE TABLE accessibility (+ id INTEGER PRIMARY KEY,+ timestamp DATETIME NOT NULL,+ app_name TEXT NOT NULL,+ window_name TEXT NOT NULL,+ text_content TEXT NOT NULL,+ browser_url TEXT+);+```++### ocr_text — OCR extracted text per frame++```sql+CREATE TABLE ocr_text (+ frame_id INTEGER NOT NULL,+ text TEXT NOT NULL,+ app_name TEXT,+ window_name TEXT,+ focused BOOLEAN+);+```++## Ready-to-Use Queries++### Most used apps (by screen time)++```bash+curl -X POST http://localhost:3030/raw_sql \+ -H "Content-Type: application/json" \+ -d '{"query": "SELECT app_name, COUNT(*) as frames, ROUND(COUNT(*) * 2.0 / 60, 1) as minutes FROM frames WHERE timestamp > datetime('"'"'now'"'"', '"'"'-24 hours'"'"') AND app_name IS NOT NULL AND app_name != '"'"''"'"' GROUP BY app_name ORDER BY frames DESC LIMIT 20"}'+```++Simpler with heredoc:++```bash+curl -X POST http://localhost:3030/raw_sql \+ -H "Content-Type: application/json" \+ --data-binary @- <<'PAYLOAD'+{"query": "SELECT app_name, COUNT(*) as frames, ROUND(COUNT(*) * 2.0 / 60, 1) as minutes FROM frames WHERE timestamp > datetime('now', '-24 hours') AND app_name IS NOT NULL AND app_name != '' GROUP BY app_name ORDER BY frames DESC LIMIT 20"}+PAYLOAD+```++### Most visited websites++```bash+curl -X POST http://localhost:3030/raw_sql \+ -H "Content-Type: application/json" \+ --data-binary @- <<'PAYLOAD'+{"query": "SELECT CASE WHEN INSTR(SUBSTR(browser_url, INSTR(browser_url, '://') + 3), '/') > 0 THEN SUBSTR(SUBSTR(browser_url, INSTR(browser_url, '://') + 3), 1, INSTR(SUBSTR(browser_url, INSTR(browser_url, '://') + 3), '/') - 1) ELSE SUBSTR(browser_url, INSTR(browser_url, '://') + 3) END as domain, COUNT(*) as visits FROM frames WHERE timestamp > datetime('now', '-24 hours') AND browser_url IS NOT NULL AND browser_url != '' GROUP BY domain ORDER BY visits DESC LIMIT 20"}+PAYLOAD+```++### Daily screen time (last 7 days)++```bash+curl -X POST http://localhost:3030/raw_sql \+ -H "Content-Type: application/json" \+ --data-binary @- <<'PAYLOAD'+{"query": "SELECT date(timestamp) as day, COUNT(*) as frames, ROUND(COUNT(*) * 2.0 / 3600, 1) as hours, COUNT(DISTINCT app_name) as unique_apps FROM frames WHERE timestamp > datetime('now', '-7 days') AND app_name IS NOT NULL GROUP BY day ORDER BY day DESC LIMIT 10"}+PAYLOAD+```++### Hourly app usage breakdown++```bash+curl -X POST http://localhost:3030/raw_sql \+ -H "Content-Type: application/json" \+ --data-binary @- <<'PAYLOAD'+{"query": "SELECT strftime('%H:00', timestamp) as hour, app_name, COUNT(*) as frames FROM frames WHERE timestamp > datetime('now', '-24 hours') AND app_name IS NOT NULL AND app_name != '' GROUP BY hour, app_name HAVING frames > 5 ORDER BY hour DESC, frames DESC LIMIT 50"}+PAYLOAD+```++### Most viewed windows/documents++```bash+curl -X POST http://localhost:3030/raw_sql \+ -H "Content-Type: application/json" \+ --data-binary @- <<'PAYLOAD'+{"query": "SELECT window_name, app_name, COUNT(*) as frames, ROUND(COUNT(*) * 2.0 / 60, 1) as minutes FROM frames WHERE timestamp > datetime('now', '-24 hours') AND window_name IS NOT NULL AND window_name != '' GROUP BY window_name, app_name ORDER BY frames DESC LIMIT 20"}+PAYLOAD+```++### Speaker stats (who talked the most)++```bash+curl -X POST http://localhost:3030/raw_sql \+ -H "Content-Type: application/json" \+ --data-binary @- <<'PAYLOAD'+{"query": "SELECT COALESCE(NULLIF(s.name, ''), 'Unknown') as speaker, COUNT(*) as segments, SUM(LENGTH(at.transcription)) as total_chars FROM audio_transcriptions at LEFT JOIN speakers s ON at.speaker_id = s.id WHERE at.timestamp > datetime('now', '-24 hours') GROUP BY at.speaker_id ORDER BY segments DESC LIMIT 20"}+PAYLOAD+```++### Context switching frequency (app switches per hour)++```bash+curl -X POST http://localhost:3030/raw_sql \+ -H "Content-Type: application/json" \+ --data-binary @- <<'PAYLOAD'+{"query": "SELECT strftime('%H:00', timestamp) as hour, COUNT(*) as switches FROM ui_events WHERE event_type = 'app_switch' AND timestamp > datetime('now', '-24 hours') GROUP BY hour ORDER BY hour LIMIT 24"}+PAYLOAD+```++### Click interactions by app++```bash+curl -X POST http://localhost:3030/raw_sql \+ -H "Content-Type: application/json" \+ --data-binary @- <<'PAYLOAD'+{"query": "SELECT app_name, COUNT(*) as clicks FROM ui_events WHERE event_type = 'click' AND timestamp > datetime('now', '-24 hours') AND app_name IS NOT NULL GROUP BY app_name ORDER BY clicks DESC LIMIT 20"}+PAYLOAD+```++### Typing volume by app++```bash+curl -X POST http://localhost:3030/raw_sql \+ -H "Content-Type: application/json" \+ --data-binary @- <<'PAYLOAD'+{"query": "SELECT app_name, COUNT(*) as keystrokes FROM ui_events WHERE event_type = 'key' AND timestamp > datetime('now', '-24 hours') AND app_name IS NOT NULL GROUP BY app_name ORDER BY keystrokes DESC LIMIT 15"}+PAYLOAD+```++### Daily audio recording stats (meeting time estimate)++```bash+curl -X POST http://localhost:3030/raw_sql \+ -H "Content-Type: application/json" \+ --data-binary @- <<'PAYLOAD'+{"query": "SELECT date(timestamp) as day, COUNT(DISTINCT id) as chunks, ROUND(COUNT(DISTINCT id) * 30.0 / 3600, 1) as approx_hours FROM audio_chunks WHERE timestamp > datetime('now', '-7 days') GROUP BY day ORDER BY day DESC LIMIT 10"}+PAYLOAD+```++### Browser time by domain++```bash+curl -X POST http://localhost:3030/raw_sql \+ -H "Content-Type: application/json" \+ --data-binary @- <<'PAYLOAD'+{"query": "SELECT CASE WHEN INSTR(SUBSTR(browser_url, INSTR(browser_url, '://') + 3), '/') > 0 THEN SUBSTR(SUBSTR(browser_url, INSTR(browser_url, '://') + 3), 1, INSTR(SUBSTR(browser_url, INSTR(browser_url, '://') + 3), '/') - 1) ELSE SUBSTR(browser_url, INSTR(browser_url, '://') + 3) END as domain, ROUND(COUNT(*) * 2.0 / 60, 1) as minutes FROM frames WHERE timestamp > datetime('now', '-24 hours') AND browser_url IS NOT NULL AND browser_url != '' GROUP BY domain ORDER BY minutes DESC LIMIT 20"}+PAYLOAD+```++### Productivity breakdown (coding vs browsing vs communication)++```bash+curl -X POST http://localhost:3030/raw_sql \+ -H "Content-Type: application/json" \+ --data-binary @- <<'PAYLOAD'+{"query": "SELECT CASE WHEN app_name IN ('VS Code', 'Code', 'Cursor', 'IntelliJ IDEA', 'PyCharm', 'WebStorm', 'Xcode', 'Android Studio', 'Neovim', 'Vim', 'Emacs', 'Sublime Text', 'Atom', 'WezTerm', 'iTerm2', 'Terminal', 'Alacritty', 'Warp', 'kitty', 'Ghostty', 'Hyper') THEN 'Coding & Terminal' WHEN app_name IN ('Google Chrome', 'Arc', 'Safari', 'Firefox', 'Brave Browser', 'Microsoft Edge', 'Chromium', 'Opera') THEN 'Browser' WHEN app_name IN ('Slack', 'Discord', 'Microsoft Teams', 'Telegram', 'Messages', 'WhatsApp', 'Signal', 'Zoom', 'zoom.us', 'Google Meet') THEN 'Communication' WHEN app_name IN ('Notion', 'Obsidian', 'Bear', 'Notes', 'Evernote', 'Roam Research', 'Logseq') THEN 'Notes & Docs' WHEN app_name IN ('Figma', 'Sketch', 'Adobe Photoshop', 'Adobe Illustrator', 'Canva') THEN 'Design' ELSE 'Other' END as category, COUNT(*) as frames, ROUND(COUNT(*) * 2.0 / 60, 1) as minutes FROM frames WHERE timestamp > datetime('now', '-24 hours') AND app_name IS NOT NULL AND app_name != '' GROUP BY category ORDER BY frames DESC LIMIT 10"}+PAYLOAD+```++### Active hours heatmap (when are you at the computer)++```bash+curl -X POST http://localhost:3030/raw_sql \+ -H "Content-Type: application/json" \+ --data-binary @- <<'PAYLOAD'+{"query": "SELECT strftime('%w', timestamp) as weekday, strftime('%H', timestamp) as hour, COUNT(*) as frames FROM frames WHERE timestamp > datetime('now', '-7 days') AND app_name IS NOT NULL GROUP BY weekday, hour ORDER BY weekday, hour LIMIT 200"}+PAYLOAD+```++Weekday values: 0=Sunday, 1=Monday, ..., 6=Saturday.++## Building Custom Queries++### Available tables and their purposes++| Table | Purpose | Time column | Key columns |+|-------|---------|-------------|-------------|+| `frames` | Screen captures (~0.5 fps) | `timestamp` | `app_name`, `window_name`, `browser_url`, `focused` |+| `ocr_text` | OCR text per frame | Join via `frame_id` | `text`, `app_name`, `window_name` |+| `audio_transcriptions` | Speech segments | `timestamp` | `transcription`, `device`, `speaker_id`, `is_input_device` |+| `audio_chunks` | Audio files (~30s) | `timestamp` | `file_path` |+| `speakers` | Speaker identities | — | `name`, `metadata` |+| `ui_events` | User interactions | `timestamp` | `event_type`, `app_name`, `window_title`, `browser_url` |+| `accessibility` | Accessibility tree text | `timestamp` | `app_name`, `window_name`, `text_content`, `browser_url` |++### Common patterns++```sql+-- Time filtering+WHERE timestamp > datetime('now', '-24 hours')+WHERE timestamp > datetime('now', '-7 days')+WHERE date(timestamp) = date('now')+WHERE timestamp BETWEEN '2024-01-15T00:00:00Z' AND '2024-01-15T23:59:59Z'++-- Group by time+GROUP BY date(timestamp) -- daily+GROUP BY strftime('%H:00', timestamp) -- hourly+GROUP BY strftime('%w', timestamp) -- by weekday++-- Screen time approximation+ROUND(COUNT(*) * 2.0 / 60, 1) -- frames → minutes+ROUND(COUNT(*) * 2.0 / 3600, 1) -- frames → hours++-- Domain extraction from browser_url+CASE WHEN INSTR(SUBSTR(browser_url, INSTR(browser_url, '://') + 3), '/') > 0+ THEN SUBSTR(SUBSTR(browser_url, INSTR(browser_url, '://') + 3), 1, INSTR(SUBSTR(browser_url, INSTR(browser_url, '://') + 3), '/') - 1)+ ELSE SUBSTR(browser_url, INSTR(browser_url, '://') + 3)+END as domain+```++### Joining tables++```sql+-- Audio with speaker names+SELECT at.*, s.name as speaker_name+FROM audio_transcriptions at+LEFT JOIN speakers s ON at.speaker_id = s.id++-- OCR text with frame metadata+SELECT f.timestamp, f.app_name, o.text+FROM frames f+JOIN ocr_text o ON o.frame_id = f.id++-- UI events with frame context+SELECT u.event_type, u.app_name, u.element_name, f.window_name+FROM ui_events u+LEFT JOIN frames f ON u.frame_id = f.id+```++## Tips++- **Screen time from frames** is approximate: each frame represents ~2 seconds of screen time at 0.5 fps capture rate.+- **Combine multiple queries** to build a full picture — e.g., app usage + website usage + typing stats.+- **Use HAVING** to filter out noise — `HAVING frames > 5` removes apps you glanced at briefly.+- **Window titles reveal context** — for coding, they contain file names and project names. For browsers, they contain page titles.+- **speaker_id can be NULL** — not all audio gets speaker detection. Use `LEFT JOIN` and `COALESCE`.+- **ui_events event_type values**: `click`, `key`, `scroll`, `app_switch`, `window_focus`, `text`, `clipboard`.+- When presenting results, **format numbers** (round decimals, add units like "minutes" or "hours") and **sort by most interesting** metric.+- For productivity reports, combine screen time + typing + click data for a comprehensive view.diff --git a/apps/screenpipe-app-tauri/src-tauri/src/pi.rs b/apps/screenpipe-app-tauri/src-tauri/src/pi.rsindex 7b7b842cf..551ee1f20 100644--- a/apps/screenpipe-app-tauri/src-tauri/src/pi.rs+++ b/apps/screenpipe-app-tauri/src-tauri/src/pi.rs@@ -342,6 +342,7 @@ fn ensure_screenpipe_skill(project_dir: &str) -> Result<(), String> {("screenpipe-pipe-creator", include_str!("../assets/skills/screenpipe-pipe-creator/SKILL.md")),("screenpipe-media", include_str!("../assets/skills/screenpipe-media/SKILL.md")),("screenpipe-retranscribe", include_str!("../assets/skills/screenpipe-retranscribe/SKILL.md")),+ ("screenpipe-analytics", include_str!("../assets/skills/screenpipe-analytics/SKILL.md")),];for (name, content) in skills {diff --git a/crates/screenpipe-core/assets/skills/screenpipe-analytics/SKILL.md b/crates/screenpipe-core/assets/skills/screenpipe-analytics/SKILL.mdnew file mode 100644index 000000000..27bfcca71--- /dev/null+++ b/crates/screenpipe-core/assets/skills/screenpipe-analytics/SKILL.md@@ -0,0 +1,348 @@+---+name: screenpipe-analytics+description: Analyze the user's computer usage patterns using raw SQL queries on their local Screenpipe database. Use when the user asks about their most used apps, websites, screen time, productivity, meeting time, typing habits, context switching, or any aggregate statistics about their activity.+---++# Screenpipe Analytics++Run raw SQL queries against the user's local Screenpipe database to answer questions about their computer usage patterns, productivity, and habits.++The API runs at `http://localhost:3030`.++## Shell: pick the right one for the OS++- **macOS/Linux** → `bash`, `curl`+- **Windows** → `powershell`, `curl.exe` (not the alias)++All examples below use bash. On Windows, adapt: use `powershell`, replace `curl` with `curl.exe`.++## Raw SQL API++```bash+curl -X POST http://localhost:3030/raw_sql \+ -H "Content-Type: application/json" \+ -d '{"query": "SELECT ... LIMIT 100"}'+```++Returns a JSON array of row objects.++## CRITICAL RULES++1. **Every SELECT must have a LIMIT** — the API rejects queries without one. Use `LIMIT 100` or less.+2. **Always filter by time** — use `WHERE timestamp > datetime('now', '-24 hours')` or similar. The database can have millions of rows.+3. **Read-only** — only SELECT queries are allowed. No INSERT, UPDATE, DELETE, DROP, etc.+4. **Use datetime() for time math** — SQLite syntax: `datetime('now', '-1 hours')`, `datetime('now', '-7 days')`, `date('now')`.+5. **Default to last 24 hours** unless the user asks for a different range.+6. **"today"** = `date(timestamp) = date('now')`. **"yesterday"** = `date(timestamp) = date('now', '-1 day')`. **"this week"** = `timestamp > datetime('now', '-7 days')`.++## Database Schema++### frames — Screen captures (1 row per screenshot, ~0.5 fps)++```sql+CREATE TABLE frames (+ id INTEGER PRIMARY KEY,+ video_chunk_id INTEGER,+ offset_index INTEGER,+ timestamp TIMESTAMP NOT NULL,+ app_name TEXT, -- e.g. "Google Chrome", "VS Code", "Slack"+ window_name TEXT, -- window title+ focused BOOLEAN,+ browser_url TEXT, -- URL if browser window+ device_name TEXT -- monitor name+);+```++**Key facts:**+- ~0.5 fps capture rate → approximate screen time: `COUNT(*) * 2 / 60` = minutes+- `app_name` is the focused application+- `browser_url` is populated for browser windows+- `window_name` contains document/tab titles++### audio_transcriptions — Speech-to-text segments++```sql+CREATE TABLE audio_transcriptions (+ id INTEGER PRIMARY KEY,+ audio_chunk_id INTEGER,+ timestamp TIMESTAMP NOT NULL,+ transcription TEXT NOT NULL,+ device TEXT, -- device name (e.g. "MacBook Pro Microphone")+ is_input_device BOOLEAN, -- true = microphone, false = system audio+ speaker_id INTEGER,+ transcription_engine TEXT+);+```++### audio_chunks — Audio recording files (~30s each)++```sql+CREATE TABLE audio_chunks (+ id INTEGER PRIMARY KEY,+ file_path TEXT NOT NULL,+ timestamp TIMESTAMP+);+```++### speakers — Known speakers++```sql+CREATE TABLE speakers (+ id INTEGER PRIMARY KEY,+ name TEXT,+ metadata JSON+);+```++### ui_events — User interactions (clicks, keystrokes, app switches)++```sql+CREATE TABLE ui_events (+ id INTEGER PRIMARY KEY,+ timestamp DATETIME NOT NULL,+ event_type TEXT NOT NULL, -- 'click', 'key', 'scroll', 'app_switch', 'window_focus', 'text'+ app_name TEXT,+ window_title TEXT,+ browser_url TEXT,+ element_role TEXT, -- accessibility role of clicked element+ element_name TEXT, -- accessibility name of clicked element+ text_content TEXT,+ text_length INTEGER+);+```++### accessibility — Accessibility tree snapshots++```sql+CREATE TABLE accessibility (+ id INTEGER PRIMARY KEY,+ timestamp DATETIME NOT NULL,+ app_name TEXT NOT NULL,+ window_name TEXT NOT NULL,+ text_content TEXT NOT NULL,+ browser_url TEXT+);+```++### ocr_text — OCR extracted text per frame++```sql+CREATE TABLE ocr_text (+ frame_id INTEGER NOT NULL,+ text TEXT NOT NULL,+ app_name TEXT,+ window_name TEXT,+ focused BOOLEAN+);+```++## Ready-to-Use Queries++### Most used apps (by screen time)++```bash+curl -X POST http://localhost:3030/raw_sql \+ -H "Content-Type: application/json" \+ -d '{"query": "SELECT app_name, COUNT(*) as frames, ROUND(COUNT(*) * 2.0 / 60, 1) as minutes FROM frames WHERE timestamp > datetime('"'"'now'"'"', '"'"'-24 hours'"'"') AND app_name IS NOT NULL AND app_name != '"'"''"'"' GROUP BY app_name ORDER BY frames DESC LIMIT 20"}'+```++Simpler with heredoc:++```bash+curl -X POST http://localhost:3030/raw_sql \+ -H "Content-Type: application/json" \+ --data-binary @- <<'PAYLOAD'+{"query": "SELECT app_name, COUNT(*) as frames, ROUND(COUNT(*) * 2.0 / 60, 1) as minutes FROM frames WHERE timestamp > datetime('now', '-24 hours') AND app_name IS NOT NULL AND app_name != '' GROUP BY app_name ORDER BY frames DESC LIMIT 20"}+PAYLOAD+```++### Most visited websites++```bash+curl -X POST http://localhost:3030/raw_sql \+ -H "Content-Type: application/json" \+ --data-binary @- <<'PAYLOAD'+{"query": "SELECT CASE WHEN INSTR(SUBSTR(browser_url, INSTR(browser_url, '://') + 3), '/') > 0 THEN SUBSTR(SUBSTR(browser_url, INSTR(browser_url, '://') + 3), 1, INSTR(SUBSTR(browser_url, INSTR(browser_url, '://') + 3), '/') - 1) ELSE SUBSTR(browser_url, INSTR(browser_url, '://') + 3) END as domain, COUNT(*) as visits FROM frames WHERE timestamp > datetime('now', '-24 hours') AND browser_url IS NOT NULL AND browser_url != '' GROUP BY domain ORDER BY visits DESC LIMIT 20"}+PAYLOAD+```++### Daily screen time (last 7 days)++```bash+curl -X POST http://localhost:3030/raw_sql \+ -H "Content-Type: application/json" \+ --data-binary @- <<'PAYLOAD'+{"query": "SELECT date(timestamp) as day, COUNT(*) as frames, ROUND(COUNT(*) * 2.0 / 3600, 1) as hours, COUNT(DISTINCT app_name) as unique_apps FROM frames WHERE timestamp > datetime('now', '-7 days') AND app_name IS NOT NULL GROUP BY day ORDER BY day DESC LIMIT 10"}+PAYLOAD+```++### Hourly app usage breakdown++```bash+curl -X POST http://localhost:3030/raw_sql \+ -H "Content-Type: application/json" \+ --data-binary @- <<'PAYLOAD'+{"query": "SELECT strftime('%H:00', timestamp) as hour, app_name, COUNT(*) as frames FROM frames WHERE timestamp > datetime('now', '-24 hours') AND app_name IS NOT NULL AND app_name != '' GROUP BY hour, app_name HAVING frames > 5 ORDER BY hour DESC, frames DESC LIMIT 50"}+PAYLOAD+```++### Most viewed windows/documents++```bash+curl -X POST http://localhost:3030/raw_sql \+ -H "Content-Type: application/json" \+ --data-binary @- <<'PAYLOAD'+{"query": "SELECT window_name, app_name, COUNT(*) as frames, ROUND(COUNT(*) * 2.0 / 60, 1) as minutes FROM frames WHERE timestamp > datetime('now', '-24 hours') AND window_name IS NOT NULL AND window_name != '' GROUP BY window_name, app_name ORDER BY frames DESC LIMIT 20"}+PAYLOAD+```++### Speaker stats (who talked the most)++```bash+curl -X POST http://localhost:3030/raw_sql \+ -H "Content-Type: application/json" \+ --data-binary @- <<'PAYLOAD'+{"query": "SELECT COALESCE(NULLIF(s.name, ''), 'Unknown') as speaker, COUNT(*) as segments, SUM(LENGTH(at.transcription)) as total_chars FROM audio_transcriptions at LEFT JOIN speakers s ON at.speaker_id = s.id WHERE at.timestamp > datetime('now', '-24 hours') GROUP BY at.speaker_id ORDER BY segments DESC LIMIT 20"}+PAYLOAD+```++### Context switching frequency (app switches per hour)++```bash+curl -X POST http://localhost:3030/raw_sql \+ -H "Content-Type: application/json" \+ --data-binary @- <<'PAYLOAD'+{"query": "SELECT strftime('%H:00', timestamp) as hour, COUNT(*) as switches FROM ui_events WHERE event_type = 'app_switch' AND timestamp > datetime('now', '-24 hours') GROUP BY hour ORDER BY hour LIMIT 24"}+PAYLOAD+```++### Click interactions by app++```bash+curl -X POST http://localhost:3030/raw_sql \+ -H "Content-Type: application/json" \+ --data-binary @- <<'PAYLOAD'+{"query": "SELECT app_name, COUNT(*) as clicks FROM ui_events WHERE event_type = 'click' AND timestamp > datetime('now', '-24 hours') AND app_name IS NOT NULL GROUP BY app_name ORDER BY clicks DESC LIMIT 20"}+PAYLOAD+```++### Typing volume by app++```bash+curl -X POST http://localhost:3030/raw_sql \+ -H "Content-Type: application/json" \+ --data-binary @- <<'PAYLOAD'+{"query": "SELECT app_name, COUNT(*) as keystrokes FROM ui_events WHERE event_type = 'key' AND timestamp > datetime('now', '-24 hours') AND app_name IS NOT NULL GROUP BY app_name ORDER BY keystrokes DESC LIMIT 15"}+PAYLOAD+```++### Daily audio recording stats (meeting time estimate)++```bash+curl -X POST http://localhost:3030/raw_sql \+ -H "Content-Type: application/json" \+ --data-binary @- <<'PAYLOAD'+{"query": "SELECT date(timestamp) as day, COUNT(DISTINCT id) as chunks, ROUND(COUNT(DISTINCT id) * 30.0 / 3600, 1) as approx_hours FROM audio_chunks WHERE timestamp > datetime('now', '-7 days') GROUP BY day ORDER BY day DESC LIMIT 10"}+PAYLOAD+```++### Browser time by domain++```bash+curl -X POST http://localhost:3030/raw_sql \+ -H "Content-Type: application/json" \+ --data-binary @- <<'PAYLOAD'+{"query": "SELECT CASE WHEN INSTR(SUBSTR(browser_url, INSTR(browser_url, '://') + 3), '/') > 0 THEN SUBSTR(SUBSTR(browser_url, INSTR(browser_url, '://') + 3), 1, INSTR(SUBSTR(browser_url, INSTR(browser_url, '://') + 3), '/') - 1) ELSE SUBSTR(browser_url, INSTR(browser_url, '://') + 3) END as domain, ROUND(COUNT(*) * 2.0 / 60, 1) as minutes FROM frames WHERE timestamp > datetime('now', '-24 hours') AND browser_url IS NOT NULL AND browser_url != '' GROUP BY domain ORDER BY minutes DESC LIMIT 20"}+PAYLOAD+```++### Productivity breakdown (coding vs browsing vs communication)++```bash+curl -X POST http://localhost:3030/raw_sql \+ -H "Content-Type: application/json" \+ --data-binary @- <<'PAYLOAD'+{"query": "SELECT CASE WHEN app_name IN ('VS Code', 'Code', 'Cursor', 'IntelliJ IDEA', 'PyCharm', 'WebStorm', 'Xcode', 'Android Studio', 'Neovim', 'Vim', 'Emacs', 'Sublime Text', 'Atom', 'WezTerm', 'iTerm2', 'Terminal', 'Alacritty', 'Warp', 'kitty', 'Ghostty', 'Hyper') THEN 'Coding & Terminal' WHEN app_name IN ('Google Chrome', 'Arc', 'Safari', 'Firefox', 'Brave Browser', 'Microsoft Edge', 'Chromium', 'Opera') THEN 'Browser' WHEN app_name IN ('Slack', 'Discord', 'Microsoft Teams', 'Telegram', 'Messages', 'WhatsApp', 'Signal', 'Zoom', 'zoom.us', 'Google Meet') THEN 'Communication' WHEN app_name IN ('Notion', 'Obsidian', 'Bear', 'Notes', 'Evernote', 'Roam Research', 'Logseq') THEN 'Notes & Docs' WHEN app_name IN ('Figma', 'Sketch', 'Adobe Photoshop', 'Adobe Illustrator', 'Canva') THEN 'Design' ELSE 'Other' END as category, COUNT(*) as frames, ROUND(COUNT(*) * 2.0 / 60, 1) as minutes FROM frames WHERE timestamp > datetime('now', '-24 hours') AND app_name IS NOT NULL AND app_name != '' GROUP BY category ORDER BY frames DESC LIMIT 10"}+PAYLOAD+```++### Active hours heatmap (when are you at the computer)++```bash+curl -X POST http://localhost:3030/raw_sql \+ -H "Content-Type: application/json" \+ --data-binary @- <<'PAYLOAD'+{"query": "SELECT strftime('%w', timestamp) as weekday, strftime('%H', timestamp) as hour, COUNT(*) as frames FROM frames WHERE timestamp > datetime('now', '-7 days') AND app_name IS NOT NULL GROUP BY weekday, hour ORDER BY weekday, hour LIMIT 200"}+PAYLOAD+```++Weekday values: 0=Sunday, 1=Monday, ..., 6=Saturday.++## Building Custom Queries++### Available tables and their purposes++| Table | Purpose | Time column | Key columns |+|-------|---------|-------------|-------------|+| `frames` | Screen captures (~0.5 fps) | `timestamp` | `app_name`, `window_name`, `browser_url`, `focused` |+| `ocr_text` | OCR text per frame | Join via `frame_id` | `text`, `app_name`, `window_name` |+| `audio_transcriptions` | Speech segments | `timestamp` | `transcription`, `device`, `speaker_id`, `is_input_device` |+| `audio_chunks` | Audio files (~30s) | `timestamp` | `file_path` |+| `speakers` | Speaker identities | — | `name`, `metadata` |+| `ui_events` | User interactions | `timestamp` | `event_type`, `app_name`, `window_title`, `browser_url` |+| `accessibility` | Accessibility tree text | `timestamp` | `app_name`, `window_name`, `text_content`, `browser_url` |++### Common patterns++```sql+-- Time filtering+WHERE timestamp > datetime('now', '-24 hours')+WHERE timestamp > datetime('now', '-7 days')+WHERE date(timestamp) = date('now')+WHERE timestamp BETWEEN '2024-01-15T00:00:00Z' AND '2024-01-15T23:59:59Z'++-- Group by time+GROUP BY date(timestamp) -- daily+GROUP BY strftime('%H:00', timestamp) -- hourly+GROUP BY strftime('%w', timestamp) -- by weekday++-- Screen time approximation+ROUND(COUNT(*) * 2.0 / 60, 1) -- frames → minutes+ROUND(COUNT(*) * 2.0 / 3600, 1) -- frames → hours++-- Domain extraction from browser_url+CASE WHEN INSTR(SUBSTR(browser_url, INSTR(browser_url, '://') + 3), '/') > 0+ THEN SUBSTR(SUBSTR(browser_url, INSTR(browser_url, '://') + 3), 1, INSTR(SUBSTR(browser_url, INSTR(browser_url, '://') + 3), '/') - 1)+ ELSE SUBSTR(browser_url, INSTR(browser_url, '://') + 3)+END as domain+```++### Joining tables++```sql+-- Audio with speaker names+SELECT at.*, s.name as speaker_name+FROM audio_transcriptions at+LEFT JOIN speakers s ON at.speaker_id = s.id++-- OCR text with frame metadata+SELECT f.timestamp, f.app_name, o.text+FROM frames f+JOIN ocr_text o ON o.frame_id = f.id++-- UI events with frame context+SELECT u.event_type, u.app_name, u.element_name, f.window_name+FROM ui_events u+LEFT JOIN frames f ON u.frame_id = f.id+```++## Tips++- **Screen time from frames** is approximate: each frame represents ~2 seconds of screen time at 0.5 fps capture rate.+- **Combine multiple queries** to build a full picture — e.g., app usage + website usage + typing stats.+- **Use HAVING** to filter out noise — `HAVING frames > 5` removes apps you glanced at briefly.+- **Window titles reveal context** — for coding, they contain file names and project names. For browsers, they contain page titles.+- **speaker_id can be NULL** — not all audio gets speaker detection. Use `LEFT JOIN` and `COALESCE`.+- **ui_events event_type values**: `click`, `key`, `scroll`, `app_switch`, `window_focus`, `text`, `clipboard`.+- When presenting results, **format numbers** (round decimals, add units like "minutes" or "hours") and **sort by most interesting** metric.+- For productivity reports, combine screen time + typing + click data for a comprehensive view.diff --git a/crates/screenpipe-core/src/agents/pi.rs b/crates/screenpipe-core/src/agents/pi.rsindex 77a1ad49c..6cd3fc0e9 100644--- a/crates/screenpipe-core/src/agents/pi.rs+++ b/crates/screenpipe-core/src/agents/pi.rs@@ -92,6 +92,10 @@ impl PiExecutor {"screenpipe-retranscribe",include_str!("../../assets/skills/screenpipe-retranscribe/SKILL.md"),),+ (+ "screenpipe-analytics",+ include_str!("../../assets/skills/screenpipe-analytics/SKILL.md"),+ ),];for (name, content) in skills {