fix: promote CLAUDE.md to main template when group becomes main
When a non-main group is re-registered with --is-main, the existing CLAUDE.md (copied from global template) lacked admin context. Now register.ts detects this promotion case and replaces it with the main template. Files that already contain "## Admin Context" are preserved. Adds tests for: - promoting non-main to main upgrades the template - cross-channel promotion (e.g. Telegram non-main → main) - promotion with custom assistant name - re-registration preserves user-modified main CLAUDE.md - re-registration preserves user-modified non-main CLAUDE.md Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -116,7 +116,7 @@ export async function run(args: string[]): Promise<void> {
|
||||
recursive: true,
|
||||
});
|
||||
|
||||
// Create CLAUDE.md in the new group folder from template if it doesn't exist.
|
||||
// Create or upgrade CLAUDE.md in the group folder from the appropriate template.
|
||||
// The agent runs with CWD=/workspace/group and loads CLAUDE.md from there.
|
||||
const groupClaudeMdPath = path.join(
|
||||
projectRoot,
|
||||
@@ -124,15 +124,30 @@ export async function run(args: string[]): Promise<void> {
|
||||
parsed.folder,
|
||||
'CLAUDE.md',
|
||||
);
|
||||
if (!fs.existsSync(groupClaudeMdPath)) {
|
||||
const templatePath = parsed.isMain
|
||||
? path.join(projectRoot, 'groups', 'main', 'CLAUDE.md')
|
||||
: path.join(projectRoot, 'groups', 'global', '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(templatePath)) {
|
||||
fs.copyFileSync(templatePath, groupClaudeMdPath);
|
||||
logger.info(
|
||||
{ file: groupClaudeMdPath, template: templatePath },
|
||||
'Created CLAUDE.md from template',
|
||||
{
|
||||
file: groupClaudeMdPath,
|
||||
template: templatePath,
|
||||
promoted: needsPromotion,
|
||||
},
|
||||
needsPromotion
|
||||
? 'Promoted CLAUDE.md to main template'
|
||||
: 'Created CLAUDE.md from template',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user