import { readFile, writeFile } from "node:fs/promises"; import { join } from "node:path"; export interface MarkdownConfigs { /** CLAUDE.md — persona: identity, soul, user context, tools (all in one) */ persona: string | null; /** agents.md — operating rules, cron jobs, hooks (parsed by gateway) */ agents: string | null; /** memory.md — long-term memory (agent-writable) */ memory: string | null; } export class MarkdownConfigLoader { async loadAll(configDir: string): Promise { const configs: MarkdownConfigs = { persona: null, agents: null, memory: null, }; // CLAUDE.md — main persona file configs.persona = await this.loadFile(configDir, "CLAUDE.md"); if (!configs.persona) { console.warn("Warning: CLAUDE.md not found in " + configDir); } // agents.md — parsed by gateway for cron/hooks, also included in prompt configs.agents = await this.loadFile(configDir, "agents.md"); // memory.md — agent-writable long-term memory configs.memory = await this.loadFile(configDir, "memory.md"); if (!configs.memory) { const defaultContent = "# Memory\n"; await writeFile(join(configDir, "memory.md"), defaultContent, "utf-8"); configs.memory = defaultContent; } return configs; } async loadFile(configDir: string, filename: string): Promise { try { return await readFile(join(configDir, filename), "utf-8"); } catch { return null; } } }