Merge pull request #1429 from ingyukoh/fix/ipc-register-group-claude-md

fix: create CLAUDE.md from template when registering groups via IPC
This commit is contained in:
gavrielc
2026-03-25 17:36:10 +02:00
committed by GitHub

View File

@@ -5,6 +5,7 @@ import { OneCLI } from '@onecli-sh/sdk';
import { import {
ASSISTANT_NAME, ASSISTANT_NAME,
GROUPS_DIR,
IDLE_TIMEOUT, IDLE_TIMEOUT,
ONECLI_URL, ONECLI_URL,
POLL_INTERVAL, POLL_INTERVAL,
@@ -133,6 +134,22 @@ function registerGroup(jid: string, group: RegisteredGroup): void {
// Create group folder // Create group folder
fs.mkdirSync(path.join(groupDir, 'logs'), { recursive: true }); fs.mkdirSync(path.join(groupDir, 'logs'), { recursive: true });
// Copy CLAUDE.md template into the new group folder so agents have
// identity and instructions from the first run. (Fixes #1391)
const groupMdFile = path.join(groupDir, 'CLAUDE.md');
if (!fs.existsSync(groupMdFile)) {
const templateFile = path.join(GROUPS_DIR, 'global', 'CLAUDE.md');
if (fs.existsSync(templateFile)) {
let content = fs.readFileSync(templateFile, 'utf-8');
if (ASSISTANT_NAME !== 'Andy') {
content = content.replace(/^# Andy$/m, `# ${ASSISTANT_NAME}`);
content = content.replace(/You are Andy/g, `You are ${ASSISTANT_NAME}`);
}
fs.writeFileSync(groupMdFile, content);
logger.info({ folder: group.folder }, 'Created CLAUDE.md from template');
}
}
// Ensure a corresponding OneCLI agent exists (best-effort, non-blocking) // Ensure a corresponding OneCLI agent exists (best-effort, non-blocking)
ensureOneCLIAgent(jid, group); ensureOneCLIAgent(jid, group);