mirror of
https://github.com/rohitg00/skillkit.git
synced 2026-11-20 20:34:46 +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
439 lines
14 KiB
TypeScript
439 lines
14 KiB
TypeScript
/**
|
|
* Hook Command
|
|
*
|
|
* Manage skill hooks for automatic triggering
|
|
*/
|
|
|
|
import { Command, Option } from 'clipanion';
|
|
import chalk from 'chalk';
|
|
import { createHookManager, type HookEvent, type InjectionMode } from '@skillkit/core';
|
|
import {
|
|
getHookTemplates,
|
|
getHookTemplate,
|
|
getHookTemplatesByCategory,
|
|
type HookTemplate,
|
|
type HookTemplateCategory,
|
|
} from '@skillkit/resources';
|
|
|
|
export class HookCommand extends Command {
|
|
static override paths = [['hook']];
|
|
|
|
static override usage = Command.Usage({
|
|
description: 'Manage skill hooks for automatic triggering',
|
|
examples: [
|
|
['List all hooks', '$0 hook list'],
|
|
['Add a session start hook', '$0 hook add session:start tdd-workflow'],
|
|
['Add a file save hook with pattern', '$0 hook add file:save code-review --pattern "*.ts"'],
|
|
['Remove a hook', '$0 hook remove <hook-id>'],
|
|
['Enable a hook', '$0 hook enable <hook-id>'],
|
|
['Disable a hook', '$0 hook disable <hook-id>'],
|
|
['Generate agent hooks', '$0 hook generate --agent claude-code'],
|
|
],
|
|
});
|
|
|
|
action = Option.String({ required: true });
|
|
target = Option.String({ required: false });
|
|
skill = Option.String({ required: false });
|
|
pattern = Option.String('--pattern,-p', { description: 'File pattern matcher' });
|
|
agent = Option.String('--agent,-a', { description: 'Target agent for generation' });
|
|
inject = Option.String('--inject,-i', { description: 'Injection mode: content, reference, prompt' });
|
|
priority = Option.String('--priority', { description: 'Hook priority (higher = earlier)' });
|
|
verbose = Option.Boolean('--verbose,-v', { description: 'Show detailed output' });
|
|
|
|
async execute(): Promise<number> {
|
|
const projectPath = process.cwd();
|
|
|
|
try {
|
|
switch (this.action) {
|
|
case 'list':
|
|
return await this.listHooks(projectPath);
|
|
case 'add':
|
|
return await this.addHook(projectPath);
|
|
case 'remove':
|
|
return await this.removeHook(projectPath);
|
|
case 'enable':
|
|
return await this.enableHook(projectPath);
|
|
case 'disable':
|
|
return await this.disableHook(projectPath);
|
|
case 'generate':
|
|
return await this.generateHooks(projectPath);
|
|
case 'info':
|
|
return await this.showHookInfo(projectPath);
|
|
default:
|
|
this.context.stderr.write(chalk.red(`Unknown action: ${this.action}\n`));
|
|
this.context.stderr.write('Available actions: list, add, remove, enable, disable, generate, info\n');
|
|
return 1;
|
|
}
|
|
} catch (err) {
|
|
this.context.stderr.write(chalk.red(`✗ ${err instanceof Error ? err.message : 'Unknown error'}\n`));
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
private async listHooks(projectPath: string): Promise<number> {
|
|
const manager = createHookManager({ projectPath });
|
|
const hooks = manager.getAllHooks();
|
|
|
|
if (hooks.length === 0) {
|
|
this.context.stdout.write('No hooks configured.\n');
|
|
this.context.stdout.write(chalk.gray('Run `skillkit hook add <event> <skill>` to add a hook.\n'));
|
|
return 0;
|
|
}
|
|
|
|
this.context.stdout.write(chalk.cyan('Configured Hooks:\n\n'));
|
|
|
|
// Group by event
|
|
const eventGroups = new Map<string, typeof hooks>();
|
|
for (const hook of hooks) {
|
|
const group = eventGroups.get(hook.event) || [];
|
|
group.push(hook);
|
|
eventGroups.set(hook.event, group);
|
|
}
|
|
|
|
for (const [event, eventHooks] of eventGroups) {
|
|
this.context.stdout.write(chalk.yellow(`${event}:\n`));
|
|
for (const hook of eventHooks) {
|
|
const status = hook.enabled ? chalk.green('●') : chalk.gray('○');
|
|
this.context.stdout.write(` ${status} ${chalk.white(hook.id.slice(0, 8))} → ${hook.skills.join(', ')}\n`);
|
|
if (hook.matcher) {
|
|
this.context.stdout.write(chalk.gray(` Pattern: ${hook.matcher}\n`));
|
|
}
|
|
if (this.verbose) {
|
|
this.context.stdout.write(chalk.gray(` Inject: ${hook.inject}, Priority: ${hook.priority || 0}\n`));
|
|
}
|
|
}
|
|
}
|
|
|
|
this.context.stdout.write(`\nTotal: ${hooks.length} hooks\n`);
|
|
return 0;
|
|
}
|
|
|
|
private async addHook(projectPath: string): Promise<number> {
|
|
if (!this.target) {
|
|
this.context.stderr.write(chalk.red('Event type required.\n'));
|
|
this.context.stderr.write('Usage: skillkit hook add <event> <skill>\n');
|
|
this.context.stderr.write('Events: session:start, session:end, file:save, file:open, task:start, commit:pre, commit:post, error:occur, test:fail, build:fail\n');
|
|
return 1;
|
|
}
|
|
|
|
if (!this.skill) {
|
|
this.context.stderr.write(chalk.red('Skill name required.\n'));
|
|
this.context.stderr.write('Usage: skillkit hook add <event> <skill>\n');
|
|
return 1;
|
|
}
|
|
|
|
const event = this.target as HookEvent;
|
|
const validEvents: HookEvent[] = [
|
|
'session:start', 'session:resume', 'session:end',
|
|
'file:open', 'file:save', 'file:create', 'file:delete',
|
|
'task:start', 'task:complete',
|
|
'commit:pre', 'commit:post',
|
|
'error:occur', 'test:fail', 'test:pass',
|
|
'build:start', 'build:fail', 'build:success',
|
|
];
|
|
|
|
if (!validEvents.includes(event)) {
|
|
this.context.stderr.write(chalk.red(`Invalid event: ${this.target}\n`));
|
|
this.context.stderr.write(`Valid events: ${validEvents.join(', ')}\n`);
|
|
return 1;
|
|
}
|
|
|
|
const manager = createHookManager({ projectPath });
|
|
|
|
const hook = manager.registerHook({
|
|
event,
|
|
skills: [this.skill],
|
|
inject: (this.inject as InjectionMode) || 'reference',
|
|
matcher: this.pattern,
|
|
priority: this.priority ? parseInt(this.priority, 10) : 0,
|
|
enabled: true,
|
|
});
|
|
|
|
manager.save();
|
|
|
|
this.context.stdout.write(chalk.green(`✓ Hook added: ${hook.id.slice(0, 8)}\n`));
|
|
this.context.stdout.write(` Event: ${event}\n`);
|
|
this.context.stdout.write(` Skill: ${this.skill}\n`);
|
|
if (this.pattern) {
|
|
this.context.stdout.write(` Pattern: ${this.pattern}\n`);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
private async removeHook(projectPath: string): Promise<number> {
|
|
if (!this.target) {
|
|
this.context.stderr.write(chalk.red('Hook ID required.\n'));
|
|
this.context.stderr.write('Usage: skillkit hook remove <hook-id>\n');
|
|
return 1;
|
|
}
|
|
|
|
const manager = createHookManager({ projectPath });
|
|
const hooks = manager.getAllHooks();
|
|
|
|
// Find hook by ID prefix
|
|
const hook = hooks.find((h) => h.id.startsWith(this.target!));
|
|
if (!hook) {
|
|
this.context.stderr.write(chalk.red(`Hook not found: ${this.target}\n`));
|
|
return 1;
|
|
}
|
|
|
|
manager.unregisterHook(hook.id);
|
|
manager.save();
|
|
|
|
this.context.stdout.write(chalk.green(`✓ Hook removed: ${hook.id.slice(0, 8)}\n`));
|
|
return 0;
|
|
}
|
|
|
|
private async enableHook(projectPath: string): Promise<number> {
|
|
if (!this.target) {
|
|
this.context.stderr.write(chalk.red('Hook ID required.\n'));
|
|
return 1;
|
|
}
|
|
|
|
const manager = createHookManager({ projectPath });
|
|
const hooks = manager.getAllHooks();
|
|
const hook = hooks.find((h) => h.id.startsWith(this.target!));
|
|
|
|
if (!hook) {
|
|
this.context.stderr.write(chalk.red(`Hook not found: ${this.target}\n`));
|
|
return 1;
|
|
}
|
|
|
|
manager.enableHook(hook.id);
|
|
manager.save();
|
|
|
|
this.context.stdout.write(chalk.green(`✓ Hook enabled: ${hook.id.slice(0, 8)}\n`));
|
|
return 0;
|
|
}
|
|
|
|
private async disableHook(projectPath: string): Promise<number> {
|
|
if (!this.target) {
|
|
this.context.stderr.write(chalk.red('Hook ID required.\n'));
|
|
return 1;
|
|
}
|
|
|
|
const manager = createHookManager({ projectPath });
|
|
const hooks = manager.getAllHooks();
|
|
const hook = hooks.find((h) => h.id.startsWith(this.target!));
|
|
|
|
if (!hook) {
|
|
this.context.stderr.write(chalk.red(`Hook not found: ${this.target}\n`));
|
|
return 1;
|
|
}
|
|
|
|
manager.disableHook(hook.id);
|
|
manager.save();
|
|
|
|
this.context.stdout.write(chalk.yellow(`○ Hook disabled: ${hook.id.slice(0, 8)}\n`));
|
|
return 0;
|
|
}
|
|
|
|
private async generateHooks(projectPath: string): Promise<number> {
|
|
const manager = createHookManager({ projectPath });
|
|
const hooks = manager.getAllHooks();
|
|
|
|
if (hooks.length === 0) {
|
|
this.context.stdout.write('No hooks configured to generate.\n');
|
|
return 0;
|
|
}
|
|
|
|
const agent = this.agent || 'claude-code';
|
|
const generated = manager.generateAgentHooks(agent as any);
|
|
|
|
this.context.stdout.write(chalk.cyan(`Generated hooks for ${agent}:\n\n`));
|
|
|
|
if (typeof generated === 'string') {
|
|
this.context.stdout.write(generated);
|
|
} else {
|
|
this.context.stdout.write(JSON.stringify(generated, null, 2));
|
|
}
|
|
|
|
this.context.stdout.write('\n');
|
|
return 0;
|
|
}
|
|
|
|
private async showHookInfo(projectPath: string): Promise<number> {
|
|
if (!this.target) {
|
|
this.context.stderr.write(chalk.red('Hook ID required.\n'));
|
|
return 1;
|
|
}
|
|
|
|
const manager = createHookManager({ projectPath });
|
|
const hooks = manager.getAllHooks();
|
|
const hook = hooks.find((h) => h.id.startsWith(this.target!));
|
|
|
|
if (!hook) {
|
|
this.context.stderr.write(chalk.red(`Hook not found: ${this.target}\n`));
|
|
return 1;
|
|
}
|
|
|
|
this.context.stdout.write(chalk.cyan(`\nHook: ${hook.id}\n`));
|
|
this.context.stdout.write(`Event: ${hook.event}\n`);
|
|
this.context.stdout.write(`Skills: ${hook.skills.join(', ')}\n`);
|
|
this.context.stdout.write(`Enabled: ${hook.enabled ? 'Yes' : 'No'}\n`);
|
|
this.context.stdout.write(`Inject: ${hook.inject}\n`);
|
|
this.context.stdout.write(`Priority: ${hook.priority || 0}\n`);
|
|
if (hook.matcher) {
|
|
this.context.stdout.write(`Pattern: ${hook.matcher}\n`);
|
|
}
|
|
if (hook.condition) {
|
|
this.context.stdout.write(`Condition: ${hook.condition}\n`);
|
|
}
|
|
if (hook.agentOverrides) {
|
|
this.context.stdout.write(`Agent Overrides: ${Object.keys(hook.agentOverrides).join(', ')}\n`);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
export class HookTemplateListCommand extends Command {
|
|
static override paths = [['hook', 'template', 'list']];
|
|
|
|
static override usage = Command.Usage({
|
|
description: 'List available hook templates',
|
|
examples: [
|
|
['List all templates', '$0 hook template list'],
|
|
['Filter by category', '$0 hook template list --category quality'],
|
|
],
|
|
});
|
|
|
|
category = Option.String('--category,-c', {
|
|
description: 'Filter by category (security, quality, workflow, productivity)',
|
|
});
|
|
|
|
json = Option.Boolean('--json,-j', false, {
|
|
description: 'Output as JSON',
|
|
});
|
|
|
|
async execute(): Promise<number> {
|
|
let templates = this.category
|
|
? getHookTemplatesByCategory(this.category as HookTemplateCategory)
|
|
: getHookTemplates();
|
|
|
|
if (this.json) {
|
|
console.log(JSON.stringify(templates, null, 2));
|
|
return 0;
|
|
}
|
|
|
|
console.log(chalk.cyan(`Hook Templates (${templates.length}):\n`));
|
|
|
|
const byCategory = new Map<HookTemplateCategory, HookTemplate[]>();
|
|
for (const template of templates) {
|
|
if (!byCategory.has(template.category)) {
|
|
byCategory.set(template.category, []);
|
|
}
|
|
byCategory.get(template.category)!.push(template);
|
|
}
|
|
|
|
for (const [category, catTemplates] of byCategory) {
|
|
console.log(chalk.blue(` ${formatCategory(category)}`));
|
|
for (const template of catTemplates) {
|
|
const blocking = template.blocking ? chalk.yellow(' [blocking]') : '';
|
|
console.log(` ${chalk.bold(template.id)}${blocking}`);
|
|
console.log(` ${chalk.dim(template.description)}`);
|
|
console.log(` Event: ${template.event}`);
|
|
}
|
|
console.log();
|
|
}
|
|
|
|
console.log(chalk.dim('Apply with: skillkit hook template apply <id>'));
|
|
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
export class HookTemplateApplyCommand extends Command {
|
|
static override paths = [['hook', 'template', 'apply']];
|
|
|
|
static override usage = Command.Usage({
|
|
description: 'Apply a hook template',
|
|
examples: [
|
|
['Apply typescript-check', '$0 hook template apply typescript-check'],
|
|
['Apply security-scan', '$0 hook template apply security-scan'],
|
|
],
|
|
});
|
|
|
|
id = Option.String({ required: true });
|
|
|
|
async execute(): Promise<number> {
|
|
const template = getHookTemplate(this.id);
|
|
|
|
if (!template) {
|
|
console.log(chalk.red(`Template not found: ${this.id}`));
|
|
console.log(chalk.dim('Run `skillkit hook template list` to see available templates'));
|
|
return 1;
|
|
}
|
|
|
|
const projectPath = process.cwd();
|
|
const manager = createHookManager({ projectPath });
|
|
|
|
const hook = manager.registerHook({
|
|
event: template.event as HookEvent,
|
|
skills: [`template:${template.id}`],
|
|
inject: 'content',
|
|
matcher: template.matcher,
|
|
enabled: true,
|
|
metadata: {
|
|
templateId: template.id,
|
|
command: template.command,
|
|
timeout: template.timeout,
|
|
blocking: template.blocking,
|
|
},
|
|
});
|
|
|
|
manager.save();
|
|
|
|
console.log(chalk.green(`✓ Applied template: ${template.name}`));
|
|
console.log(` Hook ID: ${hook.id.slice(0, 8)}`);
|
|
console.log(` Event: ${template.event}`);
|
|
console.log(` Command: ${chalk.dim(template.command)}`);
|
|
if (template.blocking) {
|
|
console.log(chalk.yellow(` Blocking: yes`));
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
export class HookTemplateShowCommand extends Command {
|
|
static override paths = [['hook', 'template', 'show']];
|
|
|
|
static override usage = Command.Usage({
|
|
description: 'Show hook template details',
|
|
examples: [['Show template', '$0 hook template show typescript-check']],
|
|
});
|
|
|
|
id = Option.String({ required: true });
|
|
|
|
async execute(): Promise<number> {
|
|
const template = getHookTemplate(this.id);
|
|
|
|
if (!template) {
|
|
console.log(chalk.red(`Template not found: ${this.id}`));
|
|
return 1;
|
|
}
|
|
|
|
console.log(chalk.cyan(`Template: ${template.name}\n`));
|
|
console.log(`ID: ${template.id}`);
|
|
console.log(`Category: ${template.category}`);
|
|
console.log(`Description: ${template.description}`);
|
|
console.log(`Event: ${template.event}`);
|
|
if (template.matcher) {
|
|
console.log(`Matcher: ${template.matcher}`);
|
|
}
|
|
console.log(`Blocking: ${template.blocking ? 'yes' : 'no'}`);
|
|
console.log(`Timeout: ${template.timeout || 30000}ms`);
|
|
console.log();
|
|
console.log(chalk.bold('Command:'));
|
|
console.log(` ${template.command}`);
|
|
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
function formatCategory(category: string): string {
|
|
return category.charAt(0).toUpperCase() + category.slice(1);
|
|
}
|