fix(skills-health): explain a missing scripts/lib instead of a module stack (#3259)

A managed plugin install can lack scripts/lib/skill-evolution, which made skills-health fail on the first require with Cannot find module. Catch that specific resolution failure and print the install-apply remedy; other errors still propagate.

Co-Authored-By: TRAE <noreply@trae.ai>
This commit is contained in:
huangpz6andTRAE committed 2026-11-04 11:21:21 +08:00
1 parent b38be6a7f6
commit f5b1867268
2 files changed
+71 -2

No files matched your search

+20 -2
View File
@@ -1,8 +1,26 @@
#!/usr/bin/env node
'use strict';
const { collectSkillHealth, formatHealthReport } = require('./lib/skill-evolution/health');
const { renderDashboard } = require('./lib/skill-evolution/dashboard');
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).
if (error && error.code === 'MODULE_NOT_FOUND' && /skill-evolution/.test(error.message)) {
console.error(
'skills-health requires scripts/lib/skill-evolution, which is missing from this installation.\n' +
'Reinstall ECC with the commands-core module (node scripts/install-apply.js --target <host>) ' +
'or run this script from a full checkout of the repository.'
);
process.exit(1);
}
throw error;
}
function showHelp() {
console.log(`
@@ -0,0 +1,51 @@
/**
* A managed install without scripts/lib must get the remedy, not a stack trace
* (#3259).
*/
const assert = require('assert');
const fs = require('fs');
const os = require('os');
const path = require('path');
const { spawnSync } = require('child_process');
const script = path.join(__dirname, '..', '..', 'scripts', 'skills-health.js');
function test(name, fn) {
try {
fn();
console.log(` ✓ ${name}`);
return true;
} catch (error) {
console.log(` ✗ ${name}`);
console.log(` Error: ${error.message}`);
return false;
}
}
let passed = 0;
let failed = 0;
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'ecc-health-missing-lib-'));
fs.mkdirSync(path.join(tmp, 'scripts'), { recursive: true });
fs.copyFileSync(script, path.join(tmp, 'scripts', 'skills-health.js'));
if (
test('missing scripts/lib prints the install remedy instead of a stack trace', () => {
const result = spawnSync('node', [path.join(tmp, 'scripts', 'skills-health.js')], {
encoding: 'utf8',
timeout: 15000
});
assert.strictEqual(result.status, 1);
assert.match(result.stderr, /missing from this installation/i);
assert.match(result.stderr, /install-apply\.js/);
assert.doesNotMatch(result.stderr, /Cannot find module/);
})
)
passed++;
else failed++;
fs.rmSync(tmp, { recursive: true, force: true });
console.log(`\n ${passed} passed, ${failed} failed\n`);
process.exit(failed > 0 ? 1 : 0);