muse_session_history
Manage vibe coding session history by saving, retrieving, searching, and updating sessions with code contexts and design decisions.
Instructions
Manages vibe coding session history. Save, retrieve, search, and manage past coding sessions with their code contexts and design decisions.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| action | Yes | Action to perform: save (create new), get (retrieve by ID), update (modify existing), delete (remove), list (get all), search (find by keyword), stats (storage statistics) | |
| sessionId | No | Session ID (required for get, update, delete actions) | |
| title | No | Session title (required for save, optional for update) | |
| summary | No | Session summary (required for save, optional for update) | |
| tags | No | Tags for categorization | |
| codeContexts | No | Array of code context objects | |
| designDecisions | No | Array of design decision objects | |
| metadata | No | Additional metadata | |
| limit | No | Maximum results to return (for list/search, default: 50) | |
| offset | No | Number of results to skip (for list, default: 0) | |
| filterTags | No | Filter by tags (for list) | |
| sortBy | No | Sort field (for list, default: updatedAt) | |
| sortOrder | No | Sort order (for list, default: desc) | |
| keyword | No | Search keyword (required for search action) | |
| searchIn | No | Fields to search in (for search, default: all) |
Implementation Reference
- src/tools/sessionHistory.ts:65-240 (handler)Main handler for the muse_session_history tool. Dispatches to different actions: save, get, update, delete, list, search, stats. Uses sessionStorage core module for persistence.
export async function sessionHistoryTool(input: SessionHistoryInput): Promise<SessionHistoryOutput> { const { action } = input; try { switch (action) { case 'save': { if (!input.title || !input.summary) { return { success: false, action, error: 'title and summary are required for save action' }; } const session = await saveSession({ title: input.title, summary: input.summary, tags: input.tags || [], codeContexts: input.codeContexts || [], designDecisions: input.designDecisions || [], metadata: input.metadata }); return { success: true, action, session, message: `Session saved: ${session.id}` }; } case 'get': { if (!input.sessionId) { return { success: false, action, error: 'sessionId is required for get action' }; } const session = await getSession(input.sessionId); if (!session) { return { success: false, action, error: `Session not found: ${input.sessionId}` }; } return { success: true, action, session, message: `Session retrieved: ${session.title}` }; } case 'update': { if (!input.sessionId) { return { success: false, action, error: 'sessionId is required for update action' }; } const updates: Partial<SessionData> = {}; if (input.title !== undefined) updates.title = input.title; if (input.summary !== undefined) updates.summary = input.summary; if (input.tags !== undefined) updates.tags = input.tags; if (input.codeContexts !== undefined) updates.codeContexts = input.codeContexts; if (input.designDecisions !== undefined) updates.designDecisions = input.designDecisions; if (input.metadata !== undefined) updates.metadata = input.metadata; const session = await updateSession(input.sessionId, updates); return { success: true, action, session, message: `Session updated: ${session.id}` }; } case 'delete': { if (!input.sessionId) { return { success: false, action, error: 'sessionId is required for delete action' }; } const deleted = await deleteSession(input.sessionId); if (!deleted) { return { success: false, action, error: `Session not found: ${input.sessionId}` }; } return { success: true, action, message: `Session deleted: ${input.sessionId}` }; } case 'list': { const { sessions, total } = await listSessions({ limit: input.limit, offset: input.offset, tags: input.filterTags, sortBy: input.sortBy, sortOrder: input.sortOrder }); return { success: true, action, sessions, total, message: `Found ${total} session(s)` }; } case 'search': { if (!input.keyword) { return { success: false, action, error: 'keyword is required for search action' }; } const sessions = await searchSessions(input.keyword, { limit: input.limit, searchIn: input.searchIn }); return { success: true, action, sessions, total: sessions.length, message: `Found ${sessions.length} session(s) matching "${input.keyword}"` }; } case 'stats': { const stats = await getStorageStats(); return { success: true, action, stats, message: `Storage contains ${stats.totalSessions} session(s)` }; } default: return { success: false, action, error: `Unknown action: ${action}` }; } } catch (error) { return { success: false, action, error: error instanceof Error ? error.message : String(error) }; } } - src/stdio.ts:89-92 (handler)Stdio handler that validates input via SessionHistorySchema and delegates to sessionHistoryTool.
muse_session_history: async (args: unknown) => { const validated = validateInput(SessionHistorySchema, args); return sessionHistoryTool(validated as Parameters<typeof sessionHistoryTool>[0]); }, - src/tools/sessionHistory.ts:242-317 (schema)MCP schema definition for the muse_session_history tool, including name, description, and inputSchema with all properties (action, sessionId, title, summary, tags, etc.).
export const sessionHistorySchema = { name: 'muse_session_history', description: 'Manages vibe coding session history. Save, retrieve, search, and manage past coding sessions with their code contexts and design decisions.', inputSchema: { type: 'object', properties: { action: { type: 'string', enum: ['save', 'get', 'update', 'delete', 'list', 'search', 'stats'], description: 'Action to perform: save (create new), get (retrieve by ID), update (modify existing), delete (remove), list (get all), search (find by keyword), stats (storage statistics)' }, sessionId: { type: 'string', description: 'Session ID (required for get, update, delete actions)' }, title: { type: 'string', description: 'Session title (required for save, optional for update)' }, summary: { type: 'string', description: 'Session summary (required for save, optional for update)' }, tags: { type: 'array', items: { type: 'string' }, description: 'Tags for categorization' }, codeContexts: { type: 'array', description: 'Array of code context objects' }, designDecisions: { type: 'array', description: 'Array of design decision objects' }, metadata: { type: 'object', description: 'Additional metadata' }, limit: { type: 'number', description: 'Maximum results to return (for list/search, default: 50)' }, offset: { type: 'number', description: 'Number of results to skip (for list, default: 0)' }, filterTags: { type: 'array', items: { type: 'string' }, description: 'Filter by tags (for list)' }, sortBy: { type: 'string', enum: ['createdAt', 'updatedAt', 'title'], description: 'Sort field (for list, default: updatedAt)' }, sortOrder: { type: 'string', enum: ['asc', 'desc'], description: 'Sort order (for list, default: desc)' }, keyword: { type: 'string', description: 'Search keyword (required for search action)' }, searchIn: { type: 'array', items: { type: 'string', enum: ['title', 'summary', 'tags'] }, description: 'Fields to search in (for search, default: all)' } }, required: ['action'] } }; - src/core/schemas.ts:199-231 (schema)Zod validation schema for session history input. Defines all fields with proper types and validations used by the stdio handler.
export const SessionHistorySchema = z.object({ action: z.enum(['save', 'get', 'update', 'delete', 'list', 'search', 'stats']), sessionId: z.string().optional(), title: z.string().optional(), summary: z.string().optional(), tags: z.array(z.string()).optional(), codeContexts: z.array(z.object({ sessionId: z.string(), timestamp: z.string(), codeBlocks: z.array(z.object({ language: z.string(), code: z.string(), filename: z.string().optional() })), conversationSummary: z.string() })).optional(), designDecisions: z.array(z.object({ id: z.string(), title: z.string(), description: z.string(), rationale: z.string(), category: z.string(), timestamp: z.string() })).optional(), metadata: z.record(z.unknown()).optional(), limit: z.number().optional(), offset: z.number().optional(), filterTags: z.array(z.string()).optional(), sortBy: z.enum(['createdAt', 'updatedAt', 'title']).optional(), sortOrder: z.enum(['asc', 'desc']).optional(), keyword: z.string().optional(), searchIn: z.array(z.enum(['title', 'summary', 'tags'])).optional() }); - src/core/sessionStorage.ts:1-310 (helper)Core session storage module. Persists sessions as JSON files. Supports CRUD operations, listing with filtering/sorting/pagination, keyword search across title/summary/tags, and storage statistics.
/** * 세션 스토리지 모듈 * 바이브 코딩 세션을 저장하고 조회하는 기능 제공 * v2.6: 세션 히스토리 기능 */ import { promises as fs } from 'fs'; import * as path from 'path'; import { logger } from './logger.js'; const storageLogger = logger.child({ module: 'sessionStorage' }); export interface StoredSession { id: string; title: string; summary: string; createdAt: string; updatedAt: string; tags: string[]; codeContextCount: number; designDecisionCount: number; metadata?: Record<string, unknown>; } export interface SessionData { id: string; title: string; summary: string; createdAt: string; updatedAt: string; tags: string[]; codeContexts: Array<{ sessionId: string; timestamp: string; codeBlocks: Array<{ language: string; code: string; filename?: string }>; conversationSummary: string; }>; designDecisions: Array<{ id: string; title: string; description: string; rationale: string; category: string; timestamp: string; }>; metadata?: Record<string, unknown>; } // Default storage path const DEFAULT_STORAGE_DIR = process.env.VIBE_CODING_STORAGE_DIR || path.join(process.env.HOME || process.env.USERPROFILE || '.', '.vibe-coding-mcp', 'sessions'); let storageDir = DEFAULT_STORAGE_DIR; /** * Initialize storage directory */ export async function initializeStorage(customDir?: string): Promise<void> { if (customDir) { storageDir = customDir; } try { await fs.mkdir(storageDir, { recursive: true }); storageLogger.info('Storage initialized', { path: storageDir }); } catch (error) { storageLogger.error('Failed to initialize storage', error as Error); throw error; } } /** * Generate unique session ID */ function generateSessionId(): string { const timestamp = Date.now().toString(36); const random = Math.random().toString(36).substring(2, 8); return `session_${timestamp}_${random}`; } /** * Get session file path */ function getSessionPath(sessionId: string): string { return path.join(storageDir, `${sessionId}.json`); } /** * Save a session */ export async function saveSession(data: Omit<SessionData, 'id' | 'createdAt' | 'updatedAt'>): Promise<SessionData> { await initializeStorage(); const sessionId = generateSessionId(); const now = new Date().toISOString(); const session: SessionData = { id: sessionId, createdAt: now, updatedAt: now, ...data }; const filePath = getSessionPath(sessionId); try { await fs.writeFile(filePath, JSON.stringify(session, null, 2), 'utf-8'); storageLogger.info('Session saved', { sessionId, title: session.title }); return session; } catch (error) { storageLogger.error('Failed to save session', error as Error); throw error; } } /** * Update an existing session */ export async function updateSession(sessionId: string, updates: Partial<Omit<SessionData, 'id' | 'createdAt'>>): Promise<SessionData> { const existing = await getSession(sessionId); if (!existing) { throw new Error(`Session not found: ${sessionId}`); } const updated: SessionData = { ...existing, ...updates, updatedAt: new Date().toISOString() }; const filePath = getSessionPath(sessionId); try { await fs.writeFile(filePath, JSON.stringify(updated, null, 2), 'utf-8'); storageLogger.info('Session updated', { sessionId }); return updated; } catch (error) { storageLogger.error('Failed to update session', error as Error); throw error; } } /** * Get a session by ID */ export async function getSession(sessionId: string): Promise<SessionData | null> { const filePath = getSessionPath(sessionId); try { const content = await fs.readFile(filePath, 'utf-8'); return JSON.parse(content) as SessionData; } catch (error) { if ((error as NodeJS.ErrnoException).code === 'ENOENT') { return null; } storageLogger.error('Failed to read session', error as Error); throw error; } } /** * Delete a session */ export async function deleteSession(sessionId: string): Promise<boolean> { const filePath = getSessionPath(sessionId); try { await fs.unlink(filePath); storageLogger.info('Session deleted', { sessionId }); return true; } catch (error) { if ((error as NodeJS.ErrnoException).code === 'ENOENT') { return false; } storageLogger.error('Failed to delete session', error as Error); throw error; } } /** * List all sessions (summary only) */ export async function listSessions(options?: { limit?: number; offset?: number; tags?: string[]; sortBy?: 'createdAt' | 'updatedAt' | 'title'; sortOrder?: 'asc' | 'desc'; }): Promise<{ sessions: StoredSession[]; total: number }> { await initializeStorage(); const { limit = 50, offset = 0, tags, sortBy = 'updatedAt', sortOrder = 'desc' } = options || {}; try { const files = await fs.readdir(storageDir); const sessionFiles = files.filter(f => f.endsWith('.json')); const sessions: StoredSession[] = []; for (const file of sessionFiles) { try { const content = await fs.readFile(path.join(storageDir, file), 'utf-8'); const data = JSON.parse(content) as SessionData; // Filter by tags if specified if (tags && tags.length > 0) { const hasTag = tags.some(tag => data.tags?.includes(tag)); if (!hasTag) continue; } sessions.push({ id: data.id, title: data.title, summary: data.summary, createdAt: data.createdAt, updatedAt: data.updatedAt, tags: data.tags || [], codeContextCount: data.codeContexts?.length || 0, designDecisionCount: data.designDecisions?.length || 0, metadata: data.metadata }); } catch { // Skip invalid files continue; } } // Sort sessions.sort((a, b) => { const aVal = a[sortBy] || ''; const bVal = b[sortBy] || ''; const cmp = aVal < bVal ? -1 : aVal > bVal ? 1 : 0; return sortOrder === 'desc' ? -cmp : cmp; }); // Paginate const total = sessions.length; const paginated = sessions.slice(offset, offset + limit); return { sessions: paginated, total }; } catch (error) { storageLogger.error('Failed to list sessions', error as Error); throw error; } } /** * Search sessions by keyword */ export async function searchSessions(keyword: string, options?: { limit?: number; searchIn?: ('title' | 'summary' | 'tags')[]; }): Promise<StoredSession[]> { const { limit = 20, searchIn = ['title', 'summary', 'tags'] } = options || {}; const lowerKeyword = keyword.toLowerCase(); const { sessions } = await listSessions({ limit: 1000 }); const matches = sessions.filter(session => { if (searchIn.includes('title') && session.title.toLowerCase().includes(lowerKeyword)) { return true; } if (searchIn.includes('summary') && session.summary.toLowerCase().includes(lowerKeyword)) { return true; } if (searchIn.includes('tags') && session.tags.some(t => t.toLowerCase().includes(lowerKeyword))) { return true; } return false; }); return matches.slice(0, limit); } /** * Get storage statistics */ export async function getStorageStats(): Promise<{ totalSessions: number; totalCodeContexts: number; totalDesignDecisions: number; storageDir: string; oldestSession?: string; newestSession?: string; }> { const { sessions, total } = await listSessions({ limit: 1000 }); let totalCodeContexts = 0; let totalDesignDecisions = 0; for (const session of sessions) { totalCodeContexts += session.codeContextCount; totalDesignDecisions += session.designDecisionCount; } // Sort by createdAt to find oldest/newest const sorted = [...sessions].sort((a, b) => new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime() ); return { totalSessions: total, totalCodeContexts, totalDesignDecisions, storageDir, oldestSession: sorted[0]?.createdAt, newestSession: sorted[sorted.length - 1]?.createdAt }; }