feat: Implement session management and search functionality

- Added SDK session, observation, and summary types to types.ts.
- Refactored worker-service to use SessionStore for session management.
- Created SessionSearch class for FTS5 full-text search and structured queries.
- Implemented SessionStore for CRUD operations on SDK sessions, observations, and summaries.
- Added migrations for database schema updates, including new columns and constraints.
- Enhanced search capabilities with filters for projects, types, concepts, and date ranges.
This commit is contained in:
Alex Newman
2025-10-18 20:15:55 -04:00
parent c27682c799
commit 115270c35e
18 changed files with 807 additions and 85 deletions
+2 -2
View File
@@ -1,4 +1,4 @@
import { HooksDatabase } from '../services/sqlite/HooksDatabase.js';
import { SessionStore } from '../services/sqlite/SessionStore.js';
export interface SessionEndInput {
session_id: string;
@@ -46,7 +46,7 @@ export async function cleanupHook(input?: SessionEndInput): Promise<void> {
console.error('[claude-mem cleanup] Searching for active SDK session', { session_id, reason });
// Find active SDK session
const db = new HooksDatabase();
const db = new SessionStore();
const session = db.findActiveSDKSession(session_id);
if (!session) {
+2 -2
View File
@@ -1,5 +1,5 @@
import path from 'path';
import { HooksDatabase } from '../services/sqlite/HooksDatabase.js';
import { SessionStore } from '../services/sqlite/SessionStore.js';
export interface SessionStartInput {
session_id?: string;
@@ -20,7 +20,7 @@ export function contextHook(input?: SessionStartInput): void {
const cwd = input?.cwd ?? process.cwd();
const project = cwd ? path.basename(cwd) : 'unknown-project';
const db = new HooksDatabase();
const db = new SessionStore();
try {
const sessions = db.getRecentSessionsWithStatus(project, 3);
+2 -2
View File
@@ -1,5 +1,5 @@
import path from 'path';
import { HooksDatabase } from '../services/sqlite/HooksDatabase.js';
import { SessionStore } from '../services/sqlite/SessionStore.js';
import { createHookResponse } from './hook-response.js';
export interface UserPromptSubmitInput {
@@ -42,7 +42,7 @@ export async function newHook(input?: UserPromptSubmitInput): Promise<void> {
const { session_id, cwd, prompt } = input;
const project = path.basename(cwd);
const db = new HooksDatabase();
const db = new SessionStore();
try {
// Check for any existing session (active, failed, or completed)
+2 -2
View File
@@ -1,4 +1,4 @@
import { HooksDatabase } from '../services/sqlite/HooksDatabase.js';
import { SessionStore } from '../services/sqlite/SessionStore.js';
import { createHookResponse } from './hook-response.js';
import { logger } from '../utils/logger.js';
@@ -32,7 +32,7 @@ export async function saveHook(input?: PostToolUseInput): Promise<void> {
return;
}
const db = new HooksDatabase();
const db = new SessionStore();
const session = db.findActiveSDKSession(session_id);
if (!session) {
+2 -2
View File
@@ -1,4 +1,4 @@
import { HooksDatabase } from '../services/sqlite/HooksDatabase.js';
import { SessionStore } from '../services/sqlite/SessionStore.js';
import { createHookResponse } from './hook-response.js';
import { logger } from '../utils/logger.js';
@@ -18,7 +18,7 @@ export async function summaryHook(input?: StopInput): Promise<void> {
}
const { session_id } = input;
const db = new HooksDatabase();
const db = new SessionStore();
const session = db.findActiveSDKSession(session_id);
if (!session) {