/**
 * Session state management for TAKT
 *
 * Manages the last task execution state for interactive mode notification.
 */
import { existsSync, readFileSync, unlinkSync } from 'node:fs';
import { join } from 'node:path';
import { getProjectConfigDir, ensureDir } from '../paths.js';
import { writeFileAtomic } from './sessionStore.js';
/**
 * Get path for storing session state
 */
export function getSessionStatePath(projectDir) {
    return join(getProjectConfigDir(projectDir), 'session-state.json');
}
/**
 * Load session state from file
 * Returns null if file doesn't exist or parsing fails
 */
export function loadSessionState(projectDir) {
    const path = getSessionStatePath(projectDir);
    if (!existsSync(path)) {
        return null;
    }
    try {
        const content = readFileSync(path, 'utf-8');
        return JSON.parse(content);
    }
    catch {
        return null;
    }
}
/**
 * Save session state to file (atomic write)
 */
export function saveSessionState(projectDir, state) {
    const path = getSessionStatePath(projectDir);
    ensureDir(getProjectConfigDir(projectDir));
    writeFileAtomic(path, JSON.stringify(state, null, 2));
}
/**
 * Clear session state file
 * Does nothing if file doesn't exist
 */
export function clearSessionState(projectDir) {
    const path = getSessionStatePath(projectDir);
    if (existsSync(path)) {
        unlinkSync(path);
    }
}
//# sourceMappingURL=sessionState.js.map