MCPcopy Create free account
hub / github.com/ChinaSiro/claude-code-sourcemap / p88

Function p88

package/cli.js:7724–7725  ·  view source on GitHub ↗
(q)

Source from the content-addressed store, hash-verified

7722`);n({stdout:J6,stderr:c,output:K6,status:l,aborted:Y.aborted})})})});try{if(M)c8("info","hook_spawn_started",{hook_event_name:K,index:A});await Promise.race([o,s]);let n=await Promise.race([e,a,s]);return await $6,P=n.status,W=n.aborted??!1,n}catch(n){let l=s1(n);if(P=1,l==="EPIPE"){N("EPIPE error while writing to hook stdin (hook command likely closed early)");let A6="Hook command closed stdin before hook input was fully written (EPIPE)";return{stdout:"",stderr:A6,output:A6,status:1}}else if(l==="ABORT_ERR")return W=!0,{stdout:"",stderr:"Hook cancelled",output:"Hook cancelled",status:1,aborted:!0};else{let J6=`Error occurred while executing hook command: ${d6(n)}`;return{stdout:"",stderr:J6,output:J6,status:1}}}finally{if(M)c8("info","hook_spawn_completed",{hook_event_name:K,index:A,duration_ms:Date.now()-X,exit_code:P,aborted:W});if(j6(),!g)C.cleanup()}}function lhY(q,K){if(!K||K==="*")return!0;if(/^[a-zA-Z0-9_|]+$/.test(K)){if(K.includes("|"))return K.split("|").map((z)=>Zf(z.trim())).includes(q);return q===Zf(K)}try{let _=new RegExp(K);if(_.test(q))return!0;for(let z of $S7(q))if(_.test(z))return!0;return!1}catch{return N(`Invalid regex pattern in hook matcher: ${K}`),!1}}async function nhY(q,K){if(q.hook_event_name!=="PreToolUse"&&q.hook_event_name!=="PostToolUse"&&q.hook_event_name!=="PostToolUseFailure"&&q.hook_event_name!=="PermissionRequest")return;let _=Zf(q.tool_name),z=K&&L5(K,q.tool_name),Y=z?.inputSchema.safeParse(q.tool_input),$=Y?.success&&z?.preparePermissionMatcher?await z.preparePermissionMatcher(Y.data):void 0;return(A)=>{let O=G2(A);if(Zf(O.toolName)!==_)return!1;if(!O.ruleContent)return!0;return $?$(O.ruleContent):!1}}function NgK(q){return q.hook.type==="callback"&&q.hook.internal===!0}function RQ8(q,K){return`${q.pluginRoot??q.skillRoot??""}\x00${K}`}function ygK(q){let K=q.filter((z)=>z.pluginId);if(K.length===0)return;let _={};for(let z of K){let Y=z.pluginId.lastIndexOf("@"),A=Y>0&&_I.has(z.pluginId.slice(Y+1))?z.pluginId:"third-party";_[A]=(_[A]||0)+1}return _}function EgK(q){let K={};for(let _ of q)K[_.hook.type]=(K[_.hook.type]||0)+1;return K}function ihY(q,K,_){let z=[...bQ()?.[_]??[]],Y=fb(),$=sR()?.[_];if($)for(let A of $){if(Y&&"pluginRoot"in A)continue;z.push(A)}if(!Y&&q!==void 0){let A=HL8(q,K,_).get(_);if(A)for(let w of A)z.push(w);let O=Gb4(q,K,_).get(_);if(O)for(let w of O)z.push(w)}return z}function iS6(q,K,_){let z=bQ()?.[q];if(z&&z.length>0)return!0;let Y=sR()?.[q];if(Y&&Y.length>0)return!0;if(K?.sessionHooks.get(_)?.hooks[q])return!0;return!1}async function O_7(q,K,_,z,Y){try{let $=ihY(q,K,_),A=void 0;switch(z.hook_event_name){case"PreToolUse":case"PostToolUse":case"PostToolUseFailure":case"PermissionRequest":case"PermissionDenied":A=z.tool_name;break;case"SessionStart":A=z.source;break;case"Setup":A=z.trigger;break;case"PreCompact":case"PostCompact":A=z.trigger;break;case"Notification":A=z.notification_type;break;case"SessionEnd":A=z.reason;break;case"StopFailure":A=z.error;break;case"SubagentStart":A=z.agent_type;break;case"SubagentStop":A=z.agent_type;break;case"TeammateIdle":case"TaskCreated":case"TaskCompleted":break;case"Elicitation":A=z.mcp_server_name;break;case"ElicitationResult":A=z.mcp_server_name;break;case"ConfigChange":A=z.source;break;case"InstructionsLoaded":A=z.load_reason;break;case"FileChanged":A=dhY(z.file_path);break;default:break}N(`Getting matching hook commands for ${_} with query: ${A}`,{level:"verbose"}),N(`Found ${$.length} hook matchers in settings`,{level:"verbose"});let w=(A?$.filter((v)=>!v.matcher||lhY(A,v.matcher)):$).flatMap((v)=>{let V="pluginRoot"in v?v.pluginRoot:void 0,E="pluginId"in v?v.pluginId:void 0,S="skillRoot"in v?v.skillRoot:void 0,R=V?"pluginName"in v?`plugin:${v.pluginName}`:"plugin":S?"skillName"in v?`skill:${v.skillName}`:"skill":"settings";return v.hooks.map((x)=>({hook:x,pluginRoot:V,pluginId:E,skillRoot:S,hookSource:R}))});if(w.every((v)=>v.hook.type==="callback"||v.hook.type==="function"))return w;let j=(v)=>v.if??"",H=Array.from(new Map(w.filter((v)=>v.hook.type==="command").map((v)=>[RQ8(v,`${v.hook.shell??zD6}\x00${v.hook.command}\x00${j(v.hook)}`),v])).values()),J=Array.from(new Map(w.filter((v)=>v.hook.type==="prompt").map((v)=>[RQ8(v,`${v.hook.prompt}\x00${j(v.hook)}`),v])).values()),M=Array.from(new Map(w.filter((v)=>v.hook.type==="agent").map((v)=>[RQ8(v,`${v.hook.prompt}\x00${j(v.hook)}`),v])).values()),X=Array.from(new Map(w.filter((v)=>v.hook.type==="http").map((v)=>[RQ8(v,`${v.hook.url}\x00${j(v.hook)}`),v])).values()),P=w.filter((v)=>v.hook.type==="callback"),W=w.filter((v)=>v.hook.type==="function"),D=[...H,...J,...M,...X,...P,...W],G=D.some((v)=>(v.hook.type==="command"||v.hook.type==="prompt"||v.hook.type==="agent"||v.hook.type==="http")&&v.hook.if)?await nhY(z,Y):void 0,Z=D.filter((v)=>{if(v.hook.type!=="command"&&v.hook.type!=="prompt"&&v.hook.type!=="agent"&&v.hook.type!=="http")return!0;let V=v.hook.if;if(!V)return!0;if(!G)return N(`Hook if condition "${V}" cannot be evaluated for non-tool event ${z.hook_event_name}`),!1;if(G(V))return!0;return N(`Skipping hook due to if condition "${V}" not matching`),!1}),T=_==="SessionStart"||_==="Setup"?Z.filter((v)=>{if(v.hook.type==="http")return N(`Skipping HTTP hook ${v.hook.url} — HTTP hooks are not supported for ${_}`),!1;return!0}):Z;return N(`Matched ${T.length} unique hooks for query "${A||"no match query"}" (${w.length} before deduplication)`,{level:"verbose"}),T}catch{return[]}}function z87(q,K){return`${q} hook error: ${K.blockingError}`}function G87(q){return`Stop hook feedback:
7723${q.blockingError}`}function T87(q){return`TeammateIdle hook feedback:
7724${q.blockingError}`}function Y67(q){return`TaskCreated hook feedback:
7725${q.blockingError}`}function p88(q){return`TaskCompleted hook feedback:
7726${q.blockingError}`}function w_7(q){return`UserPromptSubmit operation blocked by hook:
7727${q.blockingError}`}async function*GR({hookInput:q,toolUseID:K,matchQuery:_,signal:z,timeoutMs:Y=PO,toolUseContext:$,messages:A,forceSyncExecution:O,requestPrompt:w,toolInputSummary:j}){if(j68())return;if(i6(process.env.CLAUDE_CODE_SIMPLE))return;let H=q.hook_event_name,J=_?`${H}:${_}`:H,M=w?.(J,j);if(Qq8()){N(`Skipping ${J} hook execution - workspace trust not accepted`);return}let X=$?$.getAppState():void 0,P=$?.agentId??N8(),W=await O_7(X,P,H,q,$?.options?.tools);if(W.length===0)return;if(z?.aborted)return;let D=W.filter((x)=>!NgK(x));if(D.length>0){let x=ygK(D),I=EgK(D);d("tengu_run_hook",{hookName:J,numCommands:D.length,hookTypeCounts:g6(I),...x&&{pluginHookCounts:g6(x)}})}else{let x=Date.now(),I=$?{getAppState:$.getAppState,updateAttributionState:$.updateAttributionState}:void 0;for(let[p,{hook:C}]of W.entries())if(C.type==="callback")await C.callback(q,K,z,p,I);let B=Date.now()-x;d36()?.observe("hook_duration_ms",B),s58(B),d("tengu_repl_hook_finished",{hookName:J,numCommands:W.length,numSuccess:W.length,numBlocking:0,numNonBlockingError:0,numCancelled:0,totalDurationMs:B});return}let f=bH()?g6(TgK(W)):"[]";if(bH())EA("hook_execution_start",{hook_event:H,hook_name:J,num_hooks:String(W.length),managed_only:String(fb()),hook_definitions:f,hook_source:fb()?"policySettings":"merged"});let G=Fg4(H,J,W.length,f);for(let{hook:x}of W)yield{message:{type:"progress",data:{type:"hook_progress",hookEvent:H,hookName:J,command:pL(x),...x.type==="prompt"&&{promptText:x.prompt},..."statusMessage"in x&&x.statusMessage!=null&&{statusMessage:x.statusMessage}},parentToolUseID:K,toolUseID:K,timestamp:new Date().toISOString(),uuid:vy()}};let Z=Date.now(),T;function v(){if(T!==void 0)return T;try{return T={ok:!0,value:g6(q)}}catch(x){return H6(Error(`Failed to stringify hook ${J} input`,{cause:x})),T={ok:!1,error:x}}}let V=W.map(async function*({hook:x,pluginRoot:I,pluginId:B,skillRoot:p},C){if(x.type==="callback"){let q6=x.timeout?x.timeout*1000:Y,{signal:e,cleanup:i}=Ty(z,{timeoutMs:q6});yield ohY({toolUseID:K,hook:x,hookEvent:H,hookInput:q,signal:e,hookIndex:C,toolUseContext:$}).finally(i);return}if(x.type==="function"){if(!A){yield{message:V4({type:"hook_error_during_execution",hookName:J,toolUseID:K,hookEvent:H,content:"Messages not provided for function hook"}),outcome:"non_blocking_error",hook:x};return}yield rhY({hook:x,messages:A,hookName:J,toolUseID:K,hookEvent:H,timeoutMs:Y,signal:z});return}let g=x.timeout?x.timeout*1000:Y,{signal:F,cleanup:U}=Ty(z,{timeoutMs:g}),c=vy(),K6=Date.now(),t=pL(x);try{let q6=v();if(!q6.ok){yield{message:V4({type:"hook_error_during_execution",hookName:J,toolUseID:K,hookEvent:H,content:`Failed to prepare hook input: ${d6(q6.error)}`,command:t,durationMs:Date.now()-K6}),outcome:"non_blocking_error",hook:x},U();return}let e=q6.value;if(x.type==="prompt"){if(!$)throw Error("ToolUseContext is required for prompt hooks. This is a bug.");let w6=await AgK(x,J,H,e,F,$,A,K);if(w6.message?.type==="attachment"){let o=w6.message.attachment;if(o.type==="hook_success"||o.type==="hook_non_blocking_error")o.command=t,o.durationMs=Date.now()-K6}yield w6,U?.();return}if(x.type==="agent"){if(!$)throw Error("ToolUseContext is required for agent hooks. This is a bug.");if(!A)throw Error("Messages are required for agent hooks. This is a bug.");let w6=await jgK(x,J,H,e,F,$,K,A,"agent_type"in q?q.agent_type:void 0);if(w6.message?.type==="attachment"){let o=w6.message.attachment;if(o.type==="hook_success"||o.type==="hook_non_blocking_error")o.command=t,o.durationMs=Date.now()-K6}yield w6,U?.();return}if(x.type==="http"){M17(c,J,H);let w6=await $_7(x,H,e,z);if(U?.(),w6.aborted){i0({hookId:c,hookName:J,hookEvent:H,output:"Hook cancelled",stdout:"",stderr:"",exitCode:void 0,outcome:"cancelled"}),yield{message:V4({type:"hook_cancelled",hookName:J,toolUseID:K,hookEvent:H}),outcome:"cancelled",hook:x};return}if(w6.error||!w6.ok){let a=w6.error||`HTTP ${w6.statusCode} from ${x.url}`;i0({hookId:c,hookName:J,hookEvent:H,output:a,stdout:"",stderr:a,exitCode:w6.statusCode,outcome:"error"}),yield{message:V4({type:"hook_non_blocking_error",hookName:J,toolUseID:K,hookEvent:H,stderr:a,stdout:"",exitCode:w6.statusCode??0}),outcome:"non_blocking_error",hook:x};return}let{json:o,validationError:s}=VgK(w6.body);if(s){i0({hookId:c,hookName:J,hookEvent:H,output:w6.body,stdout:w6.body,stderr:`JSON validation failed: ${s}`,exitCode:w6.statusCode,outcome:"error"}),yield{message:V4({type:"hook_non_blocking_error",hookName:J,toolUseID:K,hookEvent:H,stderr:`JSON validation failed: ${s}`,stdout:w6.body,exitCode:w6.statusCode??0}),outcome:"non_blocking_error",hook:x};return}if(o&&rb(o)){i0({hookId:c,hookName:J,hookEvent:H,output:w6.body,stdout:w6.body,stderr:"",exitCode:w6.statusCode,outcome:"success"}),yield{outcome:"success",hook:x};return}if(o){let a=A_7({json:o,command:x.url,hookName:J,toolUseID:K,hookEvent:H,expectedHookEvent:H,stdout:w6.body,stderr:"",exitCode:w6.statusCode});i0({hookId:c,hookName:J,hookEvent:H,output:w6.body,stdout:w6.body,stderr:"",exitCode:w6.statusCode,outcome:"success"}),yield{...a,outcome:"success",hook:x};return}return}M17(c,J,H);let i=await hQ8(x,H,J,e,F,c,C,I,B,p,O,M);U?.();let $6=Date.now()-K6;if(i.backgrounded){yield{outcome:"success",hook:x};return}if(i.aborted){i0({hookId:c,hookName:J,hookEvent:H,output:i.output,stdout:i.stdout,stderr:i.stderr,exitCode:i.status,outcome:"cancelled"}),yield{message:V4({type:"hook_cancelled",hookName:J,toolUseID:K,hookEvent:H,command:t,durationMs:$6}),outcome:"cancelled",hook:x};return}let{json:M6,plainText:j6,validationError:G6}=kgK(i.stdout);if(G6){i0({hookId:c,hookName:J,hookEvent:H,output:i.output,stdout:i.stdout,stderr:`JSON validation failed: ${G6}`,exitCode:1,outcome:"error"}),yield{message:V4({type:"hook_non_blocking_error",hookName:J,toolUseID:K,hookEvent:H,stderr:`JSON validation failed: ${G6}`,stdout:i.stdout,exitCode:1,command:t,durationMs:$6}),outcome:"non_blocking_error",hook:x};return}if(M6){if(rb(M6)){yield{outcome:"success",hook:x};return}let w6=A_7({json:M6,command:t,hookName:J,toolUseID:K,hookEvent:H,expectedHookEvent:H,stdout:i.stdout,stderr:i.stderr,exitCode:i.status,durationMs:$6});if(Cd(M6)&&!M6.suppressOutput&&j6&&i.status===0){let o=`${$8.bold(J)} completed`;i0({hookId:c,hookName:J,hookEvent:H,output:i.output,stdout:i.stdout,stderr:i.stderr,exitCode:i.status,outcome:"success"}),yield{...w6,message:w6.message||V4({type:"hook_success",hookName:J,toolUseID:K,hookEvent:H,content:o,stdout:i.stdout,stderr:i.stderr,exitCode:i.status,command:t,durationMs:$6}),outcome:"success",hook:x};return}i0({hookId:c,hookName:J,hookEvent:H,output:i.output,stdout:i.stdout,stderr:i.stderr,exitCode:i.status,outcome:i.status===0?"success":"error"}),yield{...w6,outcome:"success",hook:x};return}if(i.status===0){i0({hookId:c,hookName:J,hookEvent:H,output:i.output,stdout:i.stdout,stderr:i.stderr,exitCode:i.status,outcome:"success"}),yield{message:V4({type:"hook_success",hookName:J,toolUseID:K,hookEvent:H,content:i.stdout.trim(),stdout:i.stdout,stderr:i.stderr,exitCode:i.status,command:t,durationMs:$6}),outcome:"success",hook:x};return}if(i.status===2){i0({hookId:c,hookName:J,hookEvent:H,output:i.output,stdout:i.stdout,stderr:i.stderr,exitCode:i.status,outcome:"error"}),yield{blockingError:{blockingError:`[${x.command}]: ${i.stderr||"No stderr output"}`,command:x.command},outcome:"blocking",hook:x};return}i0({hookId:c,hookName:J,hookEvent:H,output:i.output,stdout:i.stdout,stderr:i.stderr,exitCode:i.status,outcome:"error"}),yield{message:V4({type:"hook_non_blocking_error",hookName:J,toolUseID:K,hookEvent:H,stderr:`Failed with non-blocking status code: ${i.stderr.trim()||"No stderr output"}`,stdout:i.stdout,exitCode:i.status,command:t,durationMs:$6}),outcome:"non_blocking_error",hook:x};return}catch(q6){U?.();let e=q6 instanceof Error?q6.message:String(q6);i0({hookId:c,hookName:J,hookEvent:H,output:`Failed to run: ${e}`,stdout:"",stderr:`Failed to run: ${e}`,exitCode:1,outcome:"error"}),yield{message:V4({type:"hook_non_blocking_error",hookName:J,toolUseID:K,hookEvent:H,stderr:`Failed to run: ${e}`,stdout:"",exitCode:1,command:t,durationMs:Date.now()-K6}),outcome:"non_blocking_error",hook:x};return}}),E={success:0,blocking:0,non_blocking_error:0,cancelled:0},S;for await(let x of CN8(V)){if(E[x.outcome]++,x.preventContinuation)N(`Hook ${H} (${pL(x.hook)}) requested preventContinuation`),yield{preventContinuation:!0,stopReason:x.stopReason};if(x.blockingError)yield{blockingError:x.blockingError};if(x.message)yield{message:x.message};if(x.systemMessage)yield{message:V4({type:"hook_system_message",content:x.systemMessage,hookName:J,toolUseID:K,hookEvent:H})};if(x.additionalContext)N(`Hook ${H} (${pL(x.hook)}) provided additionalContext (${x.additionalContext.length} chars)`),yield{additionalContexts:[x.additionalContext]};if(x.initialUserMessage)N(`Hook ${H} (${pL(x.hook)}) provided initialUserMessage (${x.initialUserMessage.length} chars)`),yield{initialUserMessage:x.initialUserMessage};if(x.watchPaths&&x.watchPaths.length>0)N(`Hook ${H} (${pL(x.hook)}) provided ${x.watchPaths.length} watchPaths`),yield{watchPaths:x.watchPaths};if(x.updatedMCPToolOutput)N(`Hook ${H} (${pL(x.hook)}) replaced MCP tool output`),yield{updatedMCPToolOutput:x.updatedMCPToolOutput};if(x.permissionBehavior)switch(N(`Hook ${H} (${pL(x.hook)}) returned permissionDecision: ${x.permissionBehavior}${x.hookPermissionDecisionReason?` (reason: ${x.hookPermissionDecisionReason})`:""}`),x.permissionBehavior){case"deny":S="deny";break;case"ask":if(S!=="deny")S="ask";break;case"allow":if(!S)S="allow";break;case"passthrough":break}if(S!==void 0){let I=x.updatedInput&&(x.permissionBehavior==="allow"||x.permissionBehavior==="ask")?x.updatedInput:void 0;if(I)N(`Hook ${H} (${pL(x.hook)}) modified tool input keys: [${Object.keys(I).join(", ")}]`);yield{permissionBehavior:S,hookPermissionDecisionReason:x.hookPermissionDecisionReason,hookSource:W.find((B)=>B.hook===x.hook)?.hookSource,updatedInput:I}}if(x.updatedInput&&x.permissionBehavior===void 0)N(`Hook ${H} (${pL(x.hook)}) modified tool input keys: [${Object.keys(x.updatedInput).join(", ")}]`),yield{updatedInput:x.updatedInput};if(x.permissionRequestResult)yield{permissionRequestResult:x.permissionRequestResult};if(x.retry)yield{retry:x.retry};if(x.elicitationResponse)yield{elicitationResponse:x.elicitationResponse};if(x.elicitationResultResponse)yield{elicitationResultResponse:x.elicitationResultResponse};if(X&&x.hook.type!=="callback"){let I=N8(),p=Tb4(X,I,H,_??"",x.hook);if(p?.onHookSuccess&&x.outcome==="success")try{p.onHookSuccess(x.hook,x)}catch(C){H6(Error("Session hook success callback failed",{cause:C}))}}}let R=Date.now()-Z;if(d36()?.observe("hook_duration_ms",R),s58(R),d("tengu_repl_hook_finished",{hookName:J,numCommands:W.length,numSuccess:E.success,numBlocking:E.blocking,numNonBlockingError:E.non_blocking_error,numCancelled:E.cancelled,totalDurationMs:R}),bH()){let x=TgK(W);EA("hook_execution_complete",{hook_event:H,hook_name:J,num_hooks:String(W.length),num_success:String(E.success),num_blocking:String(E.blocking),num_non_blocking_error:String(E.non_blocking_error),num_cancelled:String(E.cancelled),managed_only:String(fb()),hook_definitions:g6(x),hook_source:fb()?"policySettings":"merged"})}Ug4(G,{numSuccess:E.success,numBlocking:E.blocking,numNonBlockingError:E.non_blocking_error,numCancelled:E.cancelled})}function eT6(q){return q.some((K)=>K.blocked)}async function ob({getAppState:q,hookInput:K,matchQuery:_,signal:z,timeoutMs:Y=PO}){if(i6(process.env.CLAUDE_CODE_SIMPLE))return[];let $=K.hook_event_name,A=_?`${$}:${_}`:$;if(j68())return N(`Skipping hooks for ${A} due to 'disableAllHooks' managed setting`),[];if(Qq8())return N(`Skipping ${A} hook execution - workspace trust not accepted`),[];let O=q?q():void 0,w=N8(),j=await O_7(O,w,$,K);if(j.length===0)return[];if(z?.aborted)return[];let H=j.filter((X)=>!NgK(X));if(H.length>0){let X=ygK(H),P=EgK(H);d("tengu_run_hook",{hookName:A,numCommands:H.length,hookTypeCounts:g6(P),...X&&{pluginHookCounts:g6(X)}})}let J;try{J=g6(K)}catch(X){return H6(X),[]}let M=j.map(async({hook:X,pluginRoot:P,pluginId:W},D)=>{if(X.type==="callback"){let T=X.timeout?X.timeout*1000:Y,{signal:v,cleanup:V}=Ty(z,{timeoutMs:T});try{let E=vy(),S=await X.callback(K,E,v,D);if(V?.(),rb(S))return N(`${A} [callback] returned async response, returning empty output`),{command:"callback",succeeded:!0,output:"",blocked:!1};let R=$==="WorktreeCreate"&&Cd(S)&&S.hookSpecificOutput?.hookEventName==="WorktreeCreate"?S.hookSpecificOutput.worktreePath:S.systemMessage||"",x=Cd(S)&&S.decision==="block";return N(`${A} [callback] completed successfully`),{command:"callback",succeeded:!0,output:R,blocked:x}}catch(E){V?.();let S=E instanceof Error?E.message:String(E);return N(`${A} [callback] failed to run: ${S}`,{level:"error"}),{command:"callback",succeeded:!1,output:S,blocked:!1}}}if(X.type==="prompt")return{command:X.prompt,succeeded:!1,output:"Prompt stop hooks are not yet supported outside REPL",blocked:!1};if(X.type==="agent")return{command:X.prompt,succeeded:!1,output:"Agent stop hooks are not yet supported outside REPL",blocked:!1};if(X.type==="function")return H6(Error(`Function hook reached executeHooksOutsideREPL for ${$}. Function hooks should only be used in REPL context (Stop hooks).`)),{command:"function",succeeded:!1,output:"Internal error: function hook executed outside REPL context",blocked:!1};if(X.type==="http")try{let T=await $_7(X,$,J,z);if(T.aborted)return N(`${A} [${X.url}] cancelled`),{command:X.url,succeeded:!1,output:"Hook cancelled",blocked:!1};if(T.error||!T.ok){let R=T.error||`HTTP ${T.statusCode} from ${X.url}`;return N(`${A} [${X.url}] failed: ${R}`,{level:"error"}),{command:X.url,succeeded:!1,output:R,blocked:!1}}let{json:v,validationError:V}=VgK(T.body);if(V)throw Error(V);if(v&&!rb(v))N(`Parsed JSON output from HTTP hook: ${g6(v)}`,{level:"verbose"});let E=v&&!rb(v)&&Cd(v)&&v.decision==="block",S=$==="WorktreeCreate"?v&&Cd(v)&&v.hookSpecificOutput?.hookEventName==="WorktreeCreate"?v.hookSpecificOutput.worktreePath:"":T.body;return{command:X.url,succeeded:!0,output:S,blocked:!!E}}catch(T){let v=T instanceof Error?T.message:String(T);return N(`${A} [${X.url}] failed to run: ${v}`,{level:"error"}),{command:X.url,succeeded:!1,output:v,blocked:!1}}let f=X.timeout?X.timeout*1000:Y,{signal:G,cleanup:Z}=Ty(z,{timeoutMs:f});try{let T=await hQ8(X,$,A,J,G,vy(),D,P,W);if(Z?.(),T.aborted)return N(`${A} [${X.command}] cancelled`),{command:X.command,succeeded:!1,output:"Hook cancelled",blocked:!1};N(`${A} [${X.command}] completed with status ${T.status}`);let{json:v,validationError:V}=kgK(T.stdout);if(V)throw Error(V);if(v&&!rb(v))N(`Parsed JSON output from hook: ${g6(v)}`,{level:"verbose"});let E=v&&!rb(v)&&Cd(v)&&v.decision==="block",S=T.status===2||!!E,R=T.status===0?T.stdout||"":T.stderr||"",x=v&&Cd(v)&&v.hookSpecificOutput&&"watchPaths"in v.hookSpecificOutput?v.hookSpecificOutput.watchPaths:void 0,I=v&&Cd(v)?v.systemMessage:void 0;return{command:X.command,succeeded:T.status===0,output:R,blocked:S,watchPaths:x,systemMessage:I}}catch(T){Z?.();let v=T instanceof Error?T.message:String(T);return N(`${A} [${X.command}] failed to run: ${v}`,{level:"error"}),{command:X.command,succeeded:!1,output:v,blocked:!1}}});return await Promise.all(M)}async function*Y87(q,K,_,z,Y,$,A=PO,O,w){let j=z.getAppState(),H=z.agentId??N8();if(!iS6("PreToolUse",j,H))return;N(`executePreToolHooks called for tool: ${q}`,{level:"verbose"});let J={...C$(Y,void 0,z),hook_event_name:"PreToolUse",tool_name:q,tool_input:_,tool_use_id:K};yield*GR({hookInput:J,toolUseID:K,matchQuery:q,signal:$,timeoutMs:A,toolUseContext:z,requestPrompt:O,toolInputSummary:w})}async function*$87(q,K,_,z,Y,$,A,O=PO){let w={...C$($,void 0,Y),hook_event_name:"PostToolUse",tool_name:q,tool_input:_,tool_response:z,tool_use_id:K};yield*GR({hookInput:w,toolUseID:K,matchQuery:q,signal:A,timeoutMs:O,toolUseContext:Y})}async function*A87(q,K,_,z,Y,$,A,O,w=PO){let j=Y.getAppState(),H=Y.agentId??N8();if(!iS6("PostToolUseFailure",j,H))return;let J={...C$(A,void 0,Y),hook_event_name:"PostToolUseFailure",tool_name:q,tool_input:_,tool_use_id:K,error:z,is_interrupt:$};yield*GR({hookInput:J,toolUseID:K,matchQuery:q,signal:O,timeoutMs:w,toolUseContext:Y})}async function*j87(q,K,_,z,Y,$,A,O=PO){let w=Y.getAppState(),j=Y.agentId??N8();if(!iS6("PermissionDenied",w,j))return;let H={...C$($,void 0,Y),hook_event_name:"PermissionDenied",tool_name:q,tool_input:_,tool_use_id:K,reason:z};yield*GR({hookInput:H,toolUseID:K,matchQuery:q,signal:A,timeoutMs:O,toolUseContext:Y})}async function bU(q,K=PO){let{message:_,title:z,notificationType:Y}=q,$={...C$(void 0),hook_event_name:"Notification",message:_,title:z,notification_type:Y};await ob({hookInput:$,timeoutMs:K,matchQuery:Y})}async function kp8(q,K,_=PO){let z=K?.getAppState(),Y=N8();if(!iS6("StopFailure",z,Y))return;let $=L3(q.message.content,`
7728`).trim()||void 0,A=q.error??"unknown",O={...C$(void 0,void 0,K),hook_event_name:"StopFailure",error:A,error_details:q.errorDetails,last_assistant_message:$};await ob({getAppState:K?.getAppState,hookInput:O,timeoutMs:_,matchQuery:A})}async function*v87(q,K,_=PO,z=!1,Y,$,A,O,w){let j=Y?"SubagentStop":"Stop",H=$?.getAppState(),J=$?.agentId??N8();if(!iS6(j,H,J))return;let M=A?uP(A):void 0,X=M?L3(M.message.content,`

Callers 2

callFunction · 0.85
vWKFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected