import { useEffect, useState } from "react"; import type { ClaudeCodeSettings } from "../../lib/types"; import Toggle from "../ui/Toggle"; import { SwitchRow, selectClass } from "../ui/Field"; interface Props { settings: ClaudeCodeSettings | null; disabled: boolean; disabledReason?: string; onSave: (settings: ClaudeCodeSettings | null) => Promise; } export const CLAUDE_CODE_DEFAULTS: ClaudeCodeSettings = { tui_mode: null, effort: null, auto_scroll_disabled: false, focus_mode: false, show_thinking_summaries: false, enable_session_recap: false, env_scrub: false, prompt_caching_1h: false, }; function isAllDefaults(s: ClaudeCodeSettings): boolean { return ( s.tui_mode === null && s.effort === null && s.auto_scroll_disabled === false && s.focus_mode === false && s.show_thinking_summaries === false && s.enable_session_recap === false && s.env_scrub === false && s.prompt_caching_1h === false ); } const BOOLEAN_FIELDS: { key: keyof Omit; label: string; hint: string; }[] = [ { key: "focus_mode", label: "Focus mode", hint: "Collapses tool output to one-line summaries." }, { key: "show_thinking_summaries", label: "Thinking summaries", hint: "Shows Claude's thinking process as summaries.", }, { key: "enable_session_recap", label: "Session recap", hint: "Provides context when returning to a session.", }, { key: "auto_scroll_disabled", label: "Auto-scroll disabled", hint: "Disables auto-scroll when in fullscreen TUI mode.", }, { key: "env_scrub", label: "Env scrub", hint: "Strips credentials from subprocess environments.", }, { key: "prompt_caching_1h", label: "Prompt caching (1h)", hint: "Uses a 1-hour prompt cache TTL instead of 5 minutes.", }, ]; export default function ClaudeCodeSettingsEditor({ settings, disabled, disabledReason, onSave, }: Props) { const [local, setLocal] = useState( settings ?? { ...CLAUDE_CODE_DEFAULTS }, ); useEffect(() => { setLocal(settings ?? { ...CLAUDE_CODE_DEFAULTS }); }, [settings]); const apply = (patch: Partial) => { const next = { ...local, ...patch }; setLocal(next); onSave(isAllDefaults(next) ? null : next); }; return (
{disabled && disabledReason && (

{disabledReason}

)} apply({ tui_mode: e.target.value || null })} disabled={disabled} className={selectClass} > } /> apply({ effort: e.target.value || null })} disabled={disabled} className={selectClass} > } /> {BOOLEAN_FIELDS.map(({ key, label, hint }) => ( apply({ [key]: v } as Partial)} /> } /> ))}
); }