|
1 | 1 | import { tool } from "@opencode-ai/plugin" |
2 | | -import { existsSync, readdirSync, lstatSync, readlinkSync, readFileSync } from "fs" |
| 2 | +import { existsSync, readdirSync, readFileSync } from "fs" |
3 | 3 | import { homedir } from "os" |
4 | | -import { join, resolve, basename } from "path" |
| 4 | +import { join, basename } from "path" |
5 | 5 | import { z } from "zod/v4" |
6 | 6 | import { parseFrontmatter, resolveCommandsInText } from "../../shared" |
| 7 | +import { resolveSymlink } from "../../shared/file-utils" |
7 | 8 | import { SkillFrontmatterSchema } from "./types" |
8 | 9 | import type { SkillScope, SkillMetadata, SkillInfo, LoadedSkill, SkillFrontmatter } from "./types" |
9 | 10 |
|
@@ -37,15 +38,7 @@ function discoverSkillsFromDir( |
37 | 38 | const skillPath = join(skillsDir, entry.name) |
38 | 39 |
|
39 | 40 | if (entry.isDirectory() || entry.isSymbolicLink()) { |
40 | | - let resolvedPath = skillPath |
41 | | - try { |
42 | | - const stats = lstatSync(skillPath, { throwIfNoEntry: false }) |
43 | | - if (stats?.isSymbolicLink()) { |
44 | | - resolvedPath = resolve(skillPath, "..", readlinkSync(skillPath)) |
45 | | - } |
46 | | - } catch { |
47 | | - continue |
48 | | - } |
| 41 | + const resolvedPath = resolveSymlink(skillPath) |
49 | 42 |
|
50 | 43 | const skillMdPath = join(resolvedPath, "SKILL.md") |
51 | 44 | if (!existsSync(skillMdPath)) continue |
@@ -83,18 +76,6 @@ const skillListForDescription = availableSkills |
83 | 76 | .map((s) => `- ${s.name}: ${s.description} (${s.scope})`) |
84 | 77 | .join("\n") |
85 | 78 |
|
86 | | -function resolveSymlink(skillPath: string): string { |
87 | | - try { |
88 | | - const stats = lstatSync(skillPath, { throwIfNoEntry: false }) |
89 | | - if (stats?.isSymbolicLink()) { |
90 | | - return resolve(skillPath, "..", readlinkSync(skillPath)) |
91 | | - } |
92 | | - return skillPath |
93 | | - } catch { |
94 | | - return skillPath |
95 | | - } |
96 | | -} |
97 | | - |
98 | 79 | async function parseSkillMd(skillPath: string): Promise<SkillInfo | null> { |
99 | 80 | const resolvedPath = resolveSymlink(skillPath) |
100 | 81 | const skillMdPath = join(resolvedPath, "SKILL.md") |
|
0 commit comments