const fs = require('fs')
const path = require('path')
const repoRoot = path.resolve(__dirname, '..')
const source = path.join(repoRoot, '.agents', 'skills')
const link = path.join(repoRoot, '.claude', 'skills')
function pathExists(p) {
try {
fs.lstatSync(p)
return true
} catch {
return false
}
}
function createLink() {
if (!fs.existsSync(source)) {
console.warn(`[link-skills] source missing, skipping: ${source}`)
return
}
fs.mkdirSync(path.dirname(link), { recursive: true })
if (pathExists(link)) {
const stat = fs.lstatSync(link)
if (stat.isSymbolicLink()) {
fs.rmSync(link)
} else if (stat.isDirectory()) {
if (fs.readdirSync(link).length !== 0) {
console.warn(`[link-skills] ${link} is a non-empty directory, leaving it untouched`)
return
}
fs.rmSync(link, { recursive: true })
} else {
fs.rmSync(link)
}
}
if (process.platform === 'win32') {
fs.symlinkSync(source, link, 'junction')
} else {
fs.symlinkSync(path.relative(path.dirname(link), source), link)
}
console.log('[link-skills] linked .claude/skills -> .agents/skills')
}
try {
createLink()
} catch (err) {
console.warn(`[link-skills] could not create link: ${err.message}`)
}