diff --git a/apps/skillkit/src/cli.ts b/apps/skillkit/src/cli.ts index 2e317931..8eba159b 100644 --- a/apps/skillkit/src/cli.ts +++ b/apps/skillkit/src/cli.ts @@ -124,6 +124,9 @@ import { TimelineCommand, SessionHandoffCommand, LineageCommand, + TapAddCommand, + TapRemoveCommand, + TapListCommand, } from '@skillkit/cli'; const __filename = fileURLToPath(import.meta.url); @@ -277,4 +280,8 @@ cli.register(TimelineCommand); cli.register(SessionHandoffCommand); cli.register(LineageCommand); +cli.register(TapAddCommand); +cli.register(TapRemoveCommand); +cli.register(TapListCommand); + cli.runExit(process.argv.slice(2)); diff --git a/packages/cli/src/commands/find.ts b/packages/cli/src/commands/find.ts index 7bcd6011..51868ae4 100644 --- a/packages/cli/src/commands/find.ts +++ b/packages/cli/src/commands/find.ts @@ -13,7 +13,7 @@ import { GitHubSkillRegistry, SkillsShRegistry, } from "@skillkit/core"; -import { formatCount } from "../helpers.js"; +import { formatCount, loadTaps } from "../helpers.js"; interface SkillResult { name: string; @@ -87,6 +87,20 @@ export class FindCommand extends Command { }), ); + const taps = loadTaps(); + for (const tap of taps.taps) { + const tapLabel = tap.name || tap.source; + const exists = allSkills.some((s) => s.source === tap.source); + if (!exists) { + allSkills.push({ + name: tapLabel, + description: `Custom tap: ${tap.source}`, + source: tap.source, + repoName: tap.source.split("/").pop() || "", + }); + } + } + let results: SkillResult[]; let searchTerm: string | undefined; diff --git a/packages/cli/src/commands/index.ts b/packages/cli/src/commands/index.ts index 1382a92a..8baa283b 100644 --- a/packages/cli/src/commands/index.ts +++ b/packages/cli/src/commands/index.ts @@ -132,6 +132,7 @@ export { TimelineCommand } from './timeline.js'; export { SessionHandoffCommand } from './handoff.js'; export { LineageCommand } from './lineage.js'; export { SaveCommand } from './save.js'; +export { TapAddCommand, TapRemoveCommand, TapListCommand } from './tap.js'; export { AgentsMdCommand, AgentsMdInitCommand, diff --git a/packages/cli/src/commands/tap.ts b/packages/cli/src/commands/tap.ts new file mode 100644 index 00000000..0b2ee32a --- /dev/null +++ b/packages/cli/src/commands/tap.ts @@ -0,0 +1,106 @@ +import { Command, Option } from 'clipanion'; +import { colors, symbols, step, success, warn } from '../onboarding/index.js'; +import { loadTaps, saveTaps } from '../helpers.js'; + +export class TapAddCommand extends Command { + static override paths = [['tap', 'add']]; + + static override usage = Command.Usage({ + description: 'Add a custom skill source (tap)', + examples: [ + ['Add a GitHub source', '$0 tap add myorg/skills'], + ['Add with a display name', '$0 tap add myorg/skills --name "My Org Skills"'], + ], + }); + + source = Option.String({ required: true }); + + name = Option.String('--name,-n', { + description: 'Display name for the tap', + }); + + async execute(): Promise { + const taps = loadTaps(); + + const exists = taps.taps.some((t) => t.source === this.source); + if (exists) { + warn(`Tap already exists: ${this.source}`); + return 0; + } + + taps.taps.push({ + source: this.source, + name: this.name, + addedAt: new Date().toISOString(), + }); + saveTaps(taps); + + success(`Added tap: ${this.source}${this.name ? ` (${this.name})` : ''}`); + console.log(colors.muted('Skills from this source will appear in search results')); + return 0; + } +} + +export class TapRemoveCommand extends Command { + static override paths = [['tap', 'remove'], ['tap', 'rm']]; + + static override usage = Command.Usage({ + description: 'Remove a custom skill source (tap)', + examples: [ + ['Remove a tap', '$0 tap remove myorg/skills'], + ], + }); + + source = Option.String({ required: true }); + + async execute(): Promise { + const taps = loadTaps(); + + const idx = taps.taps.findIndex((t) => t.source === this.source); + if (idx === -1) { + warn(`Tap not found: ${this.source}`); + return 0; + } + + taps.taps.splice(idx, 1); + saveTaps(taps); + + success(`Removed tap: ${this.source}`); + return 0; + } +} + +export class TapListCommand extends Command { + static override paths = [['tap', 'list'], ['tap', 'ls'], ['tap']]; + + static override usage = Command.Usage({ + description: 'List all custom skill sources (taps)', + examples: [ + ['List taps', '$0 tap list'], + ], + }); + + async execute(): Promise { + const taps = loadTaps(); + + if (taps.taps.length === 0) { + step('No custom taps configured'); + console.log(colors.muted('Add one with: skillkit tap add owner/repo')); + return 0; + } + + step(`${taps.taps.length} tap(s) configured`); + console.log(''); + + for (const tap of taps.taps) { + const label = tap.name ? `${tap.name} (${tap.source})` : tap.source; + console.log(` ${colors.success(symbols.bullet)} ${colors.primary(label)}`); + if (tap.addedAt) { + console.log(` ${colors.muted(`Added: ${tap.addedAt}`)}`); + } + } + + console.log(''); + return 0; + } +} diff --git a/packages/cli/src/helpers.ts b/packages/cli/src/helpers.ts index 00c5155e..f661d9aa 100644 --- a/packages/cli/src/helpers.ts +++ b/packages/cli/src/helpers.ts @@ -1,3 +1,6 @@ +import { existsSync, readFileSync, writeFileSync, mkdirSync } from 'node:fs'; +import { join, dirname } from 'node:path'; +import { homedir } from 'node:os'; import { loadConfig, getSearchDirs as coreGetSearchDirs, @@ -61,6 +64,38 @@ export function timeAgo(dateStr: string): string { return `${Math.floor(days / 365)}y ago`; } +export interface TapEntry { + source: string; + name?: string; + addedAt: string; +} + +export interface TapsFile { + version: 1; + taps: TapEntry[]; +} + +const TAPS_FILE = join(homedir(), '.skillkit', 'taps.json'); + +export function loadTaps(): TapsFile { + if (!existsSync(TAPS_FILE)) return { version: 1, taps: [] }; + try { + const data = JSON.parse(readFileSync(TAPS_FILE, 'utf-8')); + if (data && data.version === 1 && Array.isArray(data.taps)) { + return data as TapsFile; + } + return { version: 1, taps: [] }; + } catch { + return { version: 1, taps: [] }; + } +} + +export function saveTaps(taps: TapsFile): void { + const dir = dirname(TAPS_FILE); + if (!existsSync(dir)) mkdirSync(dir, { recursive: true }); + writeFileSync(TAPS_FILE, JSON.stringify(taps, null, 2), 'utf-8'); +} + export async function fetchGitHubActivity( owner: string, repo: string,