Files
ECC/scripts/skills-health.js
huangpz6andTRAE 0c2a542d20 fix(skills-health): make the one-off checkout fallback explicit (#3865)
commands-core copies scripts/lib into the Claude config root, so it does not repair a marketplace plugin installation. Lead with a direct dashboard run from a full checkout and keep commands-core as the non-marketplace reinstall path.

Co-Authored-By: TRAE <noreply@trae.ai>
2026-11-04 21:54:03 +08:00

152 lines
4.3 KiB
JavaScript

#!/usr/bin/env node
'use strict';
let collectSkillHealth;
let formatHealthReport;
let renderDashboard;
try {
({ collectSkillHealth, formatHealthReport } = require('./lib/skill-evolution/health'));
({ renderDashboard } = require('./lib/skill-evolution/dashboard'));
} catch (error) {
// The Claude Code plugin marketplace clones the repo but does not run
// npm/install-apply, so scripts/lib can be missing from a managed install.
// Fail with the remedy instead of a bare module-resolution stack (#3259).
const missing = (String(error && error.message).match(/Cannot find module '([^']+)'/) || [])[1];
if (error && error.code === 'MODULE_NOT_FOUND' && missing && /skill-evolution/.test(error.message)) {
console.error(
`skills-health could not load ${missing}; this installation is missing part of scripts/lib/skill-evolution.\n` +
'For a one-off report, run from a full ECC checkout: node scripts/skills-health.js --dashboard. ' +
'For a non-marketplace install, select commands-core: node scripts/install-apply.js --target <host> --modules commands-core.'
);
process.exit(1);
}
throw error;
}
function showHelp() {
console.log(`
Usage: node scripts/skills-health.js [options]
Options:
--json Emit machine-readable JSON
--skills-root <path> Override curated skills root
--learned-root <path> Override learned skills root
--imported-root <path> Override imported skills root
--home <path> Override home directory for learned/imported skill roots
--runs-file <path> Override skill run JSONL path
--now <timestamp> Override current time for deterministic reports
--dashboard Show rich health dashboard with charts
--panel <name> Show only a specific panel (success-rate, failures, amendments, versions)
--warn-threshold <n> Decline sensitivity threshold (default: 0.1)
--help Show this help text
`);
}
function requireValue(argv, index, argName) {
const value = argv[index + 1];
if (!value || value.startsWith('--')) {
throw new Error(`Missing value for ${argName}`);
}
return value;
}
function parseArgs(argv) {
const options = {};
for (let index = 0; index < argv.length; index += 1) {
const arg = argv[index];
if (arg === '--json') {
options.json = true;
continue;
}
if (arg === '--help' || arg === '-h') {
options.help = true;
continue;
}
if (arg === '--skills-root') {
options.skillsRoot = requireValue(argv, index, '--skills-root');
index += 1;
continue;
}
if (arg === '--learned-root') {
options.learnedRoot = requireValue(argv, index, '--learned-root');
index += 1;
continue;
}
if (arg === '--imported-root') {
options.importedRoot = requireValue(argv, index, '--imported-root');
index += 1;
continue;
}
if (arg === '--home') {
options.homeDir = requireValue(argv, index, '--home');
index += 1;
continue;
}
if (arg === '--runs-file') {
options.runsFilePath = requireValue(argv, index, '--runs-file');
index += 1;
continue;
}
if (arg === '--now') {
options.now = requireValue(argv, index, '--now');
index += 1;
continue;
}
if (arg === '--warn-threshold') {
options.warnThreshold = Number(requireValue(argv, index, '--warn-threshold'));
index += 1;
continue;
}
if (arg === '--dashboard') {
options.dashboard = true;
continue;
}
if (arg === '--panel') {
options.panel = requireValue(argv, index, '--panel');
index += 1;
continue;
}
throw new Error(`Unknown argument: ${arg}`);
}
return options;
}
function main() {
try {
const options = parseArgs(process.argv.slice(2));
if (options.help) {
showHelp();
process.exit(0);
}
if (options.dashboard || options.panel) {
const result = renderDashboard(options);
process.stdout.write(options.json ? `${JSON.stringify(result.data, null, 2)}\n` : result.text);
} else {
const report = collectSkillHealth(options);
process.stdout.write(formatHealthReport(report, { json: options.json }));
}
} catch (error) {
process.stderr.write(`Error: ${error.message}\n`);
process.exit(1);
}
}
main();