Skip to content

armgit / chops

Public Imported from GitHub
0

Your AI agent skills, finally organized. A macOS app to browse, edit, and manage skills across Claude Code, Cursor, Codex, Windsurf, and Amp.

1.3 KB
Raw Blame
import Foundation

enum SkillParser {
    static func parse(fileURL: URL, toolSource: ToolSource) -> ParsedSkill? {
        guard let content = try? String(contentsOf: fileURL, encoding: .utf8) else {
            return nil
        }

        switch toolSource {
        case .claude, .claudeDesktop, .cursor:
            if fileURL.pathExtension == "mdc" {
                return MDCParser.parse(content)
            }
            return FrontmatterParser.parse(content)
        case .codex, .amp, .windsurf, .copilot, .aider, .hermes, .openclaw, .opencode, .pi, .agents, .augment, .antigravity, .custom:
            // Try frontmatter first, fall back to heading
            let parsed = FrontmatterParser.parse(content)
            if !parsed.name.isEmpty { return parsed }
            return parseHeadingFormat(content)
        }
    }

    private static func parseHeadingFormat(_ content: String) -> ParsedSkill {
        let lines = content.components(separatedBy: "\n")
        var name = ""

        for line in lines {
            if line.hasPrefix("# ") {
                name = String(line.dropFirst(2)).trimmingCharacters(in: .whitespaces)
                break
            }
        }

        return ParsedSkill(
            frontmatter: [:],
            content: content,
            name: name,
            description: ""
        )
    }
}