mirror of
https://github.com/affaan-m/ECC.git
synced 2026-11-17 13:32:18 +00:00
fix: adapt Grok hooks for Windows tool execution
This commit is contained in:
1 parent
79bbe939df
commit
d12137e1b7
5 files changed
+103
-8
No files matched your search
@@ -10,11 +10,10 @@ const {
|
||||
normalizeRelativePath,
|
||||
} = require('./helpers');
|
||||
|
||||
function grokHookBoundaryTransform() {
|
||||
function grokHookTransform() {
|
||||
return {
|
||||
type: 'text-replace',
|
||||
search: 'var e=process.env.CLAUDE_PLUGIN_ROOT;',
|
||||
replace: 'var e=process.env.GROK_PLUGIN_ROOT||process.env.CLAUDE_PLUGIN_ROOT;',
|
||||
type: 'grok-hooks',
|
||||
...(process.platform === 'win32' ? { nodeExecutable: process.execPath } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -91,7 +90,7 @@ module.exports = createInstallTargetAdapter({
|
||||
...operation,
|
||||
destinationPath: path.join(adapter.resolveRoot(input), 'plugins', 'ecc', sourceRelativePath),
|
||||
...(normalizeRelativePath(sourceRelativePath) === 'hooks/hooks.json'
|
||||
? { contentTransform: grokHookBoundaryTransform() }
|
||||
? { contentTransform: grokHookTransform() }
|
||||
: {}),
|
||||
};
|
||||
});
|
||||
@@ -103,7 +102,7 @@ module.exports = createInstallTargetAdapter({
|
||||
operations.push({
|
||||
...adapter.createScaffoldOperation('hooks-runtime', 'hooks/hooks.json', input),
|
||||
destinationPath: hooksManifestPath,
|
||||
contentTransform: grokHookBoundaryTransform(),
|
||||
contentTransform: grokHookTransform(),
|
||||
});
|
||||
}
|
||||
operations.push({
|
||||
|
||||
@@ -90,6 +90,44 @@ function transformJsonFilterObjectKeys(contract, content, sourceRelativePath) {
|
||||
return formatJson(replaceObjectAtPath(parsed, contract.path, filtered));
|
||||
}
|
||||
|
||||
function transformGrokHooks(contract, content, sourceRelativePath) {
|
||||
const config = parseTransformObject(content, sourceRelativePath);
|
||||
if (!config.hooks || typeof config.hooks !== 'object' || Array.isArray(config.hooks)) {
|
||||
throw new Error(`Invalid Grok hooks config: ${sourceRelativePath}`);
|
||||
}
|
||||
const nodeExecutable = typeof contract.nodeExecutable === 'string' && contract.nodeExecutable
|
||||
? `"${contract.nodeExecutable}"`
|
||||
: null;
|
||||
const matcherMap = { Bash: 'run_terminal_command', PowerShell: 'run_terminal_command' };
|
||||
const mapMatcherName = (name) => Object.hasOwn(matcherMap, name) ? matcherMap[name] : name;
|
||||
const mapMatcher = (matcher) => {
|
||||
if (Array.isArray(matcher)) return [...new Set(matcher.map(mapMatcherName))];
|
||||
if (typeof matcher !== 'string') return matcher;
|
||||
if (/^[\w-]+(?:\|[\w-]+)*$/.test(matcher)) {
|
||||
return [...new Set(matcher.split('|').map(mapMatcherName))].join('|');
|
||||
}
|
||||
return matcher.replace(/\b(Bash|PowerShell)\b/g, (name) => mapMatcherName(name));
|
||||
};
|
||||
const hooks = Object.fromEntries(Object.entries(config.hooks).map(([event, entries]) => [
|
||||
event,
|
||||
Array.isArray(entries) ? entries.map((entry) => {
|
||||
const matcher = mapMatcher(entry.matcher);
|
||||
return {
|
||||
...entry,
|
||||
...(matcher === undefined ? {} : { matcher }),
|
||||
hooks: Array.isArray(entry.hooks) ? entry.hooks.map((hook) => {
|
||||
if (hook.type !== 'command' || typeof hook.command !== 'string') return hook;
|
||||
const command = hook.command
|
||||
.replaceAll('var e=process.env.CLAUDE_PLUGIN_ROOT;', 'var e=process.env.GROK_PLUGIN_ROOT||process.env.CLAUDE_PLUGIN_ROOT;')
|
||||
.replace(/^node(?=\s)/, nodeExecutable || 'node');
|
||||
return { ...hook, command };
|
||||
}) : entry.hooks,
|
||||
};
|
||||
}) : entries,
|
||||
]));
|
||||
return formatJson({ ...config, hooks });
|
||||
}
|
||||
|
||||
function transformByContract(contract, content, sourceRelativePath) {
|
||||
if (!contract || typeof contract !== 'object' || Array.isArray(contract)) {
|
||||
throw new Error('Invalid install content transform contract');
|
||||
@@ -98,6 +136,7 @@ function transformByContract(contract, content, sourceRelativePath) {
|
||||
'text-replace': transformTextReplace,
|
||||
'json-set': transformJsonSet,
|
||||
'json-filter-object-keys': transformJsonFilterObjectKeys,
|
||||
'grok-hooks': transformGrokHooks,
|
||||
};
|
||||
const handler = handlers[contract.type];
|
||||
if (!handler) throw new Error(`Unknown install content transform contract: ${contract.type}`);
|
||||
|
||||
Reference in new issue
Block a user