Skills engine v0.1 + multi-channel infrastructure (#307)

* refactor: multi-channel infrastructure with explicit channel/is_group tracking

- Add channels[] array and findChannel() routing in index.ts, replacing
  hardcoded whatsapp.* calls with channel-agnostic callbacks
- Add channel TEXT and is_group INTEGER columns to chats table with
  COALESCE upsert to protect existing values from null overwrites
- is_group defaults to 0 (safe: unknown chats excluded from groups)
- WhatsApp passes explicit channel='whatsapp' and isGroup to onChatMetadata
- getAvailableGroups filters on is_group instead of JID pattern matching
- findChannel logs warnings instead of silently dropping unroutable JIDs
- Migration backfills channel/is_group from JID patterns for existing DBs

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* feat: skills engine v0.1 — deterministic skill packages with rerere resolution

Three-way merge engine for applying skill packages on top of a core
codebase. Skills declare which files they add/modify, and the engine
uses git merge-file for conflict detection with git rerere for
automatic resolution of previously-seen conflicts.

Key components:
- apply: three-way merge with backup/rollback safety net
- replay: clean-slate replay for uninstall and rebase
- update: core version updates with deletion detection
- rebase: bake applied skills into base (one-way)
- manifest: validation with path traversal protection
- resolution-cache: pre-computed rerere resolutions
- structured: npm deps, env vars, docker-compose merging
- CI: per-skill test matrix with conflict detection

151 unit tests covering merge, rerere, backup, replay, uninstall,
update, rebase, structured ops, and edge cases.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* feat: add Discord and Telegram skill packages

Skill packages for adding Discord and Telegram channels to NanoClaw.
Each package includes:
- Channel implementation (add/src/channels/)
- Three-way merge targets for index.ts, config.ts, routing.test.ts
- Intent docs explaining merge invariants
- Standalone integration tests
- manifest.yaml with dependency/conflict declarations

Applied via: npx tsx scripts/apply-skill.ts .claude/skills/add-discord
These are inert until applied — no runtime impact.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* remove unused docs (skills-system-status, implementation-guide)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
gavrielc
2026-02-19 01:55:00 +02:00
committed by GitHub
parent a689f8b3fa
commit 51788de3b9
83 changed files with 13159 additions and 626 deletions

View File

@@ -0,0 +1,99 @@
import { execSync } from 'child_process';
import fs from 'fs';
import os from 'os';
import path from 'path';
import { stringify } from 'yaml';
export function createTempDir(): string {
return fs.mkdtempSync(path.join(os.tmpdir(), 'nanoclaw-test-'));
}
export function setupNanoclawDir(tmpDir: string): void {
fs.mkdirSync(path.join(tmpDir, '.nanoclaw', 'base', 'src'), { recursive: true });
fs.mkdirSync(path.join(tmpDir, '.nanoclaw', 'backup'), { recursive: true });
}
export function writeState(tmpDir: string, state: any): void {
const statePath = path.join(tmpDir, '.nanoclaw', 'state.yaml');
fs.writeFileSync(statePath, stringify(state), 'utf-8');
}
export function createMinimalState(tmpDir: string): void {
writeState(tmpDir, {
skills_system_version: '0.1.0',
core_version: '1.0.0',
applied_skills: [],
});
}
export function createSkillPackage(tmpDir: string, opts: {
skill?: string;
version?: string;
core_version?: string;
adds?: string[];
modifies?: string[];
addFiles?: Record<string, string>;
modifyFiles?: Record<string, string>;
conflicts?: string[];
depends?: string[];
test?: string;
structured?: any;
file_ops?: any[];
post_apply?: string[];
min_skills_system_version?: string;
dirName?: string;
}): string {
const skillDir = path.join(tmpDir, opts.dirName ?? 'skill-pkg');
fs.mkdirSync(skillDir, { recursive: true });
const manifest: Record<string, unknown> = {
skill: opts.skill ?? 'test-skill',
version: opts.version ?? '1.0.0',
description: 'Test skill',
core_version: opts.core_version ?? '1.0.0',
adds: opts.adds ?? [],
modifies: opts.modifies ?? [],
conflicts: opts.conflicts ?? [],
depends: opts.depends ?? [],
test: opts.test,
structured: opts.structured,
file_ops: opts.file_ops,
};
if (opts.post_apply) manifest.post_apply = opts.post_apply;
if (opts.min_skills_system_version) manifest.min_skills_system_version = opts.min_skills_system_version;
fs.writeFileSync(path.join(skillDir, 'manifest.yaml'), stringify(manifest));
if (opts.addFiles) {
const addDir = path.join(skillDir, 'add');
for (const [relPath, content] of Object.entries(opts.addFiles)) {
const fullPath = path.join(addDir, relPath);
fs.mkdirSync(path.dirname(fullPath), { recursive: true });
fs.writeFileSync(fullPath, content);
}
}
if (opts.modifyFiles) {
const modDir = path.join(skillDir, 'modify');
for (const [relPath, content] of Object.entries(opts.modifyFiles)) {
const fullPath = path.join(modDir, relPath);
fs.mkdirSync(path.dirname(fullPath), { recursive: true });
fs.writeFileSync(fullPath, content);
}
}
return skillDir;
}
export function initGitRepo(dir: string): void {
execSync('git init', { cwd: dir, stdio: 'pipe' });
execSync('git config user.email "test@test.com"', { cwd: dir, stdio: 'pipe' });
execSync('git config user.name "Test"', { cwd: dir, stdio: 'pipe' });
execSync('git config rerere.enabled true', { cwd: dir, stdio: 'pipe' });
fs.writeFileSync(path.join(dir, '.gitignore'), 'node_modules\n');
execSync('git add -A && git commit -m "init"', { cwd: dir, stdio: 'pipe' });
}
export function cleanup(dir: string): void {
fs.rmSync(dir, { recursive: true, force: true });
}