MCPcopy
hub / github.com/slopus/happy / readSettings

Function readSettings

packages/happy-cli/src/persistence.ts:82–122  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

80}
81
82export async function readSettings(): Promise<Settings> {
83 if (!existsSync(configuration.settingsFile)) {
84 return { ...defaultSettings }
85 }
86
87 try {
88 // Read raw settings
89 const content = await readFile(configuration.settingsFile, 'utf8')
90 const raw = JSON.parse(content)
91
92 // Check schema version (default to 1 if missing)
93 const schemaVersion = raw.schemaVersion ?? 1;
94
95 // Warn if schema version is newer than supported
96 if (schemaVersion > SUPPORTED_SCHEMA_VERSION) {
97 logger.warn(
98 `⚠️ Settings schema v${schemaVersion} > supported v${SUPPORTED_SCHEMA_VERSION}. ` +
99 'Update happy-cli for full functionality.'
100 );
101 }
102
103 // Migrate if needed
104 const migrated = migrateSettings(raw, schemaVersion);
105
106 if (migrated.sandboxConfig !== undefined) {
107 try {
108 migrated.sandboxConfig = SandboxConfigSchema.parse(migrated.sandboxConfig);
109 } catch (error: any) {
110 logger.warn(`⚠️ Invalid sandbox config - skipping. Error: ${error.message}`);
111 migrated.sandboxConfig = undefined;
112 }
113 }
114
115 // Merge with defaults to ensure all required fields exist
116 return { ...defaultSettings, ...migrated };
117 } catch (error: any) {
118 logger.warn(`Failed to read settings: ${error.message}`);
119 // Return defaults on any error
120 return { ...defaultSettings }
121 }
122}
123
124export async function writeSettings(settings: Settings): Promise<void> {
125 if (!existsSync(configuration.happyHomeDir)) {

Callers 11

index.tsFile · 0.90
runGeminiFunction · 0.90
handleSandboxStatusFunction · 0.90
handleAuthLoginFunction · 0.90
handleAuthStatusFunction · 0.90
runDoctorCommandFunction · 0.90
runOpenClawFunction · 0.90
runCodexFunction · 0.90
runAcpFunction · 0.90
runClaudeFunction · 0.90
updateSettingsFunction · 0.85

Calls 3

migrateSettingsFunction · 0.85
parseMethod · 0.80
warnMethod · 0.80

Tested by

no test coverage detected