* 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>
145 lines
3.8 KiB
TypeScript
145 lines
3.8 KiB
TypeScript
#!/usr/bin/env npx tsx
|
|
|
|
import { execSync } from 'child_process';
|
|
import fs from 'fs';
|
|
import os from 'os';
|
|
import path from 'path';
|
|
|
|
import { generateMatrix, MatrixEntry } from './generate-ci-matrix.js';
|
|
|
|
interface TestResult {
|
|
entry: MatrixEntry;
|
|
passed: boolean;
|
|
error?: string;
|
|
}
|
|
|
|
function copyDirRecursive(src: string, dest: string, exclude: string[] = []): void {
|
|
fs.mkdirSync(dest, { recursive: true });
|
|
for (const entry of fs.readdirSync(src, { withFileTypes: true })) {
|
|
if (exclude.includes(entry.name)) continue;
|
|
const srcPath = path.join(src, entry.name);
|
|
const destPath = path.join(dest, entry.name);
|
|
if (entry.isDirectory()) {
|
|
copyDirRecursive(srcPath, destPath, exclude);
|
|
} else {
|
|
fs.copyFileSync(srcPath, destPath);
|
|
}
|
|
}
|
|
}
|
|
|
|
async function runMatrixEntry(
|
|
projectRoot: string,
|
|
entry: MatrixEntry,
|
|
): Promise<TestResult> {
|
|
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'nanoclaw-ci-'));
|
|
|
|
try {
|
|
// Copy project to temp dir (exclude heavy/irrelevant dirs)
|
|
copyDirRecursive(projectRoot, tmpDir, [
|
|
'node_modules',
|
|
'.git',
|
|
'dist',
|
|
'data',
|
|
'store',
|
|
'logs',
|
|
'.nanoclaw',
|
|
]);
|
|
|
|
// Install dependencies
|
|
execSync('npm install --ignore-scripts', {
|
|
cwd: tmpDir,
|
|
stdio: 'pipe',
|
|
timeout: 120_000,
|
|
});
|
|
|
|
// Initialize nanoclaw dir
|
|
execSync('npx tsx -e "import { initNanoclawDir } from \'./skills-engine/index.js\'; initNanoclawDir();"', {
|
|
cwd: tmpDir,
|
|
stdio: 'pipe',
|
|
timeout: 30_000,
|
|
});
|
|
|
|
// Apply each skill in sequence
|
|
for (const skillName of entry.skills) {
|
|
const skillDir = path.join(tmpDir, '.claude', 'skills', skillName);
|
|
if (!fs.existsSync(skillDir)) {
|
|
return {
|
|
entry,
|
|
passed: false,
|
|
error: `Skill directory not found: ${skillName}`,
|
|
};
|
|
}
|
|
|
|
const result = execSync(
|
|
`npx tsx scripts/apply-skill.ts "${skillDir}"`,
|
|
{ cwd: tmpDir, stdio: 'pipe', timeout: 120_000 },
|
|
);
|
|
const parsed = JSON.parse(result.toString());
|
|
if (!parsed.success) {
|
|
return {
|
|
entry,
|
|
passed: false,
|
|
error: `Failed to apply skill ${skillName}: ${parsed.error}`,
|
|
};
|
|
}
|
|
}
|
|
|
|
// Run all skill tests
|
|
execSync('npx vitest run --config vitest.skills.config.ts', {
|
|
cwd: tmpDir,
|
|
stdio: 'pipe',
|
|
timeout: 300_000,
|
|
});
|
|
|
|
return { entry, passed: true };
|
|
} catch (err: any) {
|
|
return {
|
|
entry,
|
|
passed: false,
|
|
error: err.message || String(err),
|
|
};
|
|
} finally {
|
|
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
}
|
|
}
|
|
|
|
// --- Main ---
|
|
async function main(): Promise<void> {
|
|
const projectRoot = process.cwd();
|
|
const skillsDir = path.join(projectRoot, '.claude', 'skills');
|
|
const matrix = generateMatrix(skillsDir);
|
|
|
|
if (matrix.length === 0) {
|
|
console.log('No overlapping skills found. Nothing to test.');
|
|
process.exit(0);
|
|
}
|
|
|
|
console.log(`Found ${matrix.length} overlapping skill combination(s):\n`);
|
|
for (const entry of matrix) {
|
|
console.log(` [${entry.skills.join(', ')}] — ${entry.reason}`);
|
|
}
|
|
console.log('');
|
|
|
|
const results: TestResult[] = [];
|
|
for (const entry of matrix) {
|
|
console.log(`Testing: [${entry.skills.join(', ')}]...`);
|
|
const result = await runMatrixEntry(projectRoot, entry);
|
|
results.push(result);
|
|
console.log(` ${result.passed ? 'PASS' : 'FAIL'}${result.error ? ` — ${result.error}` : ''}`);
|
|
}
|
|
|
|
console.log('\n--- Summary ---');
|
|
const passed = results.filter((r) => r.passed).length;
|
|
const failed = results.filter((r) => !r.passed).length;
|
|
console.log(`${passed} passed, ${failed} failed out of ${results.length} combination(s)`);
|
|
|
|
if (failed > 0) {
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
main().catch((err) => {
|
|
console.error('Fatal error:', err);
|
|
process.exit(1);
|
|
});
|