feat(backend): persistent settings store + settingsFile config
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user