Skip to content

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

feat: rich activity-summary with windows, URLs, and audio transcriptions

Louis Beaumontf25e2671f499
diff --git a/crates/screenpipe-connect/screenpipe-mcp/src/index.ts b/crates/screenpipe-connect/screenpipe-mcp/src/index.ts
index c34e54919..f6227e2a9 100644
--- a/crates/screenpipe-connect/screenpipe-mcp/src/index.ts
+++ b/crates/screenpipe-connect/screenpipe-mcp/src/index.ts
@@ -709,14 +709,37 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
}
);
+ // Window/tab activity — what pages/documents were open
+ const windowLines = (data.windows || []).map(
+ (w: {
+ app_name: string;
+ window_name: string;
+ browser_url: string;
+ minutes: number;
+ frame_count: number;
+ }) => {
+ const url = w.browser_url ? ` (${w.browser_url})` : "";
+ return ` [${w.app_name}] ${w.window_name}${url} — ${w.minutes} min`;
+ }
+ );
+
const speakerLines = (data.audio_summary?.speakers || []).map(
(s: { name: string; segment_count: number }) =>
` ${s.name}: ${s.segment_count} segments`
);
- const textLines = (data.recent_texts || []).map(
- (t: { text: string; app_name: string; timestamp: string }) =>
- ` [${t.app_name}] ${t.text}`
+ // Actual audio transcriptions (not just counts)
+ const transcriptLines = (data.audio_summary?.top_transcriptions || []).map(
+ (t: { transcription: string; speaker: string; device: string; timestamp: string }) =>
+ ` [${t.speaker}, ${t.timestamp.slice(11, 19)}] ${t.transcription}`
+ );
+
+ // Key text content sampled across the time range
+ const textLines = (data.key_texts || data.recent_texts || []).map(
+ (t: { text: string; app_name: string; window_name?: string; timestamp: string }) => {
+ const win = t.window_name ? ` | ${t.window_name}` : "";
+ return ` [${t.app_name}${win}, ${t.timestamp.slice(11, 19)}] ${t.text}`;
+ }
);
const summary = [
@@ -726,11 +749,15 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
"Apps:",
...(appsLines.length ? appsLines : [" (none)"]),
"",
+ "Windows & Tabs:",
+ ...(windowLines.length ? windowLines.slice(0, 20) : [" (none)"]),
+ "",
`Audio: ${data.audio_summary?.segment_count || 0} segments`,
...(speakerLines.length ? speakerLines : []),
+ ...(transcriptLines.length ? ["", "Audio transcriptions:", ...transcriptLines.slice(0, 15)] : []),
"",
- "Recent texts:",
- ...(textLines.length ? textLines.slice(0, 10) : [" (none)"]),
+ "Key content (sampled across time range):",
+ ...(textLines.length ? textLines.slice(0, 20) : [" (none)"]),
].join("\n");
return { content: [{ type: "text", text: summary }] };
diff --git a/crates/screenpipe-engine/src/routes/activity_summary.rs b/crates/screenpipe-engine/src/routes/activity_summary.rs
index c59f0c735..26635fbe5 100644
--- a/crates/screenpipe-engine/src/routes/activity_summary.rs
+++ b/crates/screenpipe-engine/src/routes/activity_summary.rs
@@ -40,9 +40,27 @@ pub struct AppUsage {
}
#[derive(Serialize, OaSchema)]
-pub struct RecentText {
+pub struct WindowActivity {
+ pub app_name: String,
+ pub window_name: String,
+ pub browser_url: String,
+ pub minutes: f64,
+ pub frame_count: i64,
+}
+
+#[derive(Serialize, OaSchema)]
+pub struct KeyText {
pub text: String,
pub app_name: String,
+ pub window_name: String,
+ pub timestamp: String,
+}
+
+#[derive(Serialize, OaSchema)]
+pub struct AudioSegment {
+ pub transcription: String,
+ pub speaker: String,
+ pub device: String,
pub timestamp: String,
}
@@ -56,6 +74,8 @@ pub struct SpeakerSummary {
pub struct AudioSummary {
pub segment_count: i64,
pub speakers: Vec<SpeakerSummary>,
+ /// Top transcriptions with actual text (sorted by length, most substantial first)
+ pub top_transcriptions: Vec<AudioSegment>,
}
#[derive(Serialize, OaSchema)]
@@ -67,14 +87,19 @@ pub struct TimeRange {
#[derive(Serialize, OaSchema)]
pub struct ActivitySummaryResponse {
pub apps: Vec<AppUsage>,
- pub recent_texts: Vec<RecentText>,
+ /// Distinct windows/tabs visited with time spent (grouped by app+window)
+ pub windows: Vec<WindowActivity>,
+ /// Key text content sampled across the time range (not just the latest frame)
+ pub key_texts: Vec<KeyText>,
pub audio_summary: AudioSummary,
pub total_frames: i64,
pub time_range: TimeRange,
}
-/// Lightweight compressed activity overview for a time range.
-/// Returns app usage, recent accessibility texts, and audio summary (~200-500 tokens).
+/// Rich activity summary for a time range.
+///
+/// Returns app usage, window/tab activity with URLs, sampled text content
+/// across the full period, and audio transcriptions with speaker info.
#[oasgen]
pub async fn get_activity_summary(
State(state): State<Arc<AppState>>,
@@ -83,13 +108,19 @@ pub async fn get_activity_summary(
let start = query.start_time.format("%Y-%m-%dT%H:%M:%SZ").to_string();
let end = query.end_time.format("%Y-%m-%dT%H:%M:%SZ").to_string();
- // Query 1: App usage
let app_filter = query
.app_name
.as_deref()
.map(|a| format!(" AND app_name = '{}'", a.replace('\'', "''")))
.unwrap_or_default();
+ let app_filter_f = query
+ .app_name
+ .as_deref()
+ .map(|a| format!(" AND f.app_name = '{}'", a.replace('\'', "''")))
+ .unwrap_or_default();
+
+ // Query 1: App usage (same as before — solid)
let apps_query = format!(
"SELECT app_name, \
COUNT(*) as frame_count, \
@@ -101,46 +132,93 @@ pub async fn get_activity_summary(
(JULIANDAY(LEAD(timestamp) OVER (PARTITION BY app_name ORDER BY timestamp)) \
- JULIANDAY(timestamp)) * 86400 AS gap_sec \
FROM frames \
- WHERE timestamp BETWEEN '{}' AND '{}'{} \
+ WHERE timestamp BETWEEN '{start}' AND '{end}'{app_filter} \
AND app_name IS NOT NULL AND app_name != '' \
) gaps \
- GROUP BY app_name ORDER BY minutes DESC LIMIT 20",
- start, end, app_filter
+ GROUP BY app_name ORDER BY minutes DESC LIMIT 20"
);
- // Query 2: Recent accessibility texts
- let app_filter_elements = query
- .app_name
- .as_deref()
- .map(|a| format!(" AND f.app_name = '{}'", a.replace('\'', "''")))
- .unwrap_or_default();
+ // Query 2: Window/tab activity — what was the user actually looking at?
+ // Groups by app + window_name, includes browser_url, shows time per window.
+ let windows_query = format!(
+ "SELECT app_name, window_name, \
+ COALESCE(browser_url, '') as browser_url, \
+ COUNT(*) as frame_count, \
+ ROUND(SUM(CASE WHEN gap_sec < 300 THEN gap_sec ELSE 0 END) / 60.0, 1) as minutes \
+ FROM ( \
+ SELECT app_name, \
+ COALESCE(window_name, '') as window_name, \
+ browser_url, \
+ (JULIANDAY(LEAD(timestamp) OVER (PARTITION BY app_name, window_name ORDER BY timestamp)) \
+ - JULIANDAY(timestamp)) * 86400 AS gap_sec \
+ FROM frames \
+ WHERE timestamp BETWEEN '{start}' AND '{end}'{app_filter} \
+ AND app_name IS NOT NULL AND app_name != '' \
+ AND window_name IS NOT NULL AND window_name != '' \
+ ) gaps \
+ GROUP BY app_name, window_name \
+ ORDER BY minutes DESC LIMIT 30"
+ );
+ // Query 3: Key text — sample meaningful text across the FULL time range.
+ // Strategy: pick texts from multiple time buckets (not just the last frame),
+ // filter for substantial content (>20 chars), prefer paragraphs/blocks,
+ // and deduplicate.
let texts_query = format!(
- "SELECT DISTINCT e.text, f.app_name, f.timestamp \
- FROM elements e \
- JOIN frames f ON f.id = e.frame_id \
- WHERE f.timestamp BETWEEN '{}' AND '{}'{} \
- AND e.text IS NOT NULL AND e.source IN ('accessibility', 'ocr') \
- AND e.role IN ('AXStaticText', 'line', 'paragraph', 'block') \
- ORDER BY f.timestamp DESC LIMIT 10",
- start, end, app_filter_elements
+ "SELECT text, app_name, window_name, timestamp FROM ( \
+ SELECT e.text, f.app_name, \
+ COALESCE(f.window_name, '') as window_name, \
+ f.timestamp, \
+ ROW_NUMBER() OVER ( \
+ PARTITION BY ( \
+ CAST((JULIANDAY(f.timestamp) - JULIANDAY('{start}')) * 24 AS INTEGER) \
+ ) \
+ ORDER BY LENGTH(e.text) DESC \
+ ) as rn \
+ FROM elements e \
+ JOIN frames f ON f.id = e.frame_id \
+ WHERE f.timestamp BETWEEN '{start}' AND '{end}'{app_filter_f} \
+ AND e.text IS NOT NULL \
+ AND e.source IN ('accessibility', 'ocr') \
+ AND e.role IN ('AXStaticText', 'paragraph', 'block', 'line') \
+ AND LENGTH(e.text) > 20 \
+ AND e.text NOT LIKE '%http%' \
+ AND e.text NOT GLOB '*[0-9][0-9][0-9][0-9][0-9]*' \
+ ) ranked \
+ WHERE rn <= 3 \
+ ORDER BY timestamp ASC LIMIT 30"
);
- // Query 3: Audio summary
- let audio_query = format!(
+ // Query 4: Audio — actual transcriptions, not just counts
+ let audio_speakers_query = format!(
"SELECT COALESCE(s.name, 'Unknown') as speaker_name, COUNT(*) as segment_count \
FROM audio_transcriptions at \
LEFT JOIN speakers s ON at.speaker_id = s.id \
- WHERE at.timestamp BETWEEN '{}' AND '{}' \
- GROUP BY at.speaker_id ORDER BY 2 DESC LIMIT 10",
- start, end
+ WHERE at.timestamp BETWEEN '{start}' AND '{end}' \
+ GROUP BY at.speaker_id ORDER BY 2 DESC LIMIT 10"
+ );
+
+ // Top transcriptions by length (most substantial speech segments)
+ let audio_transcripts_query = format!(
+ "SELECT at.transcription, \
+ COALESCE(s.name, 'Unknown') as speaker, \
+ at.device, \
+ at.timestamp \
+ FROM audio_transcriptions at \
+ LEFT JOIN speakers s ON at.speaker_id = s.id \
+ WHERE at.timestamp BETWEEN '{start}' AND '{end}' \
+ AND TRIM(at.transcription) != '' \
+ AND LENGTH(at.transcription) > 5 \
+ ORDER BY LENGTH(at.transcription) DESC LIMIT 20"
);
- // Execute all three queries
- let (apps_result, texts_result, audio_result) = tokio::join!(
+ // Execute all queries
+ let (apps_result, windows_result, texts_result, audio_speakers_result, audio_transcripts_result) = tokio::join!(
state.db.execute_raw_sql(&apps_query),
+ state.db.execute_raw_sql(&windows_query),
state.db.execute_raw_sql(&texts_query),
- state.db.execute_raw_sql(&audio_query),
+ state.db.execute_raw_sql(&audio_speakers_query),
+ state.db.execute_raw_sql(&audio_transcripts_query),
);
// Parse app usage
@@ -149,36 +227,14 @@ pub async fn get_activity_summary(
if let Ok(rows) = apps_result {
if let Some(arr) = rows.as_array() {
for row in arr {
- let name = row
- .get("app_name")
- .and_then(|v| v.as_str())
- .unwrap_or("")
- .to_string();
let frame_count = row.get("frame_count").and_then(|v| v.as_i64()).unwrap_or(0);
- let minutes = row
- .get("minutes")
- .and_then(|v| {
- v.as_f64()
- .or_else(|| v.as_str().and_then(|s| s.parse().ok()))
- })
- .unwrap_or(0.0);
- let first_seen = row
- .get("first_seen")
- .and_then(|v| v.as_str())
- .unwrap_or("")
- .to_string();
- let last_seen = row
- .get("last_seen")
- .and_then(|v| v.as_str())
- .unwrap_or("")
- .to_string();
total_frames += frame_count;
apps.push(AppUsage {
- name,
+ name: str_field(row, "app_name"),
frame_count,
- minutes,
- first_seen,
- last_seen,
+ minutes: num_field(row, "minutes"),
+ first_seen: str_field(row, "first_seen"),
+ last_seen: str_field(row, "last_seen"),
});
}
}
@@ -186,30 +242,46 @@ pub async fn get_activity_summary(
error!("activity summary: apps query failed: {}", e);
}
- // Parse recent texts
- let mut recent_texts = Vec::new();
+ // Parse window activity
+ let mut windows = Vec::new();
+ if let Ok(rows) = windows_result {
+ if let Some(arr) = rows.as_array() {
+ for row in arr {
+ let window_name = str_field(row, "window_name");
+ // Skip empty/useless window names
+ if window_name.is_empty() || window_name.len() < 3 {
+ continue;
+ }
+ windows.push(WindowActivity {
+ app_name: str_field(row, "app_name"),
+ window_name,
+ browser_url: str_field(row, "browser_url"),
+ minutes: num_field(row, "minutes"),
+ frame_count: row.get("frame_count").and_then(|v| v.as_i64()).unwrap_or(0),
+ });
+ }
+ }
+ } else if let Err(e) = &windows_result {
+ error!("activity summary: windows query failed: {}", e);
+ }
+
+ // Parse key texts — deduplicate by content
+ let mut key_texts = Vec::new();
+ let mut seen_texts = std::collections::HashSet::new();
if let Ok(rows) = texts_result {
if let Some(arr) = rows.as_array() {
for row in arr {
- let text = row
- .get("text")
- .and_then(|v| v.as_str())
- .unwrap_or("")
- .to_string();
- let app_name = row
- .get("app_name")
- .and_then(|v| v.as_str())
- .unwrap_or("")
- .to_string();
- let timestamp = row
- .get("timestamp")
- .and_then(|v| v.as_str())
- .unwrap_or("")
- .to_string();
- recent_texts.push(RecentText {
+ let text = str_field(row, "text");
+ // Deduplicate by normalized content
+ let normalized = text.to_lowercase().trim().to_string();
+ if normalized.len() < 15 || !seen_texts.insert(normalized) {
+ continue;
+ }
+ key_texts.push(KeyText {
text,
- app_name,
- timestamp,
+ app_name: str_field(row, "app_name"),
+ window_name: str_field(row, "window_name"),
+ timestamp: str_field(row, "timestamp"),
});
}
}
@@ -217,38 +289,52 @@ pub async fn get_activity_summary(
error!("activity summary: texts query failed: {}", e);
}
- // Parse audio summary
+ // Parse audio speakers
let mut speakers = Vec::new();
let mut total_segments: i64 = 0;
- if let Ok(rows) = audio_result {
+ if let Ok(rows) = audio_speakers_result {
if let Some(arr) = rows.as_array() {
for row in arr {
- let name = row
- .get("speaker_name")
- .and_then(|v| v.as_str())
- .unwrap_or("Unknown")
- .to_string();
let segment_count = row
.get("segment_count")
.and_then(|v| v.as_i64())
.unwrap_or(0);
total_segments += segment_count;
speakers.push(SpeakerSummary {
- name,
+ name: str_field(row, "speaker_name"),
segment_count,
});
}
}
- } else if let Err(e) = &audio_result {
- error!("activity summary: audio query failed: {}", e);
+ } else if let Err(e) = &audio_speakers_result {
+ error!("activity summary: audio speakers query failed: {}", e);
+ }
+
+ // Parse audio transcriptions
+ let mut top_transcriptions = Vec::new();
+ if let Ok(rows) = audio_transcripts_result {
+ if let Some(arr) = rows.as_array() {
+ for row in arr {
+ top_transcriptions.push(AudioSegment {
+ transcription: str_field(row, "transcription"),
+ speaker: str_field(row, "speaker"),
+ device: str_field(row, "device"),
+ timestamp: str_field(row, "timestamp"),
+ });
+ }
+ }
+ } else if let Err(e) = &audio_transcripts_result {
+ error!("activity summary: audio transcripts query failed: {}", e);
}
Ok(JsonResponse(ActivitySummaryResponse {
apps,
- recent_texts,
+ windows,
+ key_texts,
audio_summary: AudioSummary {
segment_count: total_segments,
speakers,
+ top_transcriptions,
},
total_frames,
time_range: TimeRange {
@@ -257,3 +343,16 @@ pub async fn get_activity_summary(
},
}))
}
+
+fn str_field(row: &Value, key: &str) -> String {
+ row.get(key)
+ .and_then(|v| v.as_str())
+ .unwrap_or("")
+ .to_string()
+}
+
+fn num_field(row: &Value, key: &str) -> f64 {
+ row.get(key)
+ .and_then(|v| v.as_f64().or_else(|| v.as_str().and_then(|s| s.parse().ok())))
+ .unwrap_or(0.0)
+}