"use strict";
/**
 * AI Context Manager
 * Handles loading, saving, and clearing AI context files
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.AIContextManager = exports.AI_CONTEXT_PATH = exports.OCULUM_DIR = exports.AI_CONTEXT_FILE = void 0;
const fs_1 = require("fs");
const path_1 = require("path");
/** AI context file name */
exports.AI_CONTEXT_FILE = 'ai-context.md';
/** Directory for oculum files */
exports.OCULUM_DIR = '.oculum';
/** Full path to AI context file (relative to project root) */
exports.AI_CONTEXT_PATH = `${exports.OCULUM_DIR}/${exports.AI_CONTEXT_FILE}`;
/**
 * Manages AI context files for IDE consumption
 */
class AIContextManager {
    constructor(options) {
        // Support both old string arg and new options object
        if (typeof options === 'string') {
            this.projectPath = options;
        }
        else {
            this.projectPath = options.projectPath;
        }
        this.contextPath = (0, path_1.join)(this.projectPath, exports.OCULUM_DIR, exports.AI_CONTEXT_FILE);
    }
    /**
     * Get the full path to the AI context file
     */
    getContextPath() {
        return this.contextPath;
    }
    /**
     * Save AI context to .oculum/ai-context.md
     */
    saveContext(content) {
        try {
            // Ensure .oculum directory exists
            const oculumDir = (0, path_1.join)(this.projectPath, exports.OCULUM_DIR);
            if (!(0, fs_1.existsSync)(oculumDir)) {
                (0, fs_1.mkdirSync)(oculumDir, { recursive: true });
            }
            // Write content to file
            (0, fs_1.writeFileSync)(this.contextPath, content);
            return { success: true, path: this.contextPath };
        }
        catch (err) {
            return {
                success: false,
                path: this.contextPath,
                error: `Failed to save AI context: ${err instanceof Error ? err.message : 'Unknown error'}`,
            };
        }
    }
    /**
     * Load AI context from .oculum/ai-context.md
     */
    loadContext() {
        if (!(0, fs_1.existsSync)(this.contextPath)) {
            return { found: false };
        }
        try {
            const content = (0, fs_1.readFileSync)(this.contextPath, 'utf-8');
            return { found: true, content };
        }
        catch (err) {
            return {
                found: false,
                error: `Failed to read AI context: ${err instanceof Error ? err.message : 'Unknown error'}`,
            };
        }
    }
    /**
     * Clear (delete) the AI context file
     */
    clearContext() {
        const existed = (0, fs_1.existsSync)(this.contextPath);
        if (!existed) {
            return { success: true, existed: false };
        }
        try {
            (0, fs_1.unlinkSync)(this.contextPath);
            return { success: true, existed: true };
        }
        catch (err) {
            return {
                success: false,
                existed: true,
                error: `Failed to clear AI context: ${err instanceof Error ? err.message : 'Unknown error'}`,
            };
        }
    }
    /**
     * Check if an AI context file exists
     */
    hasContext() {
        return (0, fs_1.existsSync)(this.contextPath);
    }
}
exports.AIContextManager = AIContextManager;
//# sourceMappingURL=manager.js.map