/** * Shared utility: get current session ID from environment or cache file. * Extracted from crud.ts during task-mcp → session-mcp fork (CF-762). */ import * as fs from 'fs'; import * as path from 'path'; import * as os from 'os'; export function getSessionId(): string { if (process.env.CLAUDE_SESSION_ID) { return process.env.CLAUDE_SESSION_ID; } const cacheFile = path.join(os.homedir(), '.cache', 'session-memory', 'current_session'); try { const sessionId = fs.readFileSync(cacheFile, 'utf-8').trim(); if (sessionId) return sessionId; } catch { // File doesn't exist or can't be read } const now = new Date(); const timestamp = now.toISOString().replace(/[-:T]/g, '').slice(0, 15); return `session_${timestamp}`; }