fix(hooks): support 'ask' decision for BeforeTool hooks (#21146)

This commit is contained in:
Christian Gunderman
2026-03-21 03:52:39 +00:00
committed by GitHub
parent d3766875f8
commit d1dc4902fd
32 changed files with 1016 additions and 117 deletions
+9 -2
View File
@@ -125,6 +125,7 @@ export class HookAggregator {
const additionalContexts: string[] = [];
let hasBlockDecision = false;
let hasAskDecision = false;
let hasContinueFalse = false;
for (const output of outputs) {
@@ -142,6 +143,12 @@ export class HookAggregator {
if (tempOutput.isBlockingDecision()) {
hasBlockDecision = true;
merged.decision = output.decision;
} else if (tempOutput.isAskDecision()) {
hasAskDecision = true;
// Ask decision is only set if no blocking decision was found so far
if (!hasBlockDecision) {
merged.decision = output.decision;
}
}
// Collect messages
@@ -180,8 +187,8 @@ export class HookAggregator {
this.extractAdditionalContext(output, additionalContexts);
}
// Set final decision if no blocking decision was found
if (!hasBlockDecision && !hasContinueFalse) {
// Set final decision if no blocking or ask decision was found
if (!hasBlockDecision && !hasAskDecision && !hasContinueFalse) {
merged.decision = 'allow';
}
+8 -1
View File
@@ -197,12 +197,19 @@ export class DefaultHookOutput implements HookOutput {
}
/**
* Check if this output represents a blocking decision
* Check if this output represents a blocking decision (block or deny)
*/
isBlockingDecision(): boolean {
return this.decision === 'block' || this.decision === 'deny';
}
/**
* Check if this output represents an 'ask' decision
*/
isAskDecision(): boolean {
return this.decision === 'ask';
}
/**
* Check if this output requests to stop execution
*/