( filePath: string, type: SkillType, toolId: string, _pattern: ScanPattern = "directory-with-skillmd", namingMode: NamingMode = "auto" )
| 162 | } |
| 163 | |
| 164 | function parseSkillFile( |
| 165 | filePath: string, |
| 166 | type: SkillType, |
| 167 | toolId: string, |
| 168 | _pattern: ScanPattern = "directory-with-skillmd", |
| 169 | namingMode: NamingMode = "auto" |
| 170 | ): SkillItem | null { |
| 171 | try { |
| 172 | const raw = readFileSync(filePath, "utf-8"); |
| 173 | const stat = statSync(filePath); |
| 174 | const { frontmatter, content } = parseFrontmatter(raw); |
| 175 | const name = extractName(frontmatter, content, filePath, namingMode, type); |
| 176 | const description = |
| 177 | typeof frontmatter.description === "string" |
| 178 | ? frontmatter.description |
| 179 | : ""; |
| 180 | |
| 181 | let realPath: string; |
| 182 | try { |
| 183 | realPath = realpathSync(filePath); |
| 184 | } catch { /* empty */ |
| 185 | realPath = filePath; |
| 186 | } |
| 187 | |
| 188 | return { |
| 189 | id: hashPath(realPath), |
| 190 | name, |
| 191 | description, |
| 192 | type, |
| 193 | tools: [toolId], |
| 194 | filePath, |
| 195 | realPath, |
| 196 | dirPath: join(filePath, ".."), |
| 197 | content: raw, |
| 198 | frontmatter, |
| 199 | lastModified: stat.mtimeMs, |
| 200 | fileSize: stat.size, |
| 201 | isFavorite: false, |
| 202 | collections: [], |
| 203 | }; |
| 204 | } catch { /* empty */ |
| 205 | return null; |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | function scanPath(sp: SkillPath, toolId: string, namingMode: NamingMode = "auto"): SkillItem[] { |
| 210 | switch (sp.pattern) { |
no test coverage detected