Files
ECC/scripts/lib/install-targets/claude-project.js
T
haelyra dbfd6ab009 fix: protect commands-only CommonJS runtime in Claude installs
Reuse the existing scripts boundary asset and guard for commands-core without hooks. Preflight selected helper scopes and preserve user module metadata, unowned/edited JS interpretation, and boundary ownership through uninstall. Actual installed ESM help/JSON, receipt, reinstall/uninstall and 34 focused cases pass. OpenCode boundary 8/8, adapters 51/51, manifests 43/43; focused coverage exceeds 80%. Two root-owned legacy ESM core-profile fixtures require correction; no unsupported states weakened.
2026-10-11 03:04:04 -04:00

126 lines
3.9 KiB
JavaScript

const path = require('path');
const {
createInstallTargetAdapter,
createRemappedOperation,
isForeignPlatformPath,
normalizeRelativePath,
planClaudeHooksOperations,
} = require('./helpers');
const CLAUDE_ECC_NAMESPACE = 'ecc';
const CLAUDE_PROJECT_COMMONJS_PACKAGE = 'manifests/install-assets/claude-project-scripts-package.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)];
});
if (module.id !== 'hooks-runtime') {
return moduleOperations;
}
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' }
)),
...moduleOperations,
];
});
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' }
)];
},
});