Files
ECC/scripts/lib/install-targets/claude-project.js
T
YuhaoLin2005 95bf86c348 Add config-health monitor and install wiring
- Add the config-health skill: a read-only monitor for hook wiring, rule references, and rule staleness; every mode exits 0.
- Ship its own SessionStart hook asset so installing the module registers the monitor; keep PreToolUse opt-in.
- Keep one install-state record per hook source, so hooks-runtime and config-health can share settings.json and uninstall removes both.
- Split the monitor into a CLI entry plus constants, paths, and scan modules; split scan_command and the hook contract suite. All files are under 800 lines and no function body reaches 50 lines.
2026-11-02 22:53:30 +08:00

144 lines
4.8 KiB
JavaScript

const path = require('path');
const {
createInstallTargetAdapter,
createRemappedOperation,
isForeignPlatformPath,
normalizeRelativePath,
planClaudeHooksOperations,
} = require('./helpers');
const { getClaudeSettingsPath } = require('../install/claude-settings');
const CLAUDE_ECC_NAMESPACE = 'ecc';
const CLAUDE_PROJECT_COMMONJS_PACKAGE = 'manifests/install-assets/claude-project-scripts-package.json';
// config-health ships its own SessionStart hook; see claude-home.js for why
// this is not part of hooks/hooks.json.
const CONFIG_HEALTH_HOOKS_CONFIG_PATH = 'manifests/install-assets/config-health-hooks.json';
function getClaudeManagedDestinationPath(adapter, sourceRelativePath, input) {
const normalizedSourcePath = normalizeRelativePath(sourceRelativePath);
const targetRoot = adapter.resolveRoot(input);
if (normalizedSourcePath === 'rules') {
return path.join(targetRoot, 'rules', CLAUDE_ECC_NAMESPACE);
}
if (normalizedSourcePath.startsWith('rules/')) {
return path.join(
targetRoot,
'rules',
CLAUDE_ECC_NAMESPACE,
normalizedSourcePath.slice('rules/'.length)
);
}
if (normalizedSourcePath === 'skills') {
return path.join(targetRoot, 'skills');
}
if (normalizedSourcePath.startsWith('skills/')) {
return path.join(
targetRoot,
'skills',
normalizedSourcePath.slice('skills/'.length)
);
}
if (normalizedSourcePath === 'docs' || normalizedSourcePath.startsWith('docs/')) {
return path.join(targetRoot, normalizedSourcePath);
}
return null;
}
module.exports = createInstallTargetAdapter({
id: 'claude-project',
target: 'claude-project',
kind: 'project',
rootSegments: ['.claude'],
installStatePathSegments: ['ecc', 'install-state.json'],
nativeRootRelativePath: '.claude-plugin',
planOperations(input, adapter) {
const modules = Array.isArray(input.modules)
? input.modules
: (input.module ? [input.module] : []);
const planningInput = {
repoRoot: input.repoRoot,
projectRoot: input.projectRoot,
homeDir: input.homeDir,
};
const operations = modules.flatMap(module => {
const paths = Array.isArray(module.paths) ? module.paths : [];
const moduleOperations = paths
.filter(p => !isForeignPlatformPath(p, 'claude'))
.flatMap(sourceRelativePath => {
if (
module.id === 'hooks-runtime'
&& normalizeRelativePath(sourceRelativePath) === 'hooks'
) {
return planClaudeHooksOperations(adapter, module, planningInput);
}
const managedDestinationPath = getClaudeManagedDestinationPath(
adapter,
sourceRelativePath,
planningInput
);
if (managedDestinationPath) {
return [createRemappedOperation(
adapter,
module.id,
sourceRelativePath,
managedDestinationPath,
{ strategy: 'preserve-relative-path' }
)];
}
return [adapter.createScaffoldOperation(module.id, sourceRelativePath, planningInput)];
});
// The skill promises a SessionStart hook by default. Copying the skill
// and the script is not that promise: without this settings merge the
// installed monitor is never invoked by an ordinary session. PreToolUse
// stays opt-in and is deliberately absent from this config.
const withModuleHooks = module.id === 'config-health'
? [...moduleOperations, createRemappedOperation(
adapter,
module.id,
CONFIG_HEALTH_HOOKS_CONFIG_PATH,
getClaudeSettingsPath(adapter.resolveRoot(planningInput)),
{ kind: 'update-claude-settings', strategy: 'merge-hook-ids' }
)]
: moduleOperations;
if (module.id !== 'hooks-runtime') {
return withModuleHooks;
}
return [
...['hooks', 'lib'].map(directory => createRemappedOperation(
adapter,
module.id,
CLAUDE_PROJECT_COMMONJS_PACKAGE,
path.join(adapter.resolveRoot(planningInput), 'scripts', directory, 'package.json'),
{ strategy: 'preserve-relative-path' }
)),
...withModuleHooks,
];
});
if (!operations.some(operation => operation.moduleId === 'commands-core'
&& normalizeRelativePath(operation.sourceRelativePath).startsWith('scripts/'))) return operations;
// Standalone command entries and their helpers need the same scope even
// when hooks are excluded. Reuse the shared boundary asset and owner.
return [...operations, createRemappedOperation(
adapter,
'commands-core',
'manifests/install-assets/commonjs-scripts-package.json',
path.join(adapter.resolveRoot(planningInput), 'scripts', 'package.json'),
{ strategy: 'preserve-relative-path' }
)];
},
});