import { existsSync, readFileSync } from "node:fs"; import { homedir } from "node:os"; import { join } from "node:path"; export const CONFIG_DIR = join(homedir(), ".pi", "english-tutor"); const SETTINGS_PATH = join(CONFIG_DIR, "settings.json"); export interface EnglishTutorSettings { enabled: boolean; correctionProvider: string; correctionModel: string; logPath: string; /** Messages with fewer words than this are skipped without a correction call. */ skipShortMessages: number; } export const DEFAULT_SETTINGS: EnglishTutorSettings = { enabled: true, correctionProvider: "openrouter", correctionModel: "anthropic/claude-haiku-4.5", logPath: join(CONFIG_DIR, "log.jsonl"), skipShortMessages: 4, }; export function loadSettings(): EnglishTutorSettings { if (!existsSync(SETTINGS_PATH)) return DEFAULT_SETTINGS; try { const raw = JSON.parse(readFileSync(SETTINGS_PATH, "utf8")); return { ...DEFAULT_SETTINGS, ...raw }; } catch { return DEFAULT_SETTINGS; } }