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

chore: commit pending local changes from other agents

Louis Beaumont04214ebe9927
diff --git a/apps/screenpipe-app-tauri/components/rewind/timeline/timeline-tag-toolbar.tsx b/apps/screenpipe-app-tauri/components/rewind/timeline/timeline-tag-toolbar.tsx
index 0cd38b32d..91a25e9bd 100644
--- a/apps/screenpipe-app-tauri/components/rewind/timeline/timeline-tag-toolbar.tsx
+++ b/apps/screenpipe-app-tauri/components/rewind/timeline/timeline-tag-toolbar.tsx
@@ -22,6 +22,7 @@ import {
} from "@/components/ui/alert-dialog";
import posthog from "posthog-js";
import { PipeAIIcon } from "@/components/pipe-ai-icon";
+import { showChatWithPrefill } from "@/lib/chat-utils";
import { type TemplatePipe } from "@/lib/hooks/use-pipes";
import { AnimatePresence, motion } from "framer-motion";
@@ -71,8 +72,6 @@ export function TimelineTagToolbar({ anchorRect, onAskAI, onRunPipe, templatePip
const [showDeleteConfirm, setShowDeleteConfirm] = useState(false);
const [isDeleting, setIsDeleting] = useState(false);
const [isRetranscribing, setIsRetranscribing] = useState(false);
- const [showRetranscribe, setShowRetranscribe] = useState(false);
- const [retranscribePrompt, setRetranscribePrompt] = useState("");
const inputRef = useRef<HTMLInputElement>(null);
// eslint-disable-next-line react-hooks/exhaustive-deps
@@ -203,51 +202,21 @@ export function TimelineTagToolbar({ anchorRect, onAskAI, onRunPipe, templatePip
if (!selectionRange || isRetranscribing) return;
setIsRetranscribing(true);
- const body: any = {
- start: selectionRange.start.toISOString(),
- end: selectionRange.end.toISOString(),
- };
- if (retranscribePrompt.trim()) {
- body.prompt = retranscribePrompt.trim();
- }
- const hadPrompt = !!retranscribePrompt.trim();
-
- // close panel immediately — the request runs server-side
- setShowRetranscribe(false);
- setRetranscribePrompt("");
-
- const mins = Math.round((selectionRange.end.getTime() - selectionRange.start.getTime()) / 60000);
- const durLabel = mins >= 60 ? `${Math.floor(mins / 60)}h ${mins % 60}m` : mins >= 1 ? `${mins}m` : "<1m";
- toast({
- title: "re-transcribing audio...",
- description: `${durLabel} of audio — runs in background, you can close this panel`,
- duration: 60_000,
- });
+ const start = selectionRange.start.toISOString();
+ const end = selectionRange.end.toISOString();
try {
- const resp = await fetch("http://localhost:3030/audio/retranscribe", {
- method: "POST",
- headers: { "Content-Type": "application/json" },
- body: JSON.stringify(body),
+ posthog.capture("timeline_retranscribe", { method: "ai_chat" });
+ await showChatWithPrefill({
+ context: "",
+ prompt: `please read your screenpipe-api skill first, then retranscribe the audio from ${start} to ${end}. after retranscribing, ask me if i want to assign speaker names to the different speakers in the transcription.`,
+ autoSend: true,
+ source: "retranscribe-button",
});
- if (!resp.ok) throw new Error(await resp.text());
- const data = await resp.json();
- toast({
- title: "re-transcription done",
- description: `${data.chunks_processed} audio chunks updated`,
- });
- posthog.capture("timeline_retranscribe", {
- chunks_processed: data.chunks_processed,
- had_prompt: hadPrompt,
- });
- clearOcrCache();
- await clearTimelineCache();
- } catch (e) {
- toast({ title: "re-transcription failed", description: String(e), variant: "destructive" });
} finally {
setIsRetranscribing(false);
}
- }, [selectionRange, isRetranscribing, retranscribePrompt]);
+ }, [selectionRange, isRetranscribing]);
// Early return AFTER all hooks
if (!selectionRange || !anchorRect || frameIds.length === 0) {
@@ -452,10 +421,10 @@ export function TimelineTagToolbar({ anchorRect, onAskAI, onRunPipe, templatePip
</div>
)}
<button
- onClick={() => setShowRetranscribe(!showRetranscribe)}
+ onClick={handleRetranscribe}
disabled={isRetranscribing}
className="flex items-center gap-1 text-xs px-2 py-1 rounded-md border border-border hover:bg-muted transition-colors flex-shrink-0"
- title="re-transcribe audio in this range"
+ title="re-transcribe audio in this range via AI"
>
{isRetranscribing ? (
<Loader2 className="w-3 h-3 animate-spin" />
@@ -481,39 +450,6 @@ export function TimelineTagToolbar({ anchorRect, onAskAI, onRunPipe, templatePip
</div>
)}
- {/* Re-transcribe panel */}
- {showRetranscribe && (
- <div className="border border-border rounded-lg p-2 bg-muted/30 space-y-2">
- <input
- type="text"
- value={retranscribePrompt}
- onChange={(e) => setRetranscribePrompt(e.target.value)}
- placeholder="hint words: e.g. screenpipe, posthog..."
- className="w-full text-xs px-2 py-1 rounded-md border border-border bg-background text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50"
- />
- <button
- onClick={handleRetranscribe}
- disabled={isRetranscribing}
- className="w-full text-xs px-2 py-1.5 rounded-md bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-50 disabled:cursor-not-allowed flex items-center justify-center gap-1"
- >
- {isRetranscribing ? (
- <>
- <Loader2 className="w-3 h-3 animate-spin" />
- processing...
- </>
- ) : (
- <>
- <RefreshCw className="w-3 h-3" />
- re-transcribe
- </>
- )}
- </button>
- <p className="text-[10px] text-muted-foreground leading-tight">
- runs in background — safe to close this panel
- </p>
- </div>
- )}
-
{/* Quick tag buttons */}
<div className="flex flex-wrap gap-1.5 max-h-[60px] overflow-y-auto scrollbar-hide">
{quickTags.map((tag) => (
diff --git a/apps/screenpipe-app-tauri/components/standalone-chat.tsx b/apps/screenpipe-app-tauri/components/standalone-chat.tsx
index 452c445aa..2b2329227 100644
--- a/apps/screenpipe-app-tauri/components/standalone-chat.tsx
+++ b/apps/screenpipe-app-tauri/components/standalone-chat.tsx
@@ -1001,15 +1001,6 @@ export function StandaloneChat({ className }: { className?: string } = {}) {
const fullMessage = `${context}\n\n${prompt}`;
// Start a new conversation then send
(async () => {
- if (piInfo?.running) {
- try {
- // Abort + new_session now await completion — no sleeps needed
- await commands.piAbort(PI_CHAT_SESSION);
- await commands.piNewSession(PI_CHAT_SESSION);
- } catch (e) {
- console.warn("[Pi] Failed to reset session:", e);
- }
- }
// Clear all streaming state so sendPiMessage doesn't think a message is in-flight
piStreamingTextRef.current = "";
piMessageIdRef.current = null;
@@ -1039,6 +1030,16 @@ export function StandaloneChat({ className }: { className?: string } = {}) {
};
const ready = piInfo?.running || await waitForPi(10000);
if (ready) {
+ // Reset Pi session AFTER confirming it's running to clear any
+ // stale isStreaming state from a previous conversation.
+ // This must happen here, not earlier — on fresh page loads
+ // (e.g. navigateHomeAndPrefill), piInfo is null at mount time
+ // so gating on piInfo?.running would skip this entirely.
+ try {
+ await commands.piNewSession(PI_CHAT_SESSION);
+ } catch (e) {
+ console.warn("[Pi] Failed to reset session before auto-send:", e);
+ }
// Signal that the next sendPiMessage call should bypass the piInfo guard
// (we just confirmed Pi is running via waitForPi but React state may be stale)
autoSendBypassRef.current = true;
diff --git a/crates/screenpipe-audio/src/transcription/transcription_result.rs b/crates/screenpipe-audio/src/transcription/transcription_result.rs
index a013f8683..20e5f4915 100644
--- a/crates/screenpipe-audio/src/transcription/transcription_result.rs
+++ b/crates/screenpipe-audio/src/transcription/transcription_result.rs
@@ -164,6 +164,11 @@ pub async fn get_or_create_speaker_from_embedding(
) -> Result<Speaker, anyhow::Error> {
let speaker = db.get_speaker_from_embedding(embedding).await?;
if let Some(speaker) = speaker {
+ debug!(
+ "matched speaker id={} name={:?}",
+ speaker.id,
+ if speaker.name.is_empty() { "unnamed" } else { &speaker.name }
+ );
// Improve cluster over time: update centroid and store diverse embeddings
if let Err(e) = db.update_speaker_centroid(speaker.id, embedding).await {
debug!("failed to update speaker centroid: {}", e);
@@ -173,6 +178,7 @@ pub async fn get_or_create_speaker_from_embedding(
}
Ok(speaker)
} else {
+ // insert_speaker logs the creation at info level
let speaker = db.insert_speaker(embedding).await?;
Ok(speaker)
}
diff --git a/crates/screenpipe-db/src/db.rs b/crates/screenpipe-db/src/db.rs
index 98d4efc06..0c096b47d 100644
--- a/crates/screenpipe-db/src/db.rs
+++ b/crates/screenpipe-db/src/db.rs
@@ -869,6 +869,11 @@ impl DatabaseManager {
.await?;
tx.commit().await?;
+ info!(
+ "created new speaker id={} (no existing match within threshold)",
+ id
+ );
+
Ok(Speaker {
id,
name: String::new(),
@@ -946,7 +951,7 @@ impl DatabaseManager {
/// Add an embedding to a speaker's stored embeddings (up to max_stored).
/// If at capacity, replaces the most redundant embedding (closest to centroid)
- /// with the new one if it's more diverse.
+ /// to maintain diversity and adapt to changing voice conditions.
pub async fn add_embedding_to_speaker(
&self,
speaker_id: i64,
@@ -960,9 +965,10 @@ impl DatabaseManager {
.fetch_one(&self.pool)
.await?;
+ let bytes: &[u8] = embedding.as_bytes();
+
if (count as usize) < max_stored {
// Under capacity — just insert
- let bytes: &[u8] = embedding.as_bytes();
sqlx::query(
"INSERT INTO speaker_embeddings (embedding, speaker_id) VALUES (vec_f32(?1), ?2)",
)
@@ -970,18 +976,63 @@ impl DatabaseManager {
.bind(speaker_id)
.execute(&self.pool)
.await?;
+ } else {
+ // At capacity — replace the most redundant embedding (closest to centroid)
+ // to keep the collection diverse and adapting to voice drift.
+ // The centroid already represents the average, so the embedding nearest to it
+ // carries the least unique information.
+ let centroid_blob: Option<(Option<Vec<u8>>,)> =
+ sqlx::query_as("SELECT centroid FROM speakers WHERE id = ?1")
+ .bind(speaker_id)
+ .fetch_optional(&self.pool)
+ .await?;
+
+ if let Some((Some(centroid_bytes),)) = centroid_blob {
+ // Find the stored embedding closest to the centroid (most redundant)
+ let most_redundant: Option<(i64,)> = sqlx::query_as(
+ "SELECT id FROM speaker_embeddings \
+ WHERE speaker_id = ?1 \
+ ORDER BY vec_distance_cosine(embedding, vec_f32(?2)) ASC \
+ LIMIT 1",
+ )
+ .bind(speaker_id)
+ .bind(&centroid_bytes[..])
+ .fetch_optional(&self.pool)
+ .await?;
+
+ if let Some((redundant_id,)) = most_redundant {
+ // Replace it with the new embedding
+ sqlx::query(
+ "UPDATE speaker_embeddings SET embedding = vec_f32(?1) WHERE id = ?2",
+ )
+ .bind(bytes)
+ .bind(redundant_id)
+ .execute(&self.pool)
+ .await?;
+ debug!(
+ "speaker {}: rotated embedding {} (closest to centroid) with new sample",
+ speaker_id, redundant_id
+ );
+ }
+ }
}
- // At capacity — skip (diversity replacement is complex in SQL, centroid handles drift)
Ok(())
}
- /// Update a speaker's running centroid: new = (old * count + embedding) / (count + 1)
+ /// Update a speaker's running centroid with exponential decay.
+ /// Uses capped effective count (max 50) so new embeddings always contribute
+ /// at least ~2%, preventing centroid stagnation after many samples.
pub async fn update_speaker_centroid(
&self,
speaker_id: i64,
embedding: &[f32],
) -> Result<(), SqlxError> {
+ // Cap for the running average denominator. After this many samples,
+ // each new embedding contributes ~1/MAX_EFFECTIVE_COUNT to the centroid,
+ // keeping it responsive to voice drift over time.
+ const MAX_EFFECTIVE_COUNT: i64 = 50;
+
// Get current centroid and count
let row: Option<(Option<Vec<u8>>, i64)> =
sqlx::query_as("SELECT centroid, embedding_count FROM speakers WHERE id = ?1")
@@ -991,16 +1042,16 @@ impl DatabaseManager {
let (new_centroid, new_count) = match row {
Some((Some(blob), count)) if blob.len() == 512 * 4 => {
- // Update running average
+ // Update running average with capped effective count
let old: Vec<f32> = blob
.chunks_exact(4)
.map(|c| f32::from_le_bytes([c[0], c[1], c[2], c[3]]))
.collect();
- let n = count as f32;
+ let effective_n = count.min(MAX_EFFECTIVE_COUNT) as f32;
let new: Vec<f32> = old
.iter()
.zip(embedding.iter())
- .map(|(o, e)| (o * n + e) / (n + 1.0))
+ .map(|(o, e)| (o * effective_n + e) / (effective_n + 1.0))
.collect();
(new, count + 1)
}