Initial commit: Discord-Claude Gateway with event-driven agent runtime
This commit is contained in:
@@ -2,55 +2,37 @@ import { readFile, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
|
||||
export interface MarkdownConfigs {
|
||||
soul: string | null;
|
||||
identity: string | null;
|
||||
/** 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;
|
||||
user: string | null;
|
||||
/** memory.md — long-term memory (agent-writable) */
|
||||
memory: string | null;
|
||||
tools: string | null;
|
||||
}
|
||||
|
||||
const CONFIG_FILES = ["soul.md", "identity.md", "agents.md", "user.md", "memory.md", "tools.md"] as const;
|
||||
|
||||
type ConfigKey = "soul" | "identity" | "agents" | "user" | "memory" | "tools";
|
||||
|
||||
const FILE_TO_KEY: Record<string, ConfigKey> = {
|
||||
"soul.md": "soul",
|
||||
"identity.md": "identity",
|
||||
"agents.md": "agents",
|
||||
"user.md": "user",
|
||||
"memory.md": "memory",
|
||||
"tools.md": "tools",
|
||||
};
|
||||
|
||||
export class MarkdownConfigLoader {
|
||||
async loadAll(configDir: string): Promise<MarkdownConfigs> {
|
||||
const configs: MarkdownConfigs = {
|
||||
soul: null,
|
||||
identity: null,
|
||||
persona: null,
|
||||
agents: null,
|
||||
user: null,
|
||||
memory: null,
|
||||
tools: null,
|
||||
};
|
||||
|
||||
for (const filename of CONFIG_FILES) {
|
||||
const key = FILE_TO_KEY[filename];
|
||||
const filePath = join(configDir, filename);
|
||||
// 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);
|
||||
}
|
||||
|
||||
try {
|
||||
const content = await readFile(filePath, "utf-8");
|
||||
configs[key] = content;
|
||||
} catch {
|
||||
if (filename === "memory.md") {
|
||||
const defaultContent = "# Memory\n";
|
||||
await writeFile(filePath, defaultContent, "utf-8");
|
||||
configs[key] = defaultContent;
|
||||
} else {
|
||||
console.warn(`Warning: ${filename} not found in ${configDir}`);
|
||||
configs[key] = null;
|
||||
}
|
||||
}
|
||||
// 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;
|
||||
|
||||
Reference in New Issue
Block a user