"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.VIM_ENABLED_KEY = exports.PREFERRED_COMPACTION_MODEL_KEY = exports.USE_1M_CONTEXT_KEY = exports.getThinkingLevelKey = void 0;
exports.getModelKey = getModelKey;
exports.getInputKey = getInputKey;
exports.getAutoRetryKey = getAutoRetryKey;
exports.getRetryStateKey = getRetryStateKey;
exports.getLastThinkingByModelKey = getLastThinkingByModelKey;
exports.getCancelledCompactionKey = getCancelledCompactionKey;
exports.getModeKey = getModeKey;
exports.getRuntimeKey = getRuntimeKey;
exports.getCompactContinueMessageKey = getCompactContinueMessageKey;
exports.getReviewExpandStateKey = getReviewExpandStateKey;
exports.getFileTreeExpandStateKey = getFileTreeExpandStateKey;
exports.getReviewSearchStateKey = getReviewSearchStateKey;
exports.copyWorkspaceStorage = copyWorkspaceStorage;
exports.deleteWorkspaceStorage = deleteWorkspaceStorage;
/**
 * LocalStorage Key Constants and Helpers
 * These keys are used for persisting state in localStorage
 */
/**
 * Helper to create a thinking level storage key for a workspace
 * Format: "thinkingLevel:{workspaceId}"
 */
const getThinkingLevelKey = (workspaceId) => `thinkingLevel:${workspaceId}`;
exports.getThinkingLevelKey = getThinkingLevelKey;
/**
 * Get the localStorage key for the user's preferred model for a workspace
 */
function getModelKey(workspaceId) {
    return `model:${workspaceId}`;
}
/**
 * Get the localStorage key for the input text for a workspace
 */
function getInputKey(workspaceId) {
    return `input:${workspaceId}`;
}
/**
 * Get the localStorage key for auto-retry preference for a workspace
 */
function getAutoRetryKey(workspaceId) {
    return `${workspaceId}-autoRetry`;
}
/**
 * Get the localStorage key for retry state for a workspace
 * Stores: { attempt, totalRetryTime, retryStartTime }
 */
function getRetryStateKey(workspaceId) {
    return `${workspaceId}-retryState`;
}
/**
 * Get the localStorage key for the last active thinking level used for a model
 * Stores only active levels ("low" | "medium" | "high"), never "off"
 * Format: "lastThinkingByModel:{modelName}"
 */
function getLastThinkingByModelKey(modelName) {
    return `lastThinkingByModel:${modelName}`;
}
/**
 * Get storage key for cancelled compaction tracking.
 * Stores compaction-request user message ID to verify freshness across reloads.
 */
function getCancelledCompactionKey(workspaceId) {
    return `workspace:${workspaceId}:cancelled-compaction`;
}
/**
 * Get the localStorage key for the UI mode for a workspace
 * Format: "mode:{workspaceId}"
 */
function getModeKey(workspaceId) {
    return `mode:${workspaceId}`;
}
/**
 * Get the localStorage key for the default runtime for a project
 * Stores the last successfully used runtime config when creating a workspace
 * Format: "runtime:{projectPath}"
 */
function getRuntimeKey(projectPath) {
    return `runtime:${projectPath}`;
}
/**
 * Get the localStorage key for the 1M context preference (global)
 * Format: "use1MContext"
 */
exports.USE_1M_CONTEXT_KEY = "use1MContext";
/**
 * Get the localStorage key for the preferred compaction model (global)
 * Format: "preferredCompactionModel"
 */
exports.PREFERRED_COMPACTION_MODEL_KEY = "preferredCompactionModel";
/**
 * Get the localStorage key for vim mode preference (global)
 * Format: "vimEnabled"
 */
exports.VIM_ENABLED_KEY = "vimEnabled";
/**
 * Get the localStorage key for the compact continue message for a workspace
 * Temporarily stores the continuation prompt for the current compaction
 * Should be deleted immediately after use to prevent bugs
 */
function getCompactContinueMessageKey(workspaceId) {
    return `compactContinueMessage:${workspaceId}`;
}
/**
 * Get the localStorage key for hunk expand/collapse state in Review tab
 * Stores user's manual expand/collapse preferences per hunk
 * Format: "reviewExpandState:{workspaceId}"
 */
function getReviewExpandStateKey(workspaceId) {
    return `reviewExpandState:${workspaceId}`;
}
/**
 * Get the localStorage key for FileTree expand/collapse state in Review tab
 * Stores directory expand/collapse preferences per workspace
 * Format: "fileTreeExpandState:{workspaceId}"
 */
function getFileTreeExpandStateKey(workspaceId) {
    return `fileTreeExpandState:${workspaceId}`;
}
/**
 * Get the localStorage key for unified Review search state per workspace
 * Stores: { input: string, useRegex: boolean, matchCase: boolean }
 * Format: "reviewSearchState:{workspaceId}"
 */
function getReviewSearchStateKey(workspaceId) {
    return `reviewSearchState:${workspaceId}`;
}
/**
 * List of workspace-scoped key functions that should be copied on fork and deleted on removal
 * Note: Excludes ephemeral keys like getCompactContinueMessageKey
 */
const PERSISTENT_WORKSPACE_KEY_FUNCTIONS = [
    getModelKey,
    getInputKey,
    getModeKey,
    exports.getThinkingLevelKey,
    getAutoRetryKey,
    getRetryStateKey,
    getReviewExpandStateKey,
    getFileTreeExpandStateKey,
    getReviewSearchStateKey,
];
/**
 * Additional ephemeral keys to delete on workspace removal (not copied on fork)
 */
const EPHEMERAL_WORKSPACE_KEY_FUNCTIONS = [
    getCancelledCompactionKey,
    getCompactContinueMessageKey,
];
/**
 * Copy all workspace-specific localStorage keys from source to destination workspace
 * This includes: model, input, mode, thinking level, auto-retry, retry state, review expand state, file tree expand state
 */
function copyWorkspaceStorage(sourceWorkspaceId, destWorkspaceId) {
    for (const getKey of PERSISTENT_WORKSPACE_KEY_FUNCTIONS) {
        const sourceKey = getKey(sourceWorkspaceId);
        const destKey = getKey(destWorkspaceId);
        const value = localStorage.getItem(sourceKey);
        if (value !== null) {
            localStorage.setItem(destKey, value);
        }
    }
}
/**
 * Delete all workspace-specific localStorage keys for a workspace
 * Should be called when a workspace is deleted to prevent orphaned data
 */
function deleteWorkspaceStorage(workspaceId) {
    const allKeyFunctions = [
        ...PERSISTENT_WORKSPACE_KEY_FUNCTIONS,
        ...EPHEMERAL_WORKSPACE_KEY_FUNCTIONS,
    ];
    for (const getKey of allKeyFunctions) {
        const key = getKey(workspaceId);
        localStorage.removeItem(key);
    }
}
//# sourceMappingURL=storage.js.map