refinement fixes

This commit is contained in:
Storme-bit
2026-08-17 00:37:17 -07:00
parent 8f8177615c
commit 7757de76b7
5 changed files with 324 additions and 34 deletions
@@ -172,6 +172,30 @@ function getRecentEpisodes(sessionId, limit = EPISODIC.DEFAULT_RECENT_LIMIT) {
}
// Aggregate stats for a session — count, total tokens, and highest episode id.
// Lets summarization check the token threshold without pulling every episode row.
function getSessionEpisodeStats(sessionId) {
const db = getDB();
return db.prepare(`
SELECT COUNT(*) AS count,
COALESCE(SUM(token_count), 0) AS totalTokens,
COALESCE(MAX(id), 0) AS maxId
FROM episodes
WHERE session_id = ?
`).get(sessionId);
}
// Episodes newer than a given id, in chronological order. Summarization uses
// this to fetch only the un-summarized tail rather than the whole session.
function getEpisodesSince(sessionId, afterId) {
const db = getDB();
return db.prepare(`
SELECT * FROM episodes
WHERE session_id = ? AND id > ?
ORDER BY id ASC
`).all(sessionId, afterId).map(parseRow);
}
// Searches episodes using FTS5 full-text search, ordered by relevance, with a limit
function searchEpisodes(query, limit = EPISODIC.DEFAULT_SEARCH_LIMIT, sessionIds = null) {
const db = getDB();
@@ -247,6 +271,8 @@ module.exports = {
getEpisode,
getEpisodesBySession,
getRecentEpisodes,
getSessionEpisodeStats,
getEpisodesSince,
searchEpisodes,
deleteEpisode,
getEpisodesByProject