/**
 * npm Registry Discovery Provider
 *
 * Searches npm for packages with agent-skill keywords
 * and extracts their GitHub repository URLs.
 */
import { NPM_REGISTRY_URL } from '../../../utils/npm-constants.js';
const NPM_SEARCH_URL = `${NPM_REGISTRY_URL}/-/v1/search`;
const SEARCH_KEYWORDS = [
    'claude-code-skill',
    'agent-skill',
    'claude-skill',
    'specweave-plugin',
];
const GITHUB_REPO_REGEX = /^https?:\/\/github\.com\/([a-zA-Z0-9._-]+\/[a-zA-Z0-9._-]+)/;
export class NpmProvider {
    constructor() {
        this.name = 'npm';
    }
    async *discover() {
        const seen = new Set();
        for (const keyword of SEARCH_KEYWORDS) {
            try {
                const url = `${NPM_SEARCH_URL}?text=keywords:${encodeURIComponent(keyword)}&size=250`;
                const response = await fetch(url);
                if (!response.ok)
                    continue;
                const data = await response.json();
                for (const obj of data.objects || []) {
                    const repoUrl = obj.package.links?.repository;
                    if (!repoUrl)
                        continue;
                    const match = repoUrl.match(GITHUB_REPO_REGEX);
                    if (!match)
                        continue;
                    const fullName = match[1].replace(/\.git$/, '');
                    if (seen.has(fullName))
                        continue;
                    seen.add(fullName);
                    const [owner] = fullName.split('/');
                    yield {
                        fullName,
                        htmlUrl: `https://github.com/${fullName}`,
                        description: obj.package.description || null,
                        owner,
                        stars: 0,
                        lastUpdated: new Date().toISOString(),
                        skillPath: 'SKILL.md',
                    };
                }
            }
            catch {
                // Keyword search failed — continue with next
            }
        }
    }
}
//# sourceMappingURL=npm-provider.js.map