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

fix(chat-sidebar): show pipe-run rows the moment they finish

Louis Beaumont03d04a2f9e45
diff --git a/apps/screenpipe-app-tauri/lib/chat-storage.ts b/apps/screenpipe-app-tauri/lib/chat-storage.ts
index 1fc3e040b..6f19d7c24 100644
--- a/apps/screenpipe-app-tauri/lib/chat-storage.ts
+++ b/apps/screenpipe-app-tauri/lib/chat-storage.ts
@@ -252,7 +252,7 @@ async function orderedConversationEntries(dir: string): Promise<ConversationEntr
return ordered;
}
-function conversationMetaFromJson(conv: any): ConversationMeta | null {
+export function conversationMetaFromJson(conv: any): ConversationMeta | null {
if (!conv || typeof conv.id !== "string") return null;
const messages = Array.isArray(conv.messages) ? conv.messages : [];
diff --git a/apps/screenpipe-app-tauri/lib/events/pipe-run-recorder.ts b/apps/screenpipe-app-tauri/lib/events/pipe-run-recorder.ts
index 64d4f8549..9c7ece1cb 100644
--- a/apps/screenpipe-app-tauri/lib/events/pipe-run-recorder.ts
+++ b/apps/screenpipe-app-tauri/lib/events/pipe-run-recorder.ts
@@ -38,7 +38,10 @@ import {
} from "./bus";
import type { AgentEventEnvelope, AgentInnerEvent } from "./types";
import { parsePipeSessionId } from "./types";
-import { saveConversationFile } from "@/lib/chat-storage";
+import {
+ conversationMetaFromJson,
+ saveConversationFile,
+} from "@/lib/chat-storage";
import { parsePipeNdjsonToMessages } from "@/lib/pipe-ndjson-to-chat";
import type { ChatConversation, ChatMessage } from "@/lib/hooks/use-settings";
@@ -217,6 +220,24 @@ async function finalizeBuffer(sid: string, buf: PipeRunBuffer): Promise<void> {
await saveConversationFile(conv);
} catch (e) {
console.warn("[pipe-run-recorder] save failed for", sid, e);
+ return;
+ }
+
+ // Sidebar reads the in-memory chat-store, not disk. Without this
+ // upsert the new pipe-run row wouldn't show up until the next app
+ // restart (when hydrate() re-scans ~/.screenpipe/chats/). We use the
+ // same meta → SessionRecord transform as the boot hydrate path so
+ // both surfaces produce identically-shaped rows.
+ try {
+ const { useChatStore, sessionRecordFromMeta } = await import(
+ "@/lib/stores/chat-store"
+ );
+ const meta = conversationMetaFromJson(conv);
+ if (meta) {
+ useChatStore.getState().actions.upsert(sessionRecordFromMeta(meta));
+ }
+ } catch (e) {
+ console.warn("[pipe-run-recorder] sidebar upsert failed for", sid, e);
}
}
diff --git a/apps/screenpipe-app-tauri/lib/stores/chat-store.ts b/apps/screenpipe-app-tauri/lib/stores/chat-store.ts
index c5538ba8f..321fdb95c 100644
--- a/apps/screenpipe-app-tauri/lib/stores/chat-store.ts
+++ b/apps/screenpipe-app-tauri/lib/stores/chat-store.ts
@@ -22,6 +22,7 @@
import { create } from "zustand";
import type { ConversationKind, PipeContext } from "@/lib/hooks/use-settings";
+import type { ConversationMeta } from "@/lib/chat-storage";
export type SessionStatus =
| "idle" // not currently producing output
@@ -542,6 +543,28 @@ export const useChatStore = create<ChatStore>((set) => ({
* selector returns the same reference forever. Safe to use in deps. */
export const useChatActions = () => useChatStore((s) => s.actions);
+/** Build a fresh SessionRecord from on-disk metadata. Used by both the
+ * boot-time hydrate path and the pipe-run recorder so the sidebar sees
+ * identically-shaped rows whether they were loaded at startup or upserted
+ * the moment a pipe finishes. unread is false: persisted-from-disk rows
+ * aren't user-actionable in the inbox sense. */
+export function sessionRecordFromMeta(m: ConversationMeta): SessionRecord {
+ return {
+ id: m.id,
+ title: m.title || "untitled",
+ preview: "",
+ status: "idle",
+ messageCount: m.messageCount,
+ createdAt: m.createdAt,
+ updatedAt: m.updatedAt,
+ pinned: m.pinned,
+ unread: false,
+ lastUserMessageAt: m.lastUserMessageAt,
+ kind: m.kind,
+ pipeContext: m.pipeContext,
+ };
+}
+
/**
* "+ new chat" semantics. If the user already has an empty chat
* (no user message sent yet), return its id instead of spawning a
diff --git a/apps/screenpipe-app-tauri/lib/stores/pi-event-router.ts b/apps/screenpipe-app-tauri/lib/stores/pi-event-router.ts
index a169fd131..24aff2706 100644
--- a/apps/screenpipe-app-tauri/lib/stores/pi-event-router.ts
+++ b/apps/screenpipe-app-tauri/lib/stores/pi-event-router.ts
@@ -62,6 +62,7 @@ import {
import type { ChatConversation } from "@/lib/hooks/use-settings";
import {
useChatStore,
+ sessionRecordFromMeta,
type SessionStatus,
type SessionRecord,
} from "@/lib/stores/chat-store";
@@ -313,22 +314,7 @@ async function hydrate() {
limit: CHAT_HISTORY_INITIAL_LIMIT,
includeHidden: false,
});
- const records: SessionRecord[] = metas
- .map((m) => ({
- id: m.id,
- title: m.title || "untitled",
- preview: "",
- status: "idle" as const,
- messageCount: m.messageCount,
- createdAt: m.createdAt,
- updatedAt: m.updatedAt,
- pinned: m.pinned,
- // History reload doesn't count as new activity — start clean.
- unread: false,
- lastUserMessageAt: m.lastUserMessageAt,
- kind: m.kind,
- pipeContext: m.pipeContext,
- }));
+ const records: SessionRecord[] = metas.map(sessionRecordFromMeta);
useChatStore.getState().actions.hydrateFromDisk(records);
} catch {
// Storage may not be ready yet on first launch — non-fatal.