|
1 | 1 | import { existsSync } from "node:fs"; |
2 | 2 | import { chmod, mkdir, readFile, writeFile } from "node:fs/promises"; |
3 | | -import { join, resolve } from "node:path"; |
| 3 | +import { join, relative, resolve } from "node:path"; |
4 | 4 | import chalk from "chalk"; |
5 | 5 | import { generateDefaultConfig } from "../../config/writer.js"; |
6 | 6 | import { writeAgentsGitignore, ensureRootGitignoreEntries } from "../../gitignore/writer.js"; |
7 | 7 | import { ensureSkillsSymlink } from "../../symlinks/manager.js"; |
8 | 8 | import { loadConfig } from "../../config/loader.js"; |
9 | | -import { getAgent, allAgentIds, allAgents } from "../../targets/registry.js"; |
| 9 | +import { allAgentIds, allAgents } from "../../targets/registry.js"; |
| 10 | +import { skillSymlinkTargets } from "../../targets/skill-symlinks.js"; |
10 | 11 | import { parseArgs } from "node:util"; |
11 | 12 | import * as clack from "@clack/prompts"; |
12 | 13 | import { resolveScope, isInsideGitRepo, findGitDir, type ScopeRoot } from "../../scope.js"; |
@@ -71,36 +72,17 @@ export async function runInit(opts: InitOptions): Promise<void> { |
71 | 72 | // Symlinks — create per-agent symlinks so each agent discovers skills |
72 | 73 | const symlinkResults: { target: string; created: boolean; migrated: string[] }[] = []; |
73 | 74 |
|
74 | | - if (scope.scope === "user") { |
75 | | - const seen = new Set<string>(); |
76 | | - for (const agentId of config.agents) { |
77 | | - const agent = getAgent(agentId); |
78 | | - if (!agent?.userSkillsParentDirs) {continue;} |
79 | | - for (const dir of agent.userSkillsParentDirs) { |
80 | | - if (seen.has(dir)) {continue;} |
81 | | - seen.add(dir); |
82 | | - const result = await ensureSkillsSymlink(agentsDir, dir); |
83 | | - symlinkResults.push({ target: dir, ...result }); |
84 | | - } |
85 | | - } |
86 | | - } else { |
87 | | - const targets = config.symlinks?.targets ?? []; |
88 | | - for (const target of targets) { |
89 | | - const targetDir = join(scope.root, target); |
90 | | - const result = await ensureSkillsSymlink(agentsDir, targetDir); |
91 | | - symlinkResults.push({ target, ...result }); |
92 | | - } |
93 | | - |
94 | | - const seenParentDirs = new Set(targets); |
95 | | - for (const agentId of config.agents) { |
96 | | - const agent = getAgent(agentId); |
97 | | - if (!agent?.skillsParentDir) {continue;} |
98 | | - if (seenParentDirs.has(agent.skillsParentDir)) {continue;} |
99 | | - seenParentDirs.add(agent.skillsParentDir); |
100 | | - const targetDir = join(scope.root, agent.skillsParentDir); |
101 | | - const result = await ensureSkillsSymlink(agentsDir, targetDir); |
102 | | - symlinkResults.push({ target: agent.skillsParentDir, ...result }); |
103 | | - } |
| 75 | + const symlinkTargets = skillSymlinkTargets( |
| 76 | + scope, |
| 77 | + config.agents, |
| 78 | + config.symlinks?.targets, |
| 79 | + ); |
| 80 | + for (const target of symlinkTargets) { |
| 81 | + const result = await ensureSkillsSymlink(agentsDir, target); |
| 82 | + const displayTarget = scope.scope === "project" |
| 83 | + ? relative(scope.root, target) |
| 84 | + : target; |
| 85 | + symlinkResults.push({ target: displayTarget, ...result }); |
104 | 86 | } |
105 | 87 |
|
106 | 88 | // Auto-install declared skills (best-effort — may fail offline) |
|
0 commit comments