MCPcopy Create free account
hub / github.com/anus-dev/ANUS / loadSettings

Function loadSettings

packages/cli/src/config/settings.ts:315–437  ·  view source on GitHub ↗
(workspaceDir: string)

Source from the content-addressed store, hash-verified

313 * Project settings override user settings.
314 */
315export function loadSettings(workspaceDir: string): LoadedSettings {
316 let systemSettings: Settings = {};
317 let userSettings: Settings = {};
318 let workspaceSettings: Settings = {};
319 const settingsErrors: SettingsError[] = [];
320 const systemSettingsPath = getSystemSettingsPath();
321
322 // Resolve paths to their canonical representation to handle symlinks
323 const resolvedWorkspaceDir = path.resolve(workspaceDir);
324 const resolvedHomeDir = path.resolve(homedir());
325
326 let realWorkspaceDir = resolvedWorkspaceDir;
327 try {
328 // fs.realpathSync gets the "true" path, resolving any symlinks
329 realWorkspaceDir = fs.realpathSync(resolvedWorkspaceDir);
330 } catch (_e) {
331 // This is okay. The path might not exist yet, and that's a valid state.
332 }
333
334 // We expect homedir to always exist and be resolvable.
335 const realHomeDir = fs.realpathSync(resolvedHomeDir);
336
337 const workspaceSettingsPath = getWorkspaceSettingsPath(workspaceDir);
338
339 // Load system settings
340 try {
341 if (fs.existsSync(systemSettingsPath)) {
342 const systemContent = fs.readFileSync(systemSettingsPath, 'utf-8');
343 const parsedSystemSettings = JSON.parse(
344 stripJsonComments(systemContent),
345 ) as Settings;
346 systemSettings = resolveEnvVarsInObject(parsedSystemSettings);
347 }
348 } catch (error: unknown) {
349 settingsErrors.push({
350 message: getErrorMessage(error),
351 path: systemSettingsPath,
352 });
353 }
354
355 // Load user settings
356 try {
357 if (fs.existsSync(USER_SETTINGS_PATH)) {
358 const userContent = fs.readFileSync(USER_SETTINGS_PATH, 'utf-8');
359 const parsedUserSettings = JSON.parse(
360 stripJsonComments(userContent),
361 ) as Settings;
362 userSettings = resolveEnvVarsInObject(parsedUserSettings);
363 // Support legacy theme names
364 if (userSettings.theme && userSettings.theme === 'VS') {
365 userSettings.theme = DefaultLight.name;
366 } else if (userSettings.theme && userSettings.theme === 'VS2015') {
367 userSettings.theme = DefaultDark.name;
368 }
369 }
370 } catch (error: unknown) {
371 settingsErrors.push({
372 message: getErrorMessage(error),

Callers 5

mainFunction · 0.85
getMcpServersFromConfigFunction · 0.85
removeMcpServerFunction · 0.85
addMcpServerFunction · 0.85
settings.test.tsFile · 0.85

Calls 6

getSystemSettingsPathFunction · 0.85
getWorkspaceSettingsPathFunction · 0.85
stripJsonCommentsFunction · 0.85
resolveEnvVarsInObjectFunction · 0.85
getErrorMessageFunction · 0.85
loadEnvironmentFunction · 0.85

Tested by

no test coverage detected