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:
99
skills-engine/manifest.ts
Normal file
99
skills-engine/manifest.ts
Normal file
@@ -0,0 +1,99 @@
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
import { parse } from 'yaml';
|
||||
|
||||
import { SKILLS_SCHEMA_VERSION } from './constants.js';
|
||||
import { getAppliedSkills, readState, compareSemver } from './state.js';
|
||||
import { SkillManifest } from './types.js';
|
||||
|
||||
export function readManifest(skillDir: string): SkillManifest {
|
||||
const manifestPath = path.join(skillDir, 'manifest.yaml');
|
||||
if (!fs.existsSync(manifestPath)) {
|
||||
throw new Error(`Manifest not found: ${manifestPath}`);
|
||||
}
|
||||
|
||||
const content = fs.readFileSync(manifestPath, 'utf-8');
|
||||
const manifest = parse(content) as SkillManifest;
|
||||
|
||||
// Validate required fields
|
||||
const required = [
|
||||
'skill',
|
||||
'version',
|
||||
'core_version',
|
||||
'adds',
|
||||
'modifies',
|
||||
] as const;
|
||||
for (const field of required) {
|
||||
if (manifest[field] === undefined) {
|
||||
throw new Error(`Manifest missing required field: ${field}`);
|
||||
}
|
||||
}
|
||||
|
||||
// Defaults
|
||||
manifest.conflicts = manifest.conflicts || [];
|
||||
manifest.depends = manifest.depends || [];
|
||||
manifest.file_ops = manifest.file_ops || [];
|
||||
|
||||
// Validate paths don't escape project root
|
||||
const allPaths = [...manifest.adds, ...manifest.modifies];
|
||||
for (const p of allPaths) {
|
||||
if (p.includes('..') || path.isAbsolute(p)) {
|
||||
throw new Error(`Invalid path in manifest: ${p} (must be relative without "..")`);
|
||||
}
|
||||
}
|
||||
|
||||
return manifest;
|
||||
}
|
||||
|
||||
export function checkCoreVersion(manifest: SkillManifest): {
|
||||
ok: boolean;
|
||||
warning?: string;
|
||||
} {
|
||||
const state = readState();
|
||||
const cmp = compareSemver(manifest.core_version, state.core_version);
|
||||
if (cmp > 0) {
|
||||
return {
|
||||
ok: true,
|
||||
warning: `Skill targets core ${manifest.core_version} but current core is ${state.core_version}. The merge might still work but there's a compatibility risk.`,
|
||||
};
|
||||
}
|
||||
return { ok: true };
|
||||
}
|
||||
|
||||
export function checkDependencies(manifest: SkillManifest): {
|
||||
ok: boolean;
|
||||
missing: string[];
|
||||
} {
|
||||
const applied = getAppliedSkills();
|
||||
const appliedNames = new Set(applied.map((s) => s.name));
|
||||
const missing = manifest.depends.filter((dep) => !appliedNames.has(dep));
|
||||
return { ok: missing.length === 0, missing };
|
||||
}
|
||||
|
||||
export function checkSystemVersion(manifest: SkillManifest): {
|
||||
ok: boolean;
|
||||
error?: string;
|
||||
} {
|
||||
if (!manifest.min_skills_system_version) {
|
||||
return { ok: true };
|
||||
}
|
||||
const cmp = compareSemver(manifest.min_skills_system_version, SKILLS_SCHEMA_VERSION);
|
||||
if (cmp > 0) {
|
||||
return {
|
||||
ok: false,
|
||||
error: `Skill requires skills system version ${manifest.min_skills_system_version} but current is ${SKILLS_SCHEMA_VERSION}. Update your skills engine.`,
|
||||
};
|
||||
}
|
||||
return { ok: true };
|
||||
}
|
||||
|
||||
export function checkConflicts(manifest: SkillManifest): {
|
||||
ok: boolean;
|
||||
conflicting: string[];
|
||||
} {
|
||||
const applied = getAppliedSkills();
|
||||
const appliedNames = new Set(applied.map((s) => s.name));
|
||||
const conflicting = manifest.conflicts.filter((c) => appliedNames.has(c));
|
||||
return { ok: conflicting.length === 0, conflicting };
|
||||
}
|
||||
Reference in New Issue
Block a user