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

103
skills-engine/init.ts Normal file
View File

@@ -0,0 +1,103 @@
import { execSync } from 'child_process';
import fs from 'fs';
import path from 'path';
import { BACKUP_DIR, BASE_DIR, NANOCLAW_DIR } from './constants.js';
import { isGitRepo } from './merge.js';
import { writeState } from './state.js';
import { SkillState } from './types.js';
// Top-level paths to include in base snapshot
const BASE_INCLUDES = ['src/', 'package.json', '.env.example', 'container/'];
// Directories/files to always exclude from base snapshot
const BASE_EXCLUDES = [
'node_modules',
'.nanoclaw',
'.git',
'dist',
'data',
'groups',
'store',
'logs',
];
export function initNanoclawDir(): void {
const projectRoot = process.cwd();
const nanoclawDir = path.join(projectRoot, NANOCLAW_DIR);
const baseDir = path.join(projectRoot, BASE_DIR);
// Create structure
fs.mkdirSync(path.join(projectRoot, BACKUP_DIR), { recursive: true });
// Clean existing base
if (fs.existsSync(baseDir)) {
fs.rmSync(baseDir, { recursive: true, force: true });
}
fs.mkdirSync(baseDir, { recursive: true });
// Snapshot all included paths
for (const include of BASE_INCLUDES) {
const srcPath = path.join(projectRoot, include);
if (!fs.existsSync(srcPath)) continue;
const destPath = path.join(baseDir, include);
const stat = fs.statSync(srcPath);
if (stat.isDirectory()) {
copyDirFiltered(srcPath, destPath, BASE_EXCLUDES);
} else {
fs.mkdirSync(path.dirname(destPath), { recursive: true });
fs.copyFileSync(srcPath, destPath);
}
}
// Create initial state
const coreVersion = getCoreVersion(projectRoot);
const initialState: SkillState = {
skills_system_version: '0.1.0',
core_version: coreVersion,
applied_skills: [],
};
writeState(initialState);
// Enable git rerere if in a git repo
if (isGitRepo()) {
try {
execSync('git config --local rerere.enabled true', { stdio: 'pipe' });
} catch {
// Non-fatal
}
}
}
function copyDirFiltered(
src: string,
dest: string,
excludes: string[],
): void {
fs.mkdirSync(dest, { recursive: true });
for (const entry of fs.readdirSync(src, { withFileTypes: true })) {
if (excludes.includes(entry.name)) continue;
const srcPath = path.join(src, entry.name);
const destPath = path.join(dest, entry.name);
if (entry.isDirectory()) {
copyDirFiltered(srcPath, destPath, excludes);
} else {
fs.copyFileSync(srcPath, destPath);
}
}
}
function getCoreVersion(projectRoot: string): string {
try {
const pkgPath = path.join(projectRoot, 'package.json');
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
return pkg.version || '0.0.0';
} catch {
return '0.0.0';
}
}