Skip to content

Commit fe3317d

Browse files
Rachelclaude
authored andcommitted
refactor: replace repetitive env var loading with declarative mapping
Replace ~40 lines of repetitive if/init/assign blocks in loadConfig() with a data-driven ENV_TO_CONFIG table and a 5-line loop. Also remove unused module-level constants (SHARES_FILE, EPISODIC_DIR, SEMANTIC_FILE) that were superseded by instance properties. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent c73ce89 commit fe3317d

File tree

3 files changed

+24
-58
lines changed

3 files changed

+24
-58
lines changed

src/life/memory.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import { genId } from '../utils/ids.js';
66
import { todayDateStr } from '../utils/date.js';
77

88
const LIFE_DIR = join(homedir(), '.kernelbot', 'life');
9-
const EPISODIC_DIR = join(LIFE_DIR, 'memories', 'episodic');
10-
const SEMANTIC_FILE = join(LIFE_DIR, 'memories', 'semantic', 'topics.json');
119

1210
export class MemoryManager {
1311
constructor(basePath = null) {

src/life/share-queue.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { genId } from '../utils/ids.js';
66
import { getStartOfDayMs } from '../utils/date.js';
77

88
const LIFE_DIR = join(homedir(), '.kernelbot', 'life');
9-
const SHARES_FILE = join(LIFE_DIR, 'shares.json');
109

1110
export class ShareQueue {
1211
constructor(basePath = null) {

src/utils/config.js

Lines changed: 24 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -518,61 +518,30 @@ export function loadConfig() {
518518
config.telegram.allowed_users.push(ownerId);
519519
}
520520
}
521-
if (process.env.GITHUB_TOKEN) {
522-
if (!config.github) config.github = {};
523-
config.github.token = process.env.GITHUB_TOKEN;
524-
}
525-
// ElevenLabs voice credentials
526-
if (process.env.ELEVENLABS_API_KEY) {
527-
if (!config.elevenlabs) config.elevenlabs = {};
528-
config.elevenlabs.api_key = process.env.ELEVENLABS_API_KEY;
529-
}
530-
if (process.env.ELEVENLABS_VOICE_ID) {
531-
if (!config.elevenlabs) config.elevenlabs = {};
532-
config.elevenlabs.voice_id = process.env.ELEVENLABS_VOICE_ID;
533-
}
534-
535-
if (process.env.JIRA_BASE_URL || process.env.JIRA_EMAIL || process.env.JIRA_API_TOKEN) {
536-
if (!config.jira) config.jira = {};
537-
if (process.env.JIRA_BASE_URL) config.jira.base_url = process.env.JIRA_BASE_URL;
538-
if (process.env.JIRA_EMAIL) config.jira.email = process.env.JIRA_EMAIL;
539-
if (process.env.JIRA_API_TOKEN) config.jira.api_token = process.env.JIRA_API_TOKEN;
540-
}
541-
542-
// Claude Code auth credentials from env
543-
if (process.env.CLAUDE_CODE_API_KEY) {
544-
config.claude_code.api_key = process.env.CLAUDE_CODE_API_KEY;
545-
}
546-
if (process.env.CLAUDE_CODE_OAUTH_TOKEN) {
547-
config.claude_code.oauth_token = process.env.CLAUDE_CODE_OAUTH_TOKEN;
548-
}
549-
550-
// LinkedIn token-based auth from env
551-
if (process.env.LINKEDIN_ACCESS_TOKEN) {
552-
if (!config.linkedin) config.linkedin = {};
553-
config.linkedin.access_token = process.env.LINKEDIN_ACCESS_TOKEN;
554-
}
555-
if (process.env.LINKEDIN_PERSON_URN) {
556-
if (!config.linkedin) config.linkedin = {};
557-
config.linkedin.person_urn = process.env.LINKEDIN_PERSON_URN;
558-
}
559-
560-
// X (Twitter) OAuth 1.0a credentials from env
561-
if (process.env.X_CONSUMER_KEY) {
562-
if (!config.x) config.x = {};
563-
config.x.consumer_key = process.env.X_CONSUMER_KEY;
564-
}
565-
if (process.env.X_CONSUMER_SECRET) {
566-
if (!config.x) config.x = {};
567-
config.x.consumer_secret = process.env.X_CONSUMER_SECRET;
568-
}
569-
if (process.env.X_ACCESS_TOKEN) {
570-
if (!config.x) config.x = {};
571-
config.x.access_token = process.env.X_ACCESS_TOKEN;
572-
}
573-
if (process.env.X_ACCESS_TOKEN_SECRET) {
574-
if (!config.x) config.x = {};
575-
config.x.access_token_secret = process.env.X_ACCESS_TOKEN_SECRET;
521+
// Declarative env → config mapping for integration credentials.
522+
// Each entry: [ENV_VAR_NAME, configSection, configKey]
523+
const ENV_TO_CONFIG = [
524+
['GITHUB_TOKEN', 'github', 'token'],
525+
['ELEVENLABS_API_KEY', 'elevenlabs', 'api_key'],
526+
['ELEVENLABS_VOICE_ID', 'elevenlabs', 'voice_id'],
527+
['JIRA_BASE_URL', 'jira', 'base_url'],
528+
['JIRA_EMAIL', 'jira', 'email'],
529+
['JIRA_API_TOKEN', 'jira', 'api_token'],
530+
['CLAUDE_CODE_API_KEY', 'claude_code', 'api_key'],
531+
['CLAUDE_CODE_OAUTH_TOKEN','claude_code', 'oauth_token'],
532+
['LINKEDIN_ACCESS_TOKEN', 'linkedin', 'access_token'],
533+
['LINKEDIN_PERSON_URN', 'linkedin', 'person_urn'],
534+
['X_CONSUMER_KEY', 'x', 'consumer_key'],
535+
['X_CONSUMER_SECRET', 'x', 'consumer_secret'],
536+
['X_ACCESS_TOKEN', 'x', 'access_token'],
537+
['X_ACCESS_TOKEN_SECRET', 'x', 'access_token_secret'],
538+
];
539+
540+
for (const [envKey, section, key] of ENV_TO_CONFIG) {
541+
if (process.env[envKey]) {
542+
if (!config[section]) config[section] = {};
543+
config[section][key] = process.env[envKey];
544+
}
576545
}
577546

578547
return config;

0 commit comments

Comments
 (0)