export const defaultOnboardingPreferences = {
    mode: "build",
    reasoning: "medium",
    thinking: "adaptive",
    subagents: false,
};
export const preferenceRows = [
    {
        key: "mode",
        label: "Agent mode",
        values: ["plan", "build"],
    },
    {
        key: "reasoning",
        label: "Reasoning effort",
        values: ["none", "low", "medium", "high", "xhigh", "adaptive"],
    },
    {
        key: "thinking",
        label: "Thinking budget",
        values: ["fixed", "adaptive"],
    },
    {
        key: "subagents",
        label: "Planner / Reviewer subagents",
        values: ["off", "on"],
    },
];
/** Human-friendly one-liner for the currently selected value of a row. */
export function describePreferenceValue(key, value) {
    if (key === "mode") {
        return value === "plan"
            ? "Read-only. The agent inspects and plans, never writes."
            : value === "build"
                ? "Recommended. Writes and shell run behind per-action approval prompts."
                : "Use /mode bypass after setup when you want trusted-workspace bypass.";
    }
    if (key === "reasoning") {
        return value === "none"
            ? "Fastest, cheapest. No extra reasoning budget."
            : value === "adaptive"
                ? "The agent scales reasoning to the task. Good general default."
                : `Fixed ${value} reasoning budget on every step.`;
    }
    if (key === "thinking") {
        return value === "adaptive"
            ? "Thinking budget flexes with task difficulty."
            : "Thinking budget stays fixed for predictable latency.";
    }
    return value === "on"
        ? "Advisory planner and reviewer run before the main loop. Slower, higher quality."
        : "Skip advisors for faster, leaner local runs.";
}
/** Current displayed value for a preference row given the working prefs. */
export function preferenceValueString(prefs, key) {
    if (key === "subagents") {
        return prefs.subagents ? "on" : "off";
    }
    return String(prefs[key]);
}
/** Cycle a row's value forward (+1) or backward (-1), wrapping around. */
export function cyclePreference(prefs, key, direction) {
    const row = preferenceRows.find((candidate) => candidate.key === key);
    if (!row) {
        return prefs;
    }
    const current = preferenceValueString(prefs, key);
    const currentIndex = Math.max(0, row.values.indexOf(current));
    const nextIndex = (currentIndex + direction + row.values.length) % row.values.length;
    const nextValue = row.values[nextIndex] ?? row.values[0] ?? current;
    if (key === "subagents") {
        return { ...prefs, subagents: nextValue === "on" };
    }
    if (key === "mode") {
        return { ...prefs, mode: nextValue };
    }
    if (key === "thinking") {
        return { ...prefs, thinking: nextValue === "adaptive" ? "adaptive" : "fixed" };
    }
    return { ...prefs, reasoning: nextValue };
}
/** Env payload for `savePatchPilotEnvValues` derived from the chosen prefs. */
export function preferencesEnvValues(prefs) {
    return {
        PATCHPILOT_DEFAULT_MODE: prefs.mode,
        PATCHPILOT_REASONING_EFFORT: prefs.reasoning,
        PATCHPILOT_THINKING_MODE: prefs.thinking,
        PATCHPILOT_SUBAGENTS: prefs.subagents ? "1" : "0",
    };
}
/** Read persisted preferences back into a typed shape, falling back safely. */
export function readOnboardingPreferences(env = process.env) {
    const mode = env.PATCHPILOT_DEFAULT_MODE?.trim().toLowerCase();
    const reasoning = env.PATCHPILOT_REASONING_EFFORT?.trim().toLowerCase();
    const thinking = env.PATCHPILOT_THINKING_MODE?.trim().toLowerCase();
    const subagents = env.PATCHPILOT_SUBAGENTS?.trim().toLowerCase();
    return {
        mode: mode === "plan" || mode === "build" || mode === "bypass" ? mode : defaultOnboardingPreferences.mode,
        reasoning: reasoning === "none" ||
            reasoning === "low" ||
            reasoning === "medium" ||
            reasoning === "high" ||
            reasoning === "xhigh" ||
            reasoning === "adaptive"
            ? reasoning
            : defaultOnboardingPreferences.reasoning,
        thinking: thinking === "fixed" ? "fixed" : thinking === "adaptive" ? "adaptive" : defaultOnboardingPreferences.thinking,
        subagents: subagents === undefined ? defaultOnboardingPreferences.subagents : ["1", "true", "yes", "on", "enabled"].includes(subagents),
    };
}
/** Mode string maps to runtime write/shell permissions for the agent loop. */
export function modePermissions(mode) {
    return {
        allowWrite: mode === "bypass",
        allowShell: mode === "bypass",
    };
}
//# sourceMappingURL=onboardingPreferences.js.map