Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 28 additions & 4 deletions index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -1180,11 +1180,35 @@ if (cmd === 'import') {
fs.writeFileSync(path.join(agentDir, 'history.md'), historyContent);
}

// Write skills
for (const skillContent of manifest.skills) {
// Write skills to .copilot/skills/ (the canonical location)
const copilotSkillsImportDir = path.join(dest, '.copilot', 'skills');
const importedSkills = manifest.skills.map((skillContent, index) => {
const nameMatch = skillContent.match(/^name:\s*["']?(.+?)["']?\s*$/m);
const skillName = nameMatch ? nameMatch[1].trim().toLowerCase().replace(/\s+/g, '-') : `skill-${manifest.skills.indexOf(skillContent)}`;
const skillDir = path.join(aiTeamDir, 'skills', skillName);
const skillName = nameMatch
? nameMatch[1].trim().toLowerCase().replace(/\s+/g, '-')
: `skill-${index}`;
return { skillContent, skillName };
});
const hasForce = typeof force !== 'undefined' && force;

if (fs.existsSync(copilotSkillsImportDir)) {
if (hasForce) {
const archivedSkillsDir = path.join(dest, '.copilot', `skills.backup.${Date.now()}`);
fs.renameSync(copilotSkillsImportDir, archivedSkillsDir);
} else {
const collidingSkills = importedSkills
.map(({ skillName }) => skillName)
.filter((skillName) => fs.existsSync(path.join(copilotSkillsImportDir, skillName)));

if (collidingSkills.length > 0) {
fatal(`Import would overwrite existing Copilot skills: ${collidingSkills.join(', ')}. Re-run with --force to replace the existing .copilot/skills directory.`);
}
}
}

fs.mkdirSync(copilotSkillsImportDir, { recursive: true });
for (const { skillContent, skillName } of importedSkills) {
const skillDir = path.join(copilotSkillsImportDir, skillName);
fs.mkdirSync(skillDir, { recursive: true });
fs.writeFileSync(path.join(skillDir, 'SKILL.md'), skillContent);
}
Expand Down