mirror of
https://github.com/affaan-m/everything-claude-code.git
synced 2026-06-11 02:33:10 +08:00
fix: surface warn-only PreToolUse hooks (#2084)
This commit is contained in:
41
scripts/hooks/pretooluse-visible-output.js
Normal file
41
scripts/hooks/pretooluse-visible-output.js
Normal file
@@ -0,0 +1,41 @@
|
||||
#!/usr/bin/env node
|
||||
'use strict';
|
||||
|
||||
function normalizeAdditionalContext(value) {
|
||||
if (Array.isArray(value)) {
|
||||
return value
|
||||
.map(item => String(item || '').trim())
|
||||
.filter(Boolean)
|
||||
.join('\n');
|
||||
}
|
||||
|
||||
return String(value || '').trim();
|
||||
}
|
||||
|
||||
function combineAdditionalContext(current, next) {
|
||||
const currentText = normalizeAdditionalContext(current);
|
||||
const nextText = normalizeAdditionalContext(next);
|
||||
|
||||
if (!currentText) return nextText;
|
||||
if (!nextText) return currentText;
|
||||
|
||||
return `${currentText}\n${nextText}`;
|
||||
}
|
||||
|
||||
function buildPreToolUseAdditionalContext(value) {
|
||||
const additionalContext = normalizeAdditionalContext(value);
|
||||
if (!additionalContext) return '';
|
||||
|
||||
return JSON.stringify({
|
||||
hookSpecificOutput: {
|
||||
hookEventName: 'PreToolUse',
|
||||
additionalContext,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
buildPreToolUseAdditionalContext,
|
||||
combineAdditionalContext,
|
||||
normalizeAdditionalContext,
|
||||
};
|
||||
Reference in New Issue
Block a user