diff --git a/packages/cli/src/commands/check.ts b/packages/cli/src/commands/check.ts index 85890d6a..eb5df90a 100644 --- a/packages/cli/src/commands/check.ts +++ b/packages/cli/src/commands/check.ts @@ -1,8 +1,8 @@ import { existsSync } from 'node:fs'; import { join } from 'node:path'; import { Command, Option } from 'clipanion'; -import { findAllSkills, findSkill, detectProvider, isLocalPath } from '@skillkit/core'; -import { getSearchDirs, loadSkillMetadata } from '../helpers.js'; +import { findAllSkills, findSkill, detectProvider, isLocalPath, evaluateSkillDirectory } from '@skillkit/core'; +import { getSearchDirs, loadSkillMetadata, formatCount } from '../helpers.js'; import { colors, symbols, @@ -11,6 +11,8 @@ import { success, warn, header, + formatQualityBadge, + getQualityGradeFromScore, } from '../onboarding/index.js'; interface UpdateInfo { @@ -18,15 +20,19 @@ interface UpdateInfo { currentVersion?: string; hasUpdate: boolean; error?: string; + qualityScore?: number | null; + stars?: number | null; + pushedAt?: string | null; } export class CheckCommand extends Command { static override paths = [['check']]; static override usage = Command.Usage({ - description: 'Check for available skill updates (dry-run)', + description: 'Check installed skills for updates, quality, and activity', details: ` Checks if installed skills have updates available from their sources. + Shows quality scores and GitHub activity for each skill. Does not modify any files - just reports what would be updated. `, examples: [ @@ -89,12 +95,15 @@ export class CheckCommand extends Command { for (const skill of skillsToCheck) { const metadata = loadSkillMetadata(skill.path); + const quality = evaluateSkillDirectory(skill.path); + const qualityScore = quality?.overall ?? null; if (!metadata) { results.push({ name: skill.name, hasUpdate: false, error: 'No metadata (reinstall needed)', + qualityScore, }); continue; } @@ -114,6 +123,7 @@ export class CheckCommand extends Command { name: skill.name, hasUpdate: false, error: 'Local source missing', + qualityScore, }); if (this.verbose) s.stop(`${skill.name}: source missing`); continue; @@ -128,15 +138,15 @@ export class CheckCommand extends Command { const installedTime = statSync(installedSkillMd).mtime; if (sourceTime > installedTime) { - results.push({ name: skill.name, hasUpdate: true }); + results.push({ name: skill.name, hasUpdate: true, qualityScore }); updatesAvailable++; if (this.verbose) s.stop(`${skill.name}: update available`); } else { - results.push({ name: skill.name, hasUpdate: false }); + results.push({ name: skill.name, hasUpdate: false, qualityScore }); if (this.verbose) s.stop(`${skill.name}: up to date`); } } else { - results.push({ name: skill.name, hasUpdate: false }); + results.push({ name: skill.name, hasUpdate: false, qualityScore }); if (this.verbose) s.stop(`${skill.name}: up to date`); } } else { @@ -147,15 +157,31 @@ export class CheckCommand extends Command { name: skill.name, hasUpdate: false, error: 'Unknown provider', + qualityScore, }); if (this.verbose) s.stop(`${skill.name}: unknown provider`); continue; } + const parsed = provider.parseSource(metadata.source); + let stars: number | null = null; + let pushedAt: string | null = null; + + if (parsed && provider.name === 'GitHub') { + const activity = await this.fetchGitHubActivity(parsed.owner, parsed.repo); + if (activity) { + stars = activity.stars; + pushedAt = activity.pushedAt; + } + } + results.push({ name: skill.name, hasUpdate: false, currentVersion: metadata.updatedAt || metadata.installedAt, + qualityScore, + stars, + pushedAt, }); if (this.verbose) s.stop(`${skill.name}: remote source (run update to sync)`); } @@ -164,6 +190,7 @@ export class CheckCommand extends Command { name: skill.name, hasUpdate: false, error: err instanceof Error ? err.message : 'Check failed', + qualityScore, }); if (this.verbose) s.stop(`${skill.name}: error`); } @@ -178,27 +205,46 @@ export class CheckCommand extends Command { if (withUpdates.length > 0) { console.log(colors.primary('Updates available:')); for (const r of withUpdates) { - console.log(` ${colors.success(symbols.arrowUp)} ${colors.primary(r.name)}`); + const badge = this.qualityBadgeFor(r.qualityScore); + console.log(` ${colors.success(symbols.arrowUp)} ${colors.primary(r.name)}${badge}`); } console.log(''); } - if (upToDate.length > 0 && this.verbose) { - console.log(colors.muted('Up to date:')); - for (const r of upToDate) { - console.log(` ${colors.muted(symbols.success)} ${colors.muted(r.name)}`); + if (upToDate.length > 0) { + if (this.verbose) { + console.log(colors.muted('Up to date:')); } - console.log(''); + for (const r of upToDate) { + const badge = this.qualityBadgeFor(r.qualityScore); + const activityStr = this.formatActivity(r); + if (this.verbose) { + console.log(` ${colors.muted(symbols.success)} ${colors.muted(r.name)}${badge}${activityStr}`); + } + } + if (this.verbose) console.log(''); } if (withErrors.length > 0) { console.log(colors.warning('Could not check:')); for (const r of withErrors) { - console.log(` ${colors.warning(symbols.warning)} ${r.name}: ${colors.muted(r.error || 'unknown')}`); + const badge = this.qualityBadgeFor(r.qualityScore); + console.log(` ${colors.warning(symbols.warning)} ${r.name}${badge}: ${colors.muted(r.error || 'unknown')}`); } console.log(''); } + if (!this.quiet) { + const qualityScores = results + .map(r => r.qualityScore) + .filter((s): s is number => typeof s === 'number'); + if (qualityScores.length > 0) { + const avg = Math.round(qualityScores.reduce((a, b) => a + b, 0) / qualityScores.length); + const grade = getQualityGradeFromScore(avg); + console.log(colors.muted(`Average quality: ${avg}/100 (${grade})`)); + } + } + if (updatesAvailable > 0) { success(`${updatesAvailable} update(s) available`); console.log(colors.muted('Run `skillkit update` to install updates')); @@ -208,4 +254,53 @@ export class CheckCommand extends Command { return 0; } + + private qualityBadgeFor(score: number | null | undefined): string { + if (typeof score !== 'number') return ''; + return ` ${formatQualityBadge(score)}`; + } + + private formatActivity(r: UpdateInfo): string { + const parts: string[] = []; + if (typeof r.stars === 'number' && r.stars > 0) { + parts.push(`${formatCount(r.stars)} stars`); + } + if (r.pushedAt) { + parts.push(`pushed ${this.timeAgo(r.pushedAt)}`); + } + if (parts.length === 0) return ''; + return ` ${colors.muted(`(${parts.join(', ')})`)}`; + } + + private timeAgo(dateStr: string): string { + const now = Date.now(); + const then = new Date(dateStr).getTime(); + if (Number.isNaN(then)) return 'unknown'; + const days = Math.floor((now - then) / 86_400_000); + if (days === 0) return 'today'; + if (days === 1) return 'yesterday'; + if (days < 30) return `${days}d ago`; + if (days < 365) return `${Math.floor(days / 30)}mo ago`; + return `${Math.floor(days / 365)}y ago`; + } + + private async fetchGitHubActivity( + owner: string, + repo: string, + ): Promise<{ stars: number; pushedAt: string | null } | null> { + try { + const response = await fetch( + `https://api.github.com/repos/${owner}/${repo}`, + { signal: AbortSignal.timeout(5000) }, + ); + if (!response.ok) return null; + const data = (await response.json()) as Record; + return { + stars: typeof data.stargazers_count === 'number' ? data.stargazers_count : 0, + pushedAt: typeof data.pushed_at === 'string' ? data.pushed_at : null, + }; + } catch { + return null; + } + } } diff --git a/packages/cli/src/commands/publish.ts b/packages/cli/src/commands/publish.ts index 42c9259d..31d787a3 100644 --- a/packages/cli/src/commands/publish.ts +++ b/packages/cli/src/commands/publish.ts @@ -7,7 +7,15 @@ import { statSync, } from "node:fs"; import { join, basename, dirname, resolve, sep } from "node:path"; -import { colors, warn, success, error, step } from "../onboarding/index.js"; +import { + colors, + warn, + success, + error, + step, + formatQualityBadge, + getQualityGradeFromScore, +} from "../onboarding/index.js"; import { Command, Option } from "clipanion"; import { generateWellKnownIndex, @@ -15,7 +23,9 @@ import { SkillScanner, formatSummary, Severity, + evaluateSkillDirectory, } from "@skillkit/core"; +import { formatCount } from "../helpers.js"; function sanitizeSkillName(name: string): string | null { if (!name || typeof name !== "string") return null; @@ -480,6 +490,14 @@ export class PublishSubmitCommand extends Command { return 1; } + const skillDir = dirname(skillMdPath); + const quality = evaluateSkillDirectory(skillDir); + const qualityScore = quality?.overall ?? null; + const qualityGrade = qualityScore !== null ? getQualityGradeFromScore(qualityScore) : null; + const qualityBadge = qualityScore !== null ? formatQualityBadge(qualityScore) : "N/A"; + + const activity = await this.fetchGitHubActivity(repoInfo.owner, repoInfo.repo); + const skillEntry = { id: `${repoInfo.owner}/${repoInfo.repo}/${skillSlug}`, name: this.formatName(skillName), @@ -496,6 +514,19 @@ export class PublishSubmitCommand extends Command { console.log(colors.muted(` Description: ${skillEntry.description}`)); console.log(colors.muted(` Source: ${skillEntry.source}`)); console.log(colors.muted(` Tags: ${skillEntry.tags.join(", ")}`)); + console.log(colors.muted(` Quality: ${qualityBadge}${qualityScore !== null ? ` (${qualityScore}/100)` : ""}`)); + if (activity) { + const stars = formatCount(activity.stars); + const pushed = activity.pushedAt ? this.timeAgo(activity.pushedAt) : "unknown"; + console.log(colors.muted(` Stars: ${stars}`)); + console.log(colors.muted(` Last push: ${pushed}`)); + } + if (quality && quality.warnings.length > 0) { + console.log(colors.warning(` Warnings:`)); + for (const w of quality.warnings.slice(0, 3)) { + console.log(colors.muted(` - ${w}`)); + } + } console.log(); if (this.dryRun) { @@ -504,33 +535,61 @@ export class PublishSubmitCommand extends Command { return 0; } - const issueBody = this.createIssueBody(skillEntry); - const issueTitle = encodeURIComponent(`[Publish] ${skillEntry.name}`); - const issueBodyEncoded = encodeURIComponent(issueBody); - const issueUrl = `https://github.com/rohitg00/skillkit/issues/new?title=${issueTitle}&body=${issueBodyEncoded}&labels=skill-submission,publish`; - - success("Opening GitHub to submit your skill...\n"); + const issueBody = this.createIssueBody(skillEntry, { + qualityScore, + qualityGrade, + warnings: quality?.warnings ?? [], + stars: activity?.stars ?? null, + pushedAt: activity?.pushedAt ?? null, + }); try { const { execFileSync } = await import("node:child_process"); - const cmd = - process.platform === "darwin" - ? "open" - : process.platform === "win32" - ? "cmd" - : "xdg-open"; - const args = - process.platform === "win32" - ? ["/c", "start", "", issueUrl] - : [issueUrl]; - execFileSync(cmd, args, { stdio: "ignore" }); + const result = execFileSync( + "gh", + [ + "issue", + "create", + "--repo", + "rohitg00/skillkit", + "--title", + `[Publish] ${skillEntry.name}`, + "--body", + issueBody, + "--label", + "skill-submission,publish", + ], + { + encoding: "utf-8", + stdio: ["pipe", "pipe", "pipe"], + timeout: 15_000, + }, + ).trim(); - success("GitHub issue page opened!"); - console.log(colors.muted("Review and submit the issue.")); - } catch { - warn("Could not open browser automatically."); - console.log(colors.muted("Please open this URL manually:\n")); - console.log(colors.cyan(issueUrl)); + success("Submission created!"); + if (result) { + console.log(colors.muted(` ${result}`)); + } + } catch (err) { + const message = err instanceof Error ? err.message : String(err); + if (message.includes("not found") || message.includes("ENOENT")) { + error("GitHub CLI (gh) is not installed"); + console.error( + colors.muted("Install it from https://cli.github.com then run `gh auth login`"), + ); + } else if (message.includes("auth") || message.includes("401")) { + error("GitHub CLI is not authenticated"); + console.error(colors.muted("Run `gh auth login` first")); + } else { + error("Failed to create issue"); + console.error(colors.muted(message)); + } + + console.log(); + warn("You can submit manually instead:"); + const manualUrl = `https://github.com/rohitg00/skillkit/issues/new?title=${encodeURIComponent(`[Publish] ${skillEntry.name}`)}&labels=skill-submission,publish`; + console.log(colors.cyan(manualUrl)); + return 1; } return 0; @@ -601,13 +660,68 @@ export class PublishSubmitCommand extends Command { .join(" "); } - private createIssueBody(skill: { - id: string; - name: string; - description: string; - source: string; - tags: string[]; - }): string { + private async fetchGitHubActivity( + owner: string, + repo: string, + ): Promise<{ stars: number; pushedAt: string | null } | null> { + try { + const response = await fetch( + `https://api.github.com/repos/${owner}/${repo}`, + { signal: AbortSignal.timeout(5000) }, + ); + if (!response.ok) return null; + const data = (await response.json()) as Record; + return { + stars: typeof data.stargazers_count === "number" ? data.stargazers_count : 0, + pushedAt: typeof data.pushed_at === "string" ? data.pushed_at : null, + }; + } catch { + return null; + } + } + + private timeAgo(dateStr: string): string { + const now = Date.now(); + const then = new Date(dateStr).getTime(); + if (Number.isNaN(then)) return "unknown"; + const days = Math.floor((now - then) / 86_400_000); + if (days === 0) return "today"; + if (days === 1) return "yesterday"; + if (days < 30) return `${days}d ago`; + if (days < 365) return `${Math.floor(days / 30)}mo ago`; + return `${Math.floor(days / 365)}y ago`; + } + + private createIssueBody( + skill: { + id: string; + name: string; + description: string; + source: string; + tags: string[]; + }, + meta: { + qualityScore: number | null; + qualityGrade: string | null; + warnings: string[]; + stars: number | null; + pushedAt: string | null; + }, + ): string { + const qualityLine = + meta.qualityScore !== null + ? `- **Quality:** ${meta.qualityGrade} (${meta.qualityScore}/100)` + : "- **Quality:** N/A"; + const starsLine = + typeof meta.stars === "number" ? `- **Stars:** ${formatCount(meta.stars)}` : ""; + const pushLine = meta.pushedAt + ? `- **Last push:** ${meta.pushedAt.slice(0, 10)}` + : ""; + const warningLines = + meta.warnings.length > 0 + ? `\n### Warnings\n${meta.warnings.map((w) => `- ${w}`).join("\n")}` + : ""; + return `## Publish Skill Request ### Skill Details @@ -616,6 +730,10 @@ export class PublishSubmitCommand extends Command { - **Description:** ${skill.description} - **Source:** [${skill.source}](https://github.com/${skill.source}) - **Tags:** ${skill.tags.map((t) => `\`${t}\``).join(", ")} +${qualityLine} +${starsLine} +${pushLine} +${warningLines} ### JSON Entry \`\`\`json