mirror of
https://github.com/rohitg00/skillkit.git
synced 2026-11-20 12:23:29 +00:00
* feat: add persistent memory, mesh network, and agent messaging (v2.0.0)
Add three major features to SkillKit:
@skillkit/memory - CozoDB-backed semantic memory with embeddings
- 384-dim embeddings via @xenova/transformers (all-MiniLM-L6-v2)
- Memory tiers (warm/long) with promotion logic based on access patterns
- HNSW semantic search for context retrieval
- Storage: ~/.skillkit/agents/{agentId}/memory.db
@skillkit/mesh - Peer mesh network for multi-machine agent distribution
- Local LAN discovery via UDP multicast (239.255.255.250)
- Tailscale VPN support for secure remote connections
- Bidirectional peer registration with health checks
- HTTP and WebSocket transports
- Storage: ~/.skillkit/hosts.json
@skillkit/messaging - Inter-agent messaging system
- Inbox/sent/archived storage with JSON persistence
- Message router for local and cross-host delivery
- Priority levels (low/normal/high/urgent)
- Message types (request/response/notification/update)
- Storage: ~/.skillkit/messages/{inbox|sent|archived}/{agentId}/
CLI Commands:
- skillkit mesh: init, add, remove, list, health, discover, status
- skillkit message: send, inbox, read, reply, archive, forward, sent, status
All packages bumped to version 2.0.0
* feat: add advanced learning, automation, and workflow features
Implements comprehensive enhancement plan with 9 phases:
Phase 1: @skillkit/resources Package
- Bundled agents (9): architect, build-error-resolver, code-reviewer,
doc-updater, e2e-runner, planner, refactor-cleaner, security-reviewer, tdd-guide
- Command templates (10): /tdd, /plan, /e2e, /learn, /build-fix, etc.
- Operational profiles (4): dev, review, research, security
- Guidelines (5): security, code-style, testing, git, performance
- Hook templates (12): typescript-check, eslint-check, security-scan, etc.
Phase 2-3: Pattern Learning & Confidence Scoring
- skillkit learn: Extract patterns from git history
- skillkit pattern status|feedback|approve|reject|export|import|cluster
- Confidence evolution: success +0.05, failure -0.10
Phase 4: Session State Persistence
- skillkit session status|start|load|list|note|complete|in-progress
- Cross-session context preservation in ~/.skillkit/sessions/
Phase 5: Workflow Pipelines
- skillkit workflow pipeline list|<name>
- Built-in: feature, bugfix, refactor, security-audit, documentation
Phase 6: Operational Profiles
- skillkit profile list|<name>|create|remove
- Mode switching for different work contexts
Phase 7: Guidelines System
- skillkit guideline list|show|enable|disable|create|remove
- Always-on coding standards
Phase 8: Hook Templates
- skillkit hook template list|apply|show
- Pre-built automation patterns
Phase 9: Slash Command Templates
- skillkit command available|install <id>
- Install bundled command templates
* feat: add MCP memory server for Claude/Cursor integration
Adds @skillkit/mcp-memory package - an MCP (Model Context Protocol) server
that exposes SkillKit's persistent memory system to Claude, Cursor, and
other MCP-compatible AI tools.
Tools:
- memory_store: Store memories with semantic embeddings
- memory_search: Semantic search through memories
- memory_recall: Recall by category/tier/tags
- memory_get: Get memory by ID
- memory_forget: Delete a memory
- memory_link: Create relationships between memories
- memory_reinforce: Strengthen/weaken memories
- memory_stats: Get memory statistics
Resources:
- memory://stats: Current statistics (JSON)
- memory://recent: Recent memories (JSON)
Usage with Claude Desktop:
```json
{
"mcpServers": {
"skillkit-memory": {
"command": "npx",
"args": ["@skillkit/mcp-memory"],
"env": { "SKILLKIT_AGENT_ID": "claude-desktop" }
}
}
}
```
* feat(mesh): add comprehensive security hardening
- Add cryptographic identity layer (Ed25519 keypairs, fingerprints)
- Add message encryption (XChaCha20-Poly1305) and signing
- Add secure keystore with AES-256-GCM at-rest encryption
- Add JWT authentication and challenge-response handshake
- Add secure WebSocket (WSS) and HTTPS transports
- Add signed discovery messages with trust modes (open/signed/trusted-only)
- Add TLS certificate management (self-signed)
- Add CLI commands: mesh security init/status, mesh peer trust/revoke/list
- Add security presets: development, signed, secure, strict
- Align all package versions to 1.7.11
Security stack: @noble/ed25519, @noble/curves, @noble/ciphers, @noble/hashes, jose
* docs(website): add mesh network and security features
- Add Mesh Network feature card with P2P description
- Add Security feature card with Ed25519/TLS details
- Add Mesh command group with security commands
* fix: address CodeRabbit review suggestions
- cli/mesh: validate port input (1-65535 range check)
- memory/cozo-adapter: call db.close() before nullifying reference
- memory/schema: fix primary key definitions (id => columns)
- resources/hooks: guard pre-commit hooks against empty file lists
- mcp-memory: prevent double-initialization with memoized promise
- mcp-memory: don't mask reinforce failures as "not found"
- mcp-memory: guard main() to prevent auto-start on import
- mcp-memory: add js language identifiers to README code blocks
- mesh/test: update MESH_VERSION test expectation to 1.7.11
* fix: address additional CodeRabbit and Devin review suggestions
Memory package:
- encoder: reset initPromise on failure to allow retry
- encoder: call pipeline.dispose() in disposeEncoder to free GPU resources
- schema: fix probe query to use named-column matching for correct arity
Mesh package:
- hosts-config: add file locking to prevent race conditions
- local discovery: reduce multicast TTL to 1 for LAN-only traffic
- local discovery: handle announce errors in setInterval
- local discovery: close socket on membership setup failure
- local discovery: validate inbound packets (type, hostId, port range)
- local discovery: use rinfo.address to prevent spoofing
- health: guard against overlapping health checks with checking flag
- websocket: prevent auto-reconnect on explicit disconnect()
* fix(memory): increase semantic search fetch multiplier for better filter coverage
Increase from 2x to 5x results to reduce likelihood of incomplete
results when agentId/category/tier filters exclude many candidates.
Filters are applied in application code after HNSW vector search.
* feat(cli): add 'add' as alias for 'install' command
* fix(mesh/auth): use asymmetric EdDSA signing for JWT tokens
Tokens are now signed with the sender's Ed25519 private key and
verified using the sender's public key embedded in the token.
This fixes the issue where tokens couldn't be verified across
different AuthManager instances/hosts because each had a random
symmetric secret.
Changes:
- Switch from HS256 (symmetric) to EdDSA (asymmetric) algorithm
- Include sender's publicKey in JWT payload
- Add privateKey/privateKeyHex getters to PeerIdentity
- Verify fingerprint matches publicKey before accepting token
638 lines
20 KiB
TypeScript
638 lines
20 KiB
TypeScript
/**
|
|
* Command CLI
|
|
*
|
|
* Manage slash commands and agent integration.
|
|
*/
|
|
|
|
import { Command, Option } from 'clipanion';
|
|
import { readFile, writeFile, mkdir } from 'node:fs/promises';
|
|
import { resolve, join, dirname, extname } from 'node:path';
|
|
import * as path from 'node:path';
|
|
import * as fs from 'node:fs/promises';
|
|
import { existsSync } from 'node:fs';
|
|
import {
|
|
createCommandRegistry,
|
|
createCommandGenerator,
|
|
getAgentFormat,
|
|
supportsSlashCommands,
|
|
} from '@skillkit/core';
|
|
import type { SlashCommand, AgentType } from '@skillkit/core';
|
|
import {
|
|
getCommandTemplates,
|
|
getCommandTemplate,
|
|
getCommandTemplatesByCategory,
|
|
type CommandTemplate,
|
|
type CommandCategory,
|
|
} from '@skillkit/resources';
|
|
|
|
export class CommandCmd extends Command {
|
|
static paths = [['command']];
|
|
|
|
static usage = Command.Usage({
|
|
category: 'Commands',
|
|
description: 'Manage slash commands and agent integration',
|
|
details: `
|
|
This command provides tools for working with slash commands.
|
|
|
|
Actions:
|
|
- list: List registered commands
|
|
- create: Create a new command from a skill
|
|
- generate: Generate agent-specific command files
|
|
- validate: Validate command definitions
|
|
- export: Export commands to a bundle
|
|
- import: Import commands from a bundle
|
|
|
|
Examples:
|
|
$ skillkit command list
|
|
$ skillkit command create my-skill --name my-command
|
|
$ skillkit command generate --agent claude-code
|
|
$ skillkit command validate ./commands.json
|
|
`,
|
|
examples: [
|
|
['List all commands', '$0 command list'],
|
|
['Create command from skill', '$0 command create tdd --name run-tdd'],
|
|
['Generate for Claude Code', '$0 command generate --agent claude-code'],
|
|
['Export commands', '$0 command export --output commands.json'],
|
|
],
|
|
});
|
|
|
|
action = Option.String({ required: true });
|
|
|
|
skill = Option.String('--skill,-s', {
|
|
description: 'Skill to create command from',
|
|
});
|
|
|
|
name = Option.String('--name,-n', {
|
|
description: 'Command name',
|
|
});
|
|
|
|
description = Option.String('--description,-d', {
|
|
description: 'Command description',
|
|
});
|
|
|
|
agent = Option.String('--agent,-a', {
|
|
description: 'Target agent for generation',
|
|
});
|
|
|
|
output = Option.String('--output,-o', {
|
|
description: 'Output file or directory',
|
|
});
|
|
|
|
input = Option.String('--input,-i', {
|
|
description: 'Input file',
|
|
});
|
|
|
|
category = Option.String('--category,-c', {
|
|
description: 'Command category',
|
|
});
|
|
|
|
all = Option.Boolean('--all', false, {
|
|
description: 'Include all commands (hidden and disabled)',
|
|
});
|
|
|
|
json = Option.Boolean('--json', false, {
|
|
description: 'Output as JSON',
|
|
});
|
|
|
|
dryRun = Option.Boolean('--dry-run', false, {
|
|
description: 'Show what would be generated without writing files',
|
|
});
|
|
|
|
async execute(): Promise<number> {
|
|
try {
|
|
switch (this.action) {
|
|
case 'list':
|
|
return await this.listCommands();
|
|
case 'create':
|
|
return await this.createCommand();
|
|
case 'generate':
|
|
return await this.generateCommands();
|
|
case 'validate':
|
|
return await this.validateCommands();
|
|
case 'export':
|
|
return await this.exportCommands();
|
|
case 'import':
|
|
return await this.importCommands();
|
|
case 'info':
|
|
return await this.showInfo();
|
|
default:
|
|
this.context.stderr.write(
|
|
`Unknown action: ${this.action}\n` +
|
|
`Available actions: list, create, generate, validate, export, import, info\n`
|
|
);
|
|
return 1;
|
|
}
|
|
} catch (error) {
|
|
this.context.stderr.write(`Error: ${(error as Error).message}\n`);
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
private async listCommands(): Promise<number> {
|
|
const registry = createCommandRegistry();
|
|
|
|
// Load commands from local config
|
|
await this.loadCommandsFromConfig(registry);
|
|
|
|
const commands = registry.search({
|
|
category: this.category,
|
|
includeHidden: this.all,
|
|
includeDisabled: this.all,
|
|
});
|
|
|
|
if (this.json) {
|
|
this.context.stdout.write(JSON.stringify(commands, null, 2) + '\n');
|
|
} else {
|
|
if (commands.length === 0) {
|
|
this.context.stdout.write('No commands registered.\n');
|
|
this.context.stdout.write('Use "skillkit command create" to create commands from skills.\n');
|
|
return 0;
|
|
}
|
|
|
|
this.context.stdout.write(`Registered Commands (${commands.length}):\n\n`);
|
|
|
|
// Group by category
|
|
const categories = new Map<string, typeof commands>();
|
|
for (const cmd of commands) {
|
|
const cat = cmd.category || 'uncategorized';
|
|
if (!categories.has(cat)) {
|
|
categories.set(cat, []);
|
|
}
|
|
categories.get(cat)!.push(cmd);
|
|
}
|
|
|
|
for (const [category, cmds] of categories) {
|
|
this.context.stdout.write(` ${category.toUpperCase()}\n`);
|
|
for (const cmd of cmds) {
|
|
const status = cmd.enabled ? '' : ' (disabled)';
|
|
const hidden = cmd.hidden ? ' (hidden)' : '';
|
|
this.context.stdout.write(` /${cmd.name}${status}${hidden}\n`);
|
|
this.context.stdout.write(` ${cmd.description}\n`);
|
|
if (cmd.aliases && cmd.aliases.length > 0) {
|
|
this.context.stdout.write(` Aliases: ${cmd.aliases.join(', ')}\n`);
|
|
}
|
|
}
|
|
this.context.stdout.write('\n');
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
private async createCommand(): Promise<number> {
|
|
if (!this.skill) {
|
|
this.context.stderr.write('Error: --skill is required for create action\n');
|
|
return 1;
|
|
}
|
|
|
|
const commandName = this.name || this.skill.toLowerCase().replace(/[^a-z0-9]+/g, '-');
|
|
|
|
const command: SlashCommand = {
|
|
name: commandName,
|
|
description: this.description || `Execute ${this.skill} skill`,
|
|
skill: this.skill,
|
|
category: this.category,
|
|
examples: [`/${commandName}`],
|
|
};
|
|
|
|
// Save to commands config
|
|
const configPath = resolve(process.cwd(), '.skillkit', 'commands.json');
|
|
let commands: SlashCommand[] = [];
|
|
|
|
if (existsSync(configPath)) {
|
|
const content = await readFile(configPath, 'utf-8');
|
|
const config = JSON.parse(content);
|
|
commands = config.commands || [];
|
|
}
|
|
|
|
// Check if command already exists
|
|
const existing = commands.findIndex((c) => c.name === commandName);
|
|
if (existing >= 0) {
|
|
// Merge new properties with existing command to preserve metadata
|
|
const previous = commands[existing];
|
|
commands[existing] = {
|
|
...previous,
|
|
name: commandName,
|
|
skill: this.skill,
|
|
description: this.description ?? previous.description ?? command.description,
|
|
category: this.category ?? previous.category,
|
|
examples: command.examples?.length ? command.examples : previous.examples,
|
|
// Preserve existing metadata if not provided
|
|
aliases: previous.aliases,
|
|
args: previous.args,
|
|
tags: previous.tags,
|
|
hidden: previous.hidden,
|
|
metadata: previous.metadata,
|
|
};
|
|
this.context.stdout.write(`Updated command: /${commandName}\n`);
|
|
} else {
|
|
commands.push(command);
|
|
this.context.stdout.write(`Created command: /${commandName}\n`);
|
|
}
|
|
|
|
// Ensure directory exists
|
|
await mkdir(dirname(configPath), { recursive: true });
|
|
|
|
// Save config
|
|
await writeFile(
|
|
configPath,
|
|
JSON.stringify({ version: '1.0.0', commands }, null, 2)
|
|
);
|
|
|
|
this.context.stdout.write(`Saved to: ${configPath}\n`);
|
|
|
|
return 0;
|
|
}
|
|
|
|
private async generateCommands(): Promise<number> {
|
|
const agent = (this.agent || 'claude-code') as AgentType;
|
|
|
|
if (!supportsSlashCommands(agent)) {
|
|
this.context.stdout.write(`Note: ${agent} has limited slash command support.\n`);
|
|
}
|
|
|
|
const registry = createCommandRegistry();
|
|
await this.loadCommandsFromConfig(registry);
|
|
|
|
const commands = registry.getAll(this.all);
|
|
|
|
if (commands.length === 0) {
|
|
this.context.stderr.write('No commands to generate. Create commands first.\n');
|
|
return 1;
|
|
}
|
|
|
|
const generator = createCommandGenerator({
|
|
includeHidden: this.all,
|
|
includeDisabled: this.all,
|
|
});
|
|
|
|
const format = getAgentFormat(agent);
|
|
const outputTarget = this.output
|
|
? resolve(this.output)
|
|
: resolve(process.cwd(), format.directory);
|
|
const outputDir = extname(outputTarget) ? dirname(outputTarget) : outputTarget;
|
|
|
|
const result = generator.generate(commands, agent);
|
|
|
|
if (typeof result === 'string') {
|
|
// Single file output (e.g., Cursor rules)
|
|
const extension = format.extension
|
|
? format.extension.startsWith('.') ? format.extension : `.${format.extension}`
|
|
: '.mdc';
|
|
const filePath = extname(outputTarget)
|
|
? outputTarget
|
|
: join(outputTarget, `commands${extension}`);
|
|
|
|
if (this.dryRun) {
|
|
this.context.stdout.write('Would write to: ' + filePath + '\n\n');
|
|
this.context.stdout.write(result);
|
|
} else {
|
|
await mkdir(dirname(filePath), { recursive: true });
|
|
await writeFile(filePath, result);
|
|
this.context.stdout.write(`Generated: ${filePath}\n`);
|
|
}
|
|
} else {
|
|
// Multiple file output
|
|
if (extname(outputTarget)) {
|
|
this.context.stderr.write(
|
|
'Error: --output must be a directory for multi-file formats\n'
|
|
);
|
|
return 1;
|
|
}
|
|
|
|
if (this.dryRun) {
|
|
this.context.stdout.write('Would write to: ' + outputDir + '\n\n');
|
|
for (const [filename, content] of result) {
|
|
this.context.stdout.write(`--- ${filename} ---\n`);
|
|
this.context.stdout.write(content.substring(0, 500));
|
|
if (content.length > 500) {
|
|
this.context.stdout.write('\n... (truncated)\n');
|
|
}
|
|
this.context.stdout.write('\n');
|
|
}
|
|
} else {
|
|
await mkdir(outputDir, { recursive: true });
|
|
for (const [filename, content] of result) {
|
|
const filePath = join(outputDir, filename);
|
|
await writeFile(filePath, content);
|
|
this.context.stdout.write(`Generated: ${filePath}\n`);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Generate manifest
|
|
const manifestPath = join(outputDir, 'manifest.json');
|
|
const manifest = generator.generateManifest(commands);
|
|
|
|
if (!this.dryRun) {
|
|
await writeFile(manifestPath, manifest);
|
|
this.context.stdout.write(`Generated: ${manifestPath}\n`);
|
|
}
|
|
|
|
this.context.stdout.write(`\nGenerated ${commands.length} commands for ${agent}\n`);
|
|
|
|
return 0;
|
|
}
|
|
|
|
private async validateCommands(): Promise<number> {
|
|
const inputPath = this.input || resolve(process.cwd(), '.skillkit', 'commands.json');
|
|
|
|
if (!existsSync(inputPath)) {
|
|
this.context.stderr.write(`File not found: ${inputPath}\n`);
|
|
return 1;
|
|
}
|
|
|
|
const content = await readFile(inputPath, 'utf-8');
|
|
const config = JSON.parse(content);
|
|
const commands: SlashCommand[] = config.commands || [];
|
|
|
|
const registry = createCommandRegistry({ validateOnRegister: false });
|
|
let valid = 0;
|
|
let invalid = 0;
|
|
|
|
this.context.stdout.write(`Validating ${commands.length} commands...\n\n`);
|
|
|
|
for (const command of commands) {
|
|
const result = registry.validate(command);
|
|
|
|
if (result.valid) {
|
|
valid++;
|
|
if (!this.json) {
|
|
this.context.stdout.write(`\u2713 /${command.name}\n`);
|
|
}
|
|
} else {
|
|
invalid++;
|
|
if (!this.json) {
|
|
this.context.stdout.write(`\u2717 /${command.name}\n`);
|
|
for (const error of result.errors) {
|
|
this.context.stdout.write(` Error: ${error}\n`);
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!this.json && result.warnings.length > 0) {
|
|
for (const warning of result.warnings) {
|
|
this.context.stdout.write(` Warning: ${warning}\n`);
|
|
}
|
|
}
|
|
}
|
|
|
|
if (this.json) {
|
|
this.context.stdout.write(
|
|
JSON.stringify({
|
|
total: commands.length,
|
|
valid,
|
|
invalid,
|
|
}) + '\n'
|
|
);
|
|
} else {
|
|
this.context.stdout.write(`\nValidation complete: ${valid} valid, ${invalid} invalid\n`);
|
|
}
|
|
|
|
return invalid > 0 ? 1 : 0;
|
|
}
|
|
|
|
private async exportCommands(): Promise<number> {
|
|
const registry = createCommandRegistry();
|
|
await this.loadCommandsFromConfig(registry);
|
|
|
|
const bundle = registry.export(this.all);
|
|
|
|
if (this.output) {
|
|
let outputPath = resolve(this.output);
|
|
|
|
// Check if output is a directory or ends with path separator
|
|
const stat = await fs.stat(outputPath).catch(() => null);
|
|
if ((stat && stat.isDirectory()) || this.output.endsWith(path.sep)) {
|
|
outputPath = path.join(outputPath, 'commands.json');
|
|
}
|
|
|
|
// Ensure parent directory exists
|
|
await fs.mkdir(path.dirname(outputPath), { recursive: true });
|
|
await writeFile(outputPath, JSON.stringify(bundle, null, 2));
|
|
this.context.stdout.write(`Exported ${bundle.commands.length} commands to: ${outputPath}\n`);
|
|
} else {
|
|
this.context.stdout.write(JSON.stringify(bundle, null, 2) + '\n');
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
private async importCommands(): Promise<number> {
|
|
if (!this.input) {
|
|
this.context.stderr.write('Error: --input is required for import action\n');
|
|
return 1;
|
|
}
|
|
|
|
const inputPath = resolve(this.input);
|
|
if (!existsSync(inputPath)) {
|
|
this.context.stderr.write(`File not found: ${inputPath}\n`);
|
|
return 1;
|
|
}
|
|
|
|
const content = await readFile(inputPath, 'utf-8');
|
|
const bundle = JSON.parse(content);
|
|
|
|
// Load existing commands
|
|
const configPath = resolve(process.cwd(), '.skillkit', 'commands.json');
|
|
let existingCommands: SlashCommand[] = [];
|
|
|
|
if (existsSync(configPath)) {
|
|
const existingContent = await readFile(configPath, 'utf-8');
|
|
const config = JSON.parse(existingContent);
|
|
existingCommands = config.commands || [];
|
|
}
|
|
|
|
// Merge commands
|
|
const commandMap = new Map<string, SlashCommand>();
|
|
for (const cmd of existingCommands) {
|
|
commandMap.set(cmd.name, cmd);
|
|
}
|
|
for (const cmd of bundle.commands) {
|
|
commandMap.set(cmd.name, cmd);
|
|
}
|
|
|
|
const mergedCommands = Array.from(commandMap.values());
|
|
|
|
// Save
|
|
await mkdir(dirname(configPath), { recursive: true });
|
|
await writeFile(
|
|
configPath,
|
|
JSON.stringify({ version: '1.0.0', commands: mergedCommands }, null, 2)
|
|
);
|
|
|
|
const imported = bundle.commands.length;
|
|
this.context.stdout.write(`Imported ${imported} commands\n`);
|
|
this.context.stdout.write(`Total commands: ${mergedCommands.length}\n`);
|
|
this.context.stdout.write(`Saved to: ${configPath}\n`);
|
|
|
|
return 0;
|
|
}
|
|
|
|
private async showInfo(): Promise<number> {
|
|
const agent = (this.agent || 'claude-code') as AgentType;
|
|
const format = getAgentFormat(agent);
|
|
|
|
if (this.json) {
|
|
this.context.stdout.write(JSON.stringify(format, null, 2) + '\n');
|
|
} else {
|
|
this.context.stdout.write(`Agent: ${agent}\n`);
|
|
this.context.stdout.write(`Directory: ${format.directory}\n`);
|
|
this.context.stdout.write(`Extension: ${format.extension}\n`);
|
|
this.context.stdout.write(`Supports Slash Commands: ${format.supportsSlashCommands}\n`);
|
|
this.context.stdout.write(`Supports Command Files: ${format.supportsCommandFiles}\n`);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
private async loadCommandsFromConfig(
|
|
registry: ReturnType<typeof createCommandRegistry>
|
|
): Promise<void> {
|
|
const configPath = resolve(process.cwd(), '.skillkit', 'commands.json');
|
|
|
|
if (existsSync(configPath)) {
|
|
const content = await readFile(configPath, 'utf-8');
|
|
const config = JSON.parse(content);
|
|
const commands: SlashCommand[] = config.commands || [];
|
|
|
|
for (const command of commands) {
|
|
try {
|
|
registry.register(command);
|
|
} catch {
|
|
// Skip invalid commands
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
export class CommandAvailableCommand extends Command {
|
|
static override paths = [['command', 'available']];
|
|
|
|
static override usage = Command.Usage({
|
|
category: 'Commands',
|
|
description: 'List available bundled command templates',
|
|
examples: [
|
|
['List all available', '$0 command available'],
|
|
['Filter by category', '$0 command available --category testing'],
|
|
],
|
|
});
|
|
|
|
category = Option.String('--category,-c', {
|
|
description: 'Filter by category (testing, planning, development, review, workflow, learning)',
|
|
});
|
|
|
|
json = Option.Boolean('--json,-j', false, {
|
|
description: 'Output as JSON',
|
|
});
|
|
|
|
async execute(): Promise<number> {
|
|
const templates = this.category
|
|
? getCommandTemplatesByCategory(this.category as CommandCategory)
|
|
: getCommandTemplates();
|
|
|
|
if (this.json) {
|
|
this.context.stdout.write(JSON.stringify(templates, null, 2) + '\n');
|
|
return 0;
|
|
}
|
|
|
|
this.context.stdout.write(`Available Command Templates (${templates.length}):\n\n`);
|
|
|
|
const byCategory = new Map<string, CommandTemplate[]>();
|
|
for (const template of templates) {
|
|
const cat = template.category || 'general';
|
|
if (!byCategory.has(cat)) {
|
|
byCategory.set(cat, []);
|
|
}
|
|
byCategory.get(cat)!.push(template);
|
|
}
|
|
|
|
for (const [category, catTemplates] of byCategory) {
|
|
this.context.stdout.write(` ${category.toUpperCase()}\n`);
|
|
for (const template of catTemplates) {
|
|
const agent = template.agent ? ` [${template.agent}]` : '';
|
|
this.context.stdout.write(` ${template.trigger}${agent}\n`);
|
|
this.context.stdout.write(` ${template.description}\n`);
|
|
}
|
|
this.context.stdout.write('\n');
|
|
}
|
|
|
|
this.context.stdout.write('Install with: skillkit command install <id>\n');
|
|
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
export class CommandInstallCommand extends Command {
|
|
static override paths = [['command', 'install']];
|
|
|
|
static override usage = Command.Usage({
|
|
category: 'Commands',
|
|
description: 'Install a bundled command template',
|
|
examples: [
|
|
['Install TDD command', '$0 command install tdd'],
|
|
['Install code review', '$0 command install code-review'],
|
|
],
|
|
});
|
|
|
|
id = Option.String({ required: true });
|
|
|
|
async execute(): Promise<number> {
|
|
const template = getCommandTemplate(this.id);
|
|
|
|
if (!template) {
|
|
this.context.stderr.write(`Command template not found: ${this.id}\n`);
|
|
this.context.stderr.write('Run "skillkit command available" to see available templates.\n');
|
|
return 1;
|
|
}
|
|
|
|
const command: SlashCommand = {
|
|
name: template.id,
|
|
description: template.description,
|
|
skill: `template:${template.id}`,
|
|
category: template.category,
|
|
examples: template.examples,
|
|
metadata: {
|
|
templateId: template.id,
|
|
trigger: template.trigger,
|
|
agent: template.agent,
|
|
prompt: template.prompt,
|
|
},
|
|
};
|
|
|
|
const configPath = resolve(process.cwd(), '.skillkit', 'commands.json');
|
|
let commands: SlashCommand[] = [];
|
|
|
|
if (existsSync(configPath)) {
|
|
const content = await readFile(configPath, 'utf-8');
|
|
const config = JSON.parse(content);
|
|
commands = config.commands || [];
|
|
}
|
|
|
|
const existing = commands.findIndex((c) => c.name === template.id);
|
|
if (existing >= 0) {
|
|
commands[existing] = command;
|
|
this.context.stdout.write(`Updated command: ${template.trigger}\n`);
|
|
} else {
|
|
commands.push(command);
|
|
this.context.stdout.write(`Installed command: ${template.trigger}\n`);
|
|
}
|
|
|
|
await mkdir(dirname(configPath), { recursive: true });
|
|
await writeFile(
|
|
configPath,
|
|
JSON.stringify({ version: '1.0.0', commands }, null, 2)
|
|
);
|
|
|
|
this.context.stdout.write(` Name: ${template.name}\n`);
|
|
this.context.stdout.write(` Description: ${template.description}\n`);
|
|
if (template.agent) {
|
|
this.context.stdout.write(` Agent: ${template.agent}\n`);
|
|
}
|
|
this.context.stdout.write(`\nSaved to: ${configPath}\n`);
|
|
|
|
return 0;
|
|
}
|
|
}
|