MCPcopy
hub / github.com/Doorman11991/smallcode / loadConfig

Function loadConfig

bin/config.js:8–85  ·  view source on GitHub ↗
(flags = {})

Source from the content-addressed store, hash-verified

6const os = require('os');
7
8function loadConfig(flags = {}) {
9 const env = process.env;
10
11 const config = {
12 model: {
13 provider: env.SMALLCODE_PROVIDER || 'openai',
14 name: env.SMALLCODE_MODEL || '',
15 baseUrl: env.SMALLCODE_BASE_URL || (env.OLLAMA_HOST ? (env.OLLAMA_HOST + '/v1') : 'http://localhost:1234/v1'),
16 timeout: parseInt(env.SMALLCODE_MODEL_TIMEOUT) || 300, // seconds; 5 min default for slow hardware
17 },
18 context: {
19 max_budget_pct: parseInt(env.SMALLCODE_CONTEXT_BUDGET) || 70,
20 detected_window: parseInt(env.SMALLCODE_CONTEXT_WINDOW) || 128000,
21 working_memory_tokens: 500,
22 summary_threshold: 200,
23 },
24 tools: {
25 bash_timeout: parseInt(env.SMALLCODE_BASH_TIMEOUT) || 30,
26 },
27 tui: {
28 show_token_usage: true,
29 auto_approve: env.SMALLCODE_AUTO_APPROVE === 'true',
30 theme: env.SMALLCODE_THEME || 'dark',
31 },
32 escalation: {
33 enabled: true,
34 max_per_session: parseInt(env.SMALLCODE_ESCALATION_MAX) || 5,
35 confirm: env.SMALLCODE_ESCALATION_CONFIRM !== 'false',
36 provider: null,
37 api_key: null,
38 model: env.SMALLCODE_ESCALATION_MODEL || null,
39 },
40 git: {
41 auto_commit: env.SMALLCODE_AUTO_COMMIT === 'true',
42 },
43 };
44
45 // smallcode.toml / config.toml for backwards compatibility and tier routing.
46 const tomlPaths = [
47 path.join(process.cwd(), 'smallcode.toml'),
48 path.join(process.cwd(), '.smallcode', 'config.toml'),
49 path.join(os.homedir(), '.config', 'smallcode', 'config.toml'),
50 ];
51 for (const tomlPath of tomlPaths) {
52 if (fs.existsSync(tomlPath)) {
53 try {
54 const toml = parseTomlConfig(fs.readFileSync(tomlPath, 'utf-8'));
55 // Primary [model] from TOML only when env did not set SMALLCODE_MODEL.
56 if (!config.model.name) applyTomlPrimaryConfig(config, toml);
57 // Tier sections are always merged — env tier vars override below.
58 applyTomlModelTiers(config, toml);
59 break;
60 } catch {}
61 }
62 }
63
64 applyEnvModelTier(config, 'fast', 'SMALLCODE_MODEL_FAST', 'SMALLCODE_BASE_URL_FAST');
65 applyEnvModelTier(config, 'default', 'SMALLCODE_MODEL_DEFAULT', 'SMALLCODE_BASE_URL_DEFAULT');

Callers 1

Calls 6

parseTomlConfigFunction · 0.85
applyTomlPrimaryConfigFunction · 0.85
applyTomlModelTiersFunction · 0.85
applyEnvModelTierFunction · 0.85
normalizeBaseUrlFunction · 0.85
normalizeModelTiersFunction · 0.85

Tested by

no test coverage detected