feat(backend): persistent settings store + settingsFile config

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-28 16:01:22 +02:00
co-authored by Claude Opus 4.8
parent 0cd14b5b55
commit 6b2883a467
4 changed files with 79 additions and 0 deletions
+29
View File
@@ -0,0 +1,29 @@
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
import { dirname } from "node:path";
import type { AppConfig } from "../config.js";
export interface Settings {
workspace?: string;
provider?: string;
model?: string;
thinking?: string;
}
/** Read settings from cfg.settingsFile. Returns {} if missing or invalid. */
export function loadSettings(cfg: AppConfig): Settings {
try {
const raw = readFileSync(cfg.settingsFile, "utf8");
const parsed = JSON.parse(raw);
if (parsed && typeof parsed === "object") return parsed as Settings;
return {};
} catch {
return {};
}
}
/** Persist settings (pretty JSON). Creates the parent directory if needed. */
export function saveSettings(cfg: AppConfig, s: Settings): Settings {
mkdirSync(dirname(cfg.settingsFile), { recursive: true });
writeFileSync(cfg.settingsFile, JSON.stringify(s, null, 2) + "\n", "utf8");
return s;
}