fix: revert promotion logic — never overwrite existing CLAUDE.md

The promotion logic (overwriting CLAUDE.md when a group becomes main)
is unsafe. Real-world setups use is_main for groups that intentionally
lack admin context — e.g. a family chat (whatsapp_casa) with 144 lines
of custom persona, PARA workspace, task management, and family context.
Overwriting based on missing "## Admin Context" would destroy user work.

register.ts now follows a simple rule: create template for new folders,
never touch existing files. Tests updated to verify preservation across
re-registration and main promotion scenarios.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
glifocat
2026-03-24 13:09:26 +01:00
parent 3207c35e50
commit 57085cc02e
2 changed files with 50 additions and 80 deletions

View File

@@ -116,38 +116,26 @@ export async function run(args: string[]): Promise<void> {
recursive: true,
});
// Create or upgrade CLAUDE.md in the group folder from the appropriate template.
// Create CLAUDE.md in the new group folder from template if it doesn't exist.
// The agent runs with CWD=/workspace/group and loads CLAUDE.md from there.
// Never overwrite an existing CLAUDE.md — users customize these extensively
// (persona, workspace structure, communication rules, family context, etc.)
// and a stock template replacement would destroy that work.
const groupClaudeMdPath = path.join(
projectRoot,
'groups',
parsed.folder,
'CLAUDE.md',
);
const mainTemplatePath = path.join(projectRoot, 'groups', 'main', 'CLAUDE.md');
const globalTemplatePath = path.join(projectRoot, 'groups', 'global', 'CLAUDE.md');
const templatePath = parsed.isMain ? mainTemplatePath : globalTemplatePath;
const fileExists = fs.existsSync(groupClaudeMdPath);
// Promotion case: group was registered as non-main (got global template)
// and is now being re-registered as main. Replace with main template.
const needsPromotion =
parsed.isMain &&
fileExists &&
!fs.readFileSync(groupClaudeMdPath, 'utf-8').includes('## Admin Context');
if (!fileExists || needsPromotion) {
if (!fs.existsSync(groupClaudeMdPath)) {
const templatePath = parsed.isMain
? path.join(projectRoot, 'groups', 'main', 'CLAUDE.md')
: path.join(projectRoot, 'groups', 'global', 'CLAUDE.md');
if (fs.existsSync(templatePath)) {
fs.copyFileSync(templatePath, groupClaudeMdPath);
logger.info(
{
file: groupClaudeMdPath,
template: templatePath,
promoted: needsPromotion,
},
needsPromotion
? 'Promoted CLAUDE.md to main template'
: 'Created CLAUDE.md from template',
{ file: groupClaudeMdPath, template: templatePath },
'Created CLAUDE.md from template',
);
}
}