@@ -48,7 +48,7 @@ import { Shell } from "@/shell/shell"
4848import { AppFileSystem } from "@/filesystem"
4949import { Truncate } from "@/tool/truncate"
5050import { decodeDataUrl } from "@/util/data-url"
51- import { runHooks , type HookEnv } from "../hook"
51+ import { runHooks , safeToolInput , type HookEnv } from "../hook"
5252import { Config } from "../config/config"
5353import { Process } from "@/util/process"
5454import { Cause , Effect , Exit , Layer , Option , Scope , ServiceMap } from "effect"
@@ -467,7 +467,7 @@ NOTE: At any point in time through this workflow you should feel free to ask the
467467 const hookEnv : HookEnv = {
468468 OPENCODE_HOOK_EVENT : "PreToolUse" ,
469469 OPENCODE_TOOL_NAME : item . id ,
470- OPENCODE_TOOL_INPUT : JSON . stringify ( args ) ,
470+ OPENCODE_TOOL_INPUT : safeToolInput ( args ) ,
471471 OPENCODE_PROJECT_DIR : Instance . directory ,
472472 OPENCODE_SESSION_ID : ctx . sessionID ,
473473 }
@@ -504,13 +504,21 @@ NOTE: At any point in time through this workflow you should feel free to ask the
504504 )
505505
506506 // PostToolUse hooks
507- yield * Effect . promise ( ( ) =>
507+ const postHookResult = yield * Effect . promise ( ( ) =>
508508 runHooks ( hookCfg . hooks ?. PostToolUse , item . id , {
509509 ...hookEnv ,
510510 OPENCODE_HOOK_EVENT : "PostToolUse" ,
511- } ) ,
511+ } ) . catch ( ( ) : { action : "pass" } => ( { action : "pass" } ) ) ,
512512 )
513513
514+ if ( postHookResult . action === "block" ) {
515+ return {
516+ title : "Blocked by post-execution hook" ,
517+ output : postHookResult . message ?? "Tool output suppressed by hook" ,
518+ metadata : { } as any ,
519+ }
520+ }
521+
514522 return output
515523 } ) ,
516524 )
@@ -535,7 +543,7 @@ NOTE: At any point in time through this workflow you should feel free to ask the
535543 const mcpHookEnv : HookEnv = {
536544 OPENCODE_HOOK_EVENT : "PreToolUse" ,
537545 OPENCODE_TOOL_NAME : key ,
538- OPENCODE_TOOL_INPUT : JSON . stringify ( args ) ,
546+ OPENCODE_TOOL_INPUT : safeToolInput ( args ) ,
539547 OPENCODE_PROJECT_DIR : Instance . directory ,
540548 OPENCODE_SESSION_ID : ctx . sessionID ,
541549 }
@@ -569,13 +577,19 @@ NOTE: At any point in time through this workflow you should feel free to ask the
569577 )
570578
571579 // PostToolUse hooks
572- yield * Effect . promise ( ( ) =>
580+ const mcpPostResult = yield * Effect . promise ( ( ) =>
573581 runHooks ( mcpHookCfg . hooks ?. PostToolUse , key , {
574582 ...mcpHookEnv ,
575583 OPENCODE_HOOK_EVENT : "PostToolUse" ,
576- } ) ,
584+ } ) . catch ( ( ) : { action : "pass" } => ( { action : "pass" } ) ) ,
577585 )
578586
587+ if ( mcpPostResult . action === "block" ) {
588+ return {
589+ content : [ { type : "text" as const , text : mcpPostResult . message ?? "Tool output suppressed by hook" } ] ,
590+ }
591+ }
592+
579593 const textParts : string [ ] = [ ]
580594 const attachments : Omit < MessageV2 . FilePart , "id" | "sessionID" | "messageID" > [ ] = [ ]
581595 for ( const contentItem of result . content ) {
0 commit comments