Files
makeCAD/scripts/sync-cad-ai-skills.mjs
likang 678058c940
CI / Select checks (push) Has been cancelled
CI / Format and repository checks (push) Has been cancelled
CI / Compile RISC-V (manual) (push) Has been cancelled
Docker / image (push) Has been cancelled
Generated files / Regenerate and commit (push) Has been cancelled
Kernel rig / Select the rig areas (push) Has been cancelled
Lists / Design format changes merge cleanly (push) Has been cancelled
Lists / Lists are sorted one item per line (push) Has been cancelled
Packaging lint / lint (push) Has been cancelled
Pages / build (push) Has been cancelled
CI / Dependency advisories (push) Has been cancelled
CI / Quick compile (push) Has been cancelled
CI / Native Linux Clippy (push) Has been cancelled
CI / Build tests (push) Has been cancelled
CI / Native Linux tests (push) Has been cancelled
CI / GPU path tests (1/4) (push) Has been cancelled
CI / GPU path tests (2/4) (push) Has been cancelled
CI / GPU path tests (3/4) (push) Has been cancelled
CI / GPU path tests (4/4) (push) Has been cancelled
CI / Action matrix (1/16) (push) Has been cancelled
CI / Action matrix (10/16) (push) Has been cancelled
CI / Action matrix (11/16) (push) Has been cancelled
CI / Action matrix (12/16) (push) Has been cancelled
CI / Action matrix (13/16) (push) Has been cancelled
CI / Action matrix (14/16) (push) Has been cancelled
CI / Action matrix (15/16) (push) Has been cancelled
CI / Action matrix (16/16) (push) Has been cancelled
CI / Action matrix (2/16) (push) Has been cancelled
CI / Action matrix (3/16) (push) Has been cancelled
CI / Action matrix (4/16) (push) Has been cancelled
CI / Action matrix (5/16) (push) Has been cancelled
CI / Action matrix (6/16) (push) Has been cancelled
CI / Action matrix (7/16) (push) Has been cancelled
CI / Action matrix (8/16) (push) Has been cancelled
CI / Action matrix (9/16) (push) Has been cancelled
CI / Action matrix determinism (push) Has been cancelled
CI / Property tests (many cases) (push) Has been cancelled
CI / Doc tests (push) Has been cancelled
CI / Reference tests (push) Has been cancelled
CI / Windows D3D12 FXC shaders (push) Has been cancelled
CI / Windows app startup (push) Has been cancelled
CI / ci (push) Has been cancelled
CI / Compile WebAssembly (push) Has been cancelled
CI / Nightly alert (push) Has been cancelled
Kernel rig / Build the CLI (push) Has been cancelled
Kernel rig / Kernel rig (${{ matrix.shard }}) (push) Has been cancelled
Kernel rig / kernel-rig (push) Has been cancelled
Pages / deploy (push) Has been cancelled
优化skill
2026-11-16 11:32:34 +08:00

43 lines
2.8 KiB
JavaScript

#!/usr/bin/env node
// One source for native MCP, desktop, WASM and the packaged Java model gateway.
import { createHash } from 'node:crypto';
import { readFileSync, readdirSync, lstatSync, writeFileSync, mkdirSync } from 'node:fs';
import { resolve, dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
const root = resolve(dirname(fileURLToPath(import.meta.url)), '..');
const args = process.argv.slice(2);
if (args.some((arg) => arg.startsWith('--') && arg !== '--check')) throw new Error('Unknown option. Usage: node scripts/sync-cad-ai-skills.mjs [--check] <community-root>');
const check = args.includes('--check');
const paths = args.filter((arg) => arg !== '--check');
if (paths.length !== 1) throw new Error('Usage: node scripts/sync-cad-ai-skills.mjs [--check] <community-root>');
const communityRoot = resolve(paths[0]);
if (!readFileSync(join(communityRoot, 'pom.xml'), 'utf8').includes('<artifactId>vibemake</artifactId>')) throw new Error('Target must be the community Maven project root');
const skillsRoot = join(root, 'skills');
const walk = (folder, prefix = '') => readdirSync(folder).sort().flatMap((name) => {
const path = join(folder, name), relative = prefix + name, stat = lstatSync(path);
if (stat.isSymbolicLink()) throw new Error(`Skill resource is a symlink: ${relative}`);
return stat.isDirectory() ? walk(path, relative + '/') : [[relative, readFileSync(path, 'utf8')]];
});
const skills = readdirSync(skillsRoot).sort().filter((name) => lstatSync(join(skillsRoot, name)).isDirectory()).map((name) => {
const files = Object.fromEntries(walk(join(skillsRoot, name)));
const entry = files['SKILL.md'];
if (!entry) throw new Error(`Missing SKILL.md: ${name}`);
const declared = entry.match(/^name:\s*(.+)$/m)?.[1];
const description = entry.match(/^description:\s*(.+)$/m)?.[1].replace(/^"|"$/g, '');
if (declared !== name || !description || !/^makecad-[a-z-]+$/.test(name)) throw new Error(`Invalid skill metadata: ${name}`);
if (Object.values(files).some((text) => text.includes('Solid' + 'Craft'))) throw new Error(`Legacy display name in ${name}`);
return { name, description, files };
});
const source = { formatVersion: 1, workflow: readFileSync(join(skillsRoot, 'agent-workflow.md'), 'utf8'), skills };
const revision = createHash('sha256').update(JSON.stringify(source)).digest('hex');
const bundle = JSON.stringify({ ...source, revision }, null, 2) + '\n';
const target = resolve(communityRoot, 'vibemake-service/src/main/resources/cad/ai/skills.json');
if (check) {
if (readFileSync(target, 'utf8') !== bundle) throw new Error('Packaged skills differ from the MCP/desktop source. Run the sync command before building.');
} else {
mkdirSync(dirname(target), { recursive: true });
writeFileSync(target, bundle);
}
console.log(`${check ? 'Verified' : 'Synchronized'} ${skills.length} skills, revision ${revision}`);