const DEFAULT_VERBOSITY = {
    write: 'standard',
    edit: 'with_diff',
    read: 'standard',
    grep: 'matches',
    glob: 'paths_only',
    exec: 'standard',
};
const VIBECODING_VERBOSITY = {
    write: 'count_only',
    edit: 'minimal',
    read: 'standard',
    grep: 'files_only',
    glob: 'paths_only',
    exec: 'minimal',
};
const BUILT_IN_MODES = [
    {
        name: 'default',
        description: 'Standard precision tool verbosity with confirmation prompts.',
        verbosityDefaults: DEFAULT_VERBOSITY,
        enforcement: 'advisory',
    },
    {
        name: 'vibecoding',
        description: 'Reduced verbosity for rapid iteration; still confirms destructive operations.',
        verbosityDefaults: VIBECODING_VERBOSITY,
        enforcement: 'advisory',
    },
    {
        name: 'justvibes',
        description: 'Minimal output, no confirmation prompts. Fast and autonomous.',
        verbosityDefaults: VIBECODING_VERBOSITY,
        enforcement: 'advisory',
    },
];
export const HITL_QUIET = {
    name: 'quiet',
    description: 'Minimal verbosity. Suppresses most notifications. Batches updates in 5s windows.',
    defaultDomainVerbosity: 'minimal',
    quietWhileTyping: true,
    batchWindowMs: 5_000,
};
export const HITL_BALANCED = {
    name: 'balanced',
    description: 'Normal verbosity. Standard notification flow. Batches updates in 2s windows.',
    defaultDomainVerbosity: 'normal',
    quietWhileTyping: true,
    batchWindowMs: 2_000,
};
export const HITL_OPERATOR = {
    name: 'operator',
    description: 'Verbose. All notifications shown immediately. No quiet-while-typing suppression.',
    defaultDomainVerbosity: 'verbose',
    quietWhileTyping: false,
    batchWindowMs: 500,
};
const HITL_PRESETS = [HITL_QUIET, HITL_BALANCED, HITL_OPERATOR];
// ---------------------------------------------------------------------------
// ModeManager
// ---------------------------------------------------------------------------
export class ModeManager {
    currentMode = 'default';
    modes = [...BUILT_IN_MODES];
    hitlMode = 'balanced';
    domainOverrides = new Map();
    // -------------------------------------------------------------------------
    // Precision tool verbosity mode API
    // -------------------------------------------------------------------------
    getMode() {
        return this.currentMode;
    }
    getModeDefinition() {
        return this.modes.find((m) => m.name === this.currentMode) ?? this.modes[0];
    }
    setMode(mode) {
        const found = this.modes.find((m) => m.name === mode);
        if (!found) {
            const available = this.modes.map((m) => `"${m.name}"`).join(', ');
            throw new Error(`Unknown mode: "${mode}". Available modes: ${available}`);
        }
        this.currentMode = mode;
    }
    listModes() {
        return [...this.modes];
    }
    registerMode(def) {
        const idx = this.modes.findIndex((m) => m.name === def.name);
        if (idx >= 0) {
            this.modes[idx] = def;
        }
        else {
            this.modes.push(def);
        }
    }
    getVerbosityDefaults() {
        return { ...this.getModeDefinition().verbosityDefaults };
    }
    // -------------------------------------------------------------------------
    // HITL UX mode API.
    // -------------------------------------------------------------------------
    getHITLMode() {
        return this.hitlMode;
    }
    getHITLPreset() {
        return HITL_PRESETS.find((p) => p.name === this.hitlMode) ?? HITL_BALANCED;
    }
    /**
     * Switch the active HITL mode.
     *
     * Switching modes clears all per-domain verbosity overrides that may have
     * been set via {@link setDomainVerbosity}. This ensures the new mode's
     * `defaultDomainVerbosity` applies uniformly until the caller re-establishes
     * any domain-specific overrides.
     */
    setHITLMode(mode) {
        const found = HITL_PRESETS.find((p) => p.name === mode);
        if (!found) {
            const available = HITL_PRESETS.map((p) => `"${p.name}"`).join(', ');
            throw new Error(`Unknown HITL mode: "${mode}". Available: ${available}`);
        }
        this.hitlMode = mode;
        this.domainOverrides.clear();
    }
    listHITLPresets() {
        return [...HITL_PRESETS];
    }
    setDomainVerbosity(domain, verbosity) {
        this.domainOverrides.set(domain, verbosity);
    }
    getDomainVerbosity(domain) {
        return this.domainOverrides.get(domain) ?? this.getHITLPreset().defaultDomainVerbosity;
    }
    getDomainOverrides() {
        return Object.fromEntries(this.domainOverrides);
    }
    applyToRouter(router) {
        const preset = this.getHITLPreset();
        router.setQuietWhileTyping(preset.quietWhileTyping);
        router.setBatchWindowMs?.(preset.batchWindowMs);
        router.setDefaultDomainVerbosity?.(preset.defaultDomainVerbosity);
        for (const [domain, verbosity] of this.domainOverrides) {
            router.setDomainVerbosity(domain, verbosity);
        }
    }
}
