fix(install): harden Claude settings lifecycle

This commit is contained in:
wellkilo
2026-09-07 01:57:04 +08:00
parent 26d3e0038b
commit f59cfd57c2
19 changed files with 540 additions and 350 deletions
+41
View File
@@ -1,6 +1,10 @@
const fs = require('fs');
const os = require('os');
const path = require('path');
const {
CLAUDE_HOOKS_CONFIG_PATH,
getClaudeSettingsPath,
} = require('../install/claude-settings');
const PLATFORM_SOURCE_PATH_OWNERS = Object.freeze({
'.claude-plugin': 'claude',
@@ -146,6 +150,42 @@ function createRemappedOperation(adapter, moduleId, sourceRelativePath, destinat
});
}
function planClaudeHooksOperations(adapter, module, input) {
const operations = [
createRemappedOperation(
adapter,
module.id,
CLAUDE_HOOKS_CONFIG_PATH,
getClaudeSettingsPath(adapter.resolveRoot(input)),
{
kind: 'update-claude-settings',
strategy: 'merge-hook-ids',
}
),
];
if (!input.repoRoot) {
return operations;
}
const sourceHooksRoot = path.join(input.repoRoot, 'hooks');
if (!fs.existsSync(sourceHooksRoot)) {
return operations;
}
return [
...operations,
...fs.readdirSync(sourceHooksRoot, { withFileTypes: true })
.filter(entry => entry.name !== 'hooks.json')
.sort((left, right) => left.name.localeCompare(right.name))
.map(entry => adapter.createScaffoldOperation(
module.id,
path.join('hooks', entry.name),
input
)),
];
}
function createNamespacedFlatRuleOperations(adapter, moduleId, sourceRelativePath, input = {}) {
const normalizedSourcePath = normalizeRelativePath(sourceRelativePath);
const sourceRoot = path.join(input.repoRoot || '', normalizedSourcePath);
@@ -373,4 +413,5 @@ module.exports = {
createRemappedOperation,
isForeignPlatformPath,
normalizeRelativePath,
planClaudeHooksOperations,
};