Skip to content

Commit 384605c

Browse files
authored
Clean up optional checks on hookProgress (#3741)
1 parent f925ea8 commit 384605c

File tree

5 files changed

+12
-12
lines changed

5 files changed

+12
-12
lines changed

src/extension/chat/vscode-node/chatHookService.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ export class ChatHookService implements IChatHookService {
303303
// Exit code 2 (error) means deny the tool
304304
onError: (errorMessage) => {
305305
const messageWithTool = errorMessage ? `Tried to use ${toolName} - ${errorMessage}` : `Tried to use ${toolName}`;
306-
outputStream?.hookProgress?.('PreToolUse', formatHookErrorMessage(messageWithTool));
306+
outputStream?.hookProgress('PreToolUse', formatHookErrorMessage(messageWithTool));
307307
mostRestrictiveDecision = 'deny';
308308
winningReason = messageWithTool || winningReason;
309309
},
@@ -402,10 +402,10 @@ export class ChatHookService implements IChatHookService {
402402
hasBlock = true;
403403
const messageWithTool = errorMessage ? `Tried to use ${toolName} - ${errorMessage}` : `Tried to use ${toolName}`;
404404
blockReason = messageWithTool || undefined;
405-
outputStream?.hookProgress?.('PostToolUse', formatHookErrorMessage(messageWithTool));
405+
outputStream?.hookProgress('PostToolUse', formatHookErrorMessage(messageWithTool));
406406
} else {
407407
const messageWithTool = errorMessage ? `Tried to use ${toolName} - ${errorMessage}` : `Tried to use ${toolName}`;
408-
outputStream?.hookProgress?.('PostToolUse', undefined, formatHookErrorMessage(messageWithTool));
408+
outputStream?.hookProgress('PostToolUse', undefined, formatHookErrorMessage(messageWithTool));
409409
}
410410
},
411411
});

src/extension/codeBlocks/node/codeBlockProcessor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ export class CodeBlockTrackingChatResponseStream implements ChatResponseStream {
125125
workspaceEdit = this.forward(this._wrapped.workspaceEdit?.bind(this._wrapped) || (() => { }));
126126
confirmation = this.forward(this._wrapped.confirmation.bind(this._wrapped));
127127
warning = this.forward(this._wrapped.warning.bind(this._wrapped));
128-
hookProgress = this.forward(this._wrapped.hookProgress?.bind(this._wrapped) ?? (() => { }));
128+
hookProgress = this.forward(this._wrapped.hookProgress.bind(this._wrapped));
129129
reference2 = this.forward(this._wrapped.reference2.bind(this._wrapped));
130130
codeCitation = this.forward(this._wrapped.codeCitation.bind(this._wrapped));
131131
anchor = this.forward(this._wrapped.anchor.bind(this._wrapped));

src/extension/intents/node/hookResultProcessor.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export function processHookResults(options: ProcessHookResultsOptions): void {
8787
continue;
8888
}
8989
logService.info(`[ToolCallingLoop] ${hookType} hook requested abort: ${result.stopReason}`);
90-
outputStream?.hookProgress?.(hookType, formatHookErrorMessage(result.stopReason));
90+
outputStream?.hookProgress(hookType, formatHookErrorMessage(result.stopReason));
9191
throw new HookAbortError(hookType, result.stopReason);
9292
}
9393

@@ -117,14 +117,14 @@ export function processHookResults(options: ProcessHookResultsOptions): void {
117117
// Completely ignore error - no throw, no hookProgress (silently continue)
118118
continue;
119119
} else {
120-
outputStream?.hookProgress?.(hookType, formatHookErrorMessage(errorMessage));
120+
outputStream?.hookProgress(hookType, formatHookErrorMessage(errorMessage));
121121
throw new HookAbortError(hookType, errorMessage);
122122
}
123123
}
124124
}
125125

126126
// Show aggregated warnings via hookProgress
127-
if (warnings.length > 0 && outputStream?.hookProgress) {
127+
if (warnings.length > 0 && outputStream) {
128128
if (warnings.length === 1) {
129129
outputStream.hookProgress(hookType, undefined, warnings[0]);
130130
} else {

src/extension/intents/node/toolCallingLoop.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -312,10 +312,10 @@ export abstract class ToolCallingLoop<TOptions extends IToolCallingLoopOptions =
312312
protected showStopHookBlockedMessage(outputStream: ChatResponseStream | undefined, reasons: readonly string[]): void {
313313
if (outputStream) {
314314
if (reasons.length === 1) {
315-
outputStream.hookProgress?.('Stop', reasons[0]);
315+
outputStream.hookProgress('Stop', reasons[0]);
316316
} else {
317317
const formattedReasons = reasons.map((r, i) => `${i + 1}. ${r}`).join('\n');
318-
outputStream.hookProgress?.('Stop', formattedReasons);
318+
outputStream.hookProgress('Stop', formattedReasons);
319319
}
320320
}
321321
this._logService.trace(`[ToolCallingLoop] Stop hook blocked stopping: ${reasons.join('; ')}`);
@@ -465,10 +465,10 @@ export abstract class ToolCallingLoop<TOptions extends IToolCallingLoopOptions =
465465
protected showSubagentStopHookBlockedMessage(outputStream: ChatResponseStream | undefined, reasons: readonly string[]): void {
466466
if (outputStream) {
467467
if (reasons.length === 1) {
468-
outputStream.hookProgress?.('SubagentStop', reasons[0]);
468+
outputStream.hookProgress('SubagentStop', reasons[0]);
469469
} else {
470470
const formattedReasons = reasons.map((r, i) => `${i + 1}. ${r}`).join('\n');
471-
outputStream.hookProgress?.('SubagentStop', formattedReasons);
471+
outputStream.hookProgress('SubagentStop', formattedReasons);
472472
}
473473
}
474474
this._logService.trace(`[ToolCallingLoop] SubagentStop hook blocked stopping: ${reasons.join('; ')}`);

src/extension/linkify/common/responseStreamWithLinkification.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export class ResponseStreamWithLinkification implements FinalizableChatResponseS
7878
}
7979

8080
hookProgress(hookType: ChatHookType, stopReason?: string, systemMessage?: string): ChatResponseStream {
81-
this.enqueue(() => this._progress.hookProgress?.(hookType, stopReason, systemMessage), false);
81+
this.enqueue(() => this._progress.hookProgress(hookType, stopReason, systemMessage), false);
8282
return this;
8383
}
8484

0 commit comments

Comments
 (0)