Search through all messages in session, not just first message

- SessionManager now collects text from all user and assistant messages
- Added allMessagesText field containing concatenated message text
- Search now matches against all messages in a session
- More powerful session discovery (e.g., search "write file" finds any session discussing file writing)
This commit is contained in:
Mario Zechner 2025-11-12 09:32:14 +01:00
parent 101a6c4ef3
commit 9dac37d836
2 changed files with 19 additions and 5 deletions

View file

@ -253,6 +253,7 @@ export class SessionManager {
modified: Date;
messageCount: number;
firstMessage: string;
allMessagesText: string;
}> {
const sessions: Array<{
path: string;
@ -261,6 +262,7 @@ export class SessionManager {
modified: Date;
messageCount: number;
firstMessage: string;
allMessagesText: string;
}> = [];
try {
@ -278,6 +280,7 @@ export class SessionManager {
let created = stats.birthtime;
let messageCount = 0;
let firstMessage = "";
const allMessages: string[] = [];
for (const line of lines) {
try {
@ -289,17 +292,25 @@ export class SessionManager {
created = new Date(entry.timestamp);
}
// Count messages
// Count messages and collect all text
if (entry.type === "message") {
messageCount++;
// Get first user message
if (!firstMessage && entry.message.role === "user") {
// Extract text from user and assistant messages
if (entry.message.role === "user" || entry.message.role === "assistant") {
const textContent = entry.message.content
.filter((c: any) => c.type === "text")
.map((c: any) => c.text)
.join(" ");
firstMessage = textContent || "";
if (textContent) {
allMessages.push(textContent);
// Get first user message for display
if (!firstMessage && entry.message.role === "user") {
firstMessage = textContent;
}
}
}
}
} catch {
@ -314,6 +325,7 @@ export class SessionManager {
modified: stats.mtime,
messageCount,
firstMessage: firstMessage || "(no messages)",
allMessagesText: allMessages.join(" "),
});
} catch (error) {
// Skip files that can't be read

View file

@ -18,6 +18,7 @@ interface SessionItem {
modified: Date;
messageCount: number;
firstMessage: string;
allMessagesText: string;
}
/**
@ -57,7 +58,8 @@ class SessionList implements Component {
.split(/\s+/)
.filter((t) => t);
this.filteredSessions = this.allSessions.filter((session) => {
const searchText = session.firstMessage.toLowerCase();
// Search through all messages in the session
const searchText = session.allMessagesText.toLowerCase();
return searchTokens.every((token) => searchText.includes(token));
});
}