@@ -31,6 +31,8 @@ import { resolveGatewayMessageChannel } from "../utils/message-channel.js";
3131import { resolveAgentConfig } from "./agent-scope.js" ;
3232import { wrapToolWithAbortSignal } from "./agent-tools.abort.js" ;
3333import {
34+ isToolWrappedWithBeforeToolCallHook ,
35+ rewrapToolWithBeforeToolCallHook ,
3436 type ToolOutcomeObserver ,
3537 wrapToolWithBeforeToolCallHook ,
3638} from "./agent-tools.before-tool-call.js" ;
@@ -1173,28 +1175,28 @@ export function createOpenClawCodingTools(options?: {
11731175 } ) ,
11741176 ) ;
11751177 options ?. recordToolPrepStage ?.( "schema-normalization" ) ;
1178+ const hookContext = {
1179+ agentId,
1180+ ...( options ?. config ? { config : options . config } : { } ) ,
1181+ cwd : codingRoot ,
1182+ workspaceDir : workspaceRoot ,
1183+ ...( options ?. skillsSnapshot ? { skillsSnapshot : options . skillsSnapshot } : { } ) ,
1184+ ...( sandboxRoot && allowWorkspaceWrites
1185+ ? { sandbox : { root : sandboxRoot , bridge : sandboxFsBridge ! } }
1186+ : { } ) ,
1187+ sessionKey : options ?. sessionKey ,
1188+ sessionId : options ?. sessionId ,
1189+ runId : options ?. runId ,
1190+ channelId : options ?. hookChannelId ?? options ?. currentChannelId ,
1191+ ...( options ?. trace ? { trace : options . trace } : { } ) ,
1192+ loopDetection : resolveToolLoopDetectionConfig ( { cfg : options ?. config , agentId } ) ,
1193+ onToolOutcome : options ?. onToolOutcome ,
1194+ } ;
1195+ const hookOptions = { emitDiagnostics : options ?. emitBeforeToolCallDiagnostics } ;
11761196 const withHooks = normalized . map ( ( tool ) =>
1177- wrapToolWithBeforeToolCallHook (
1178- tool ,
1179- {
1180- agentId,
1181- ...( options ?. config ? { config : options . config } : { } ) ,
1182- cwd : codingRoot ,
1183- workspaceDir : workspaceRoot ,
1184- ...( options ?. skillsSnapshot ? { skillsSnapshot : options . skillsSnapshot } : { } ) ,
1185- ...( sandboxRoot && allowWorkspaceWrites
1186- ? { sandbox : { root : sandboxRoot , bridge : sandboxFsBridge ! } }
1187- : { } ) ,
1188- sessionKey : options ?. sessionKey ,
1189- sessionId : options ?. sessionId ,
1190- runId : options ?. runId ,
1191- channelId : options ?. hookChannelId ?? options ?. currentChannelId ,
1192- ...( options ?. trace ? { trace : options . trace } : { } ) ,
1193- loopDetection : resolveToolLoopDetectionConfig ( { cfg : options ?. config , agentId } ) ,
1194- onToolOutcome : options ?. onToolOutcome ,
1195- } ,
1196- { emitDiagnostics : options ?. emitBeforeToolCallDiagnostics } ,
1197- ) ,
1197+ isToolWrappedWithBeforeToolCallHook ( tool )
1198+ ? rewrapToolWithBeforeToolCallHook ( tool , hookContext , hookOptions )
1199+ : wrapToolWithBeforeToolCallHook ( tool , hookContext , hookOptions ) ,
11981200 ) ;
11991201 options ?. recordToolPrepStage ?.( "tool-hooks" ) ;
12001202 const withAbort = options ?. abortSignal
0 commit comments