@@ -90,16 +90,18 @@ impl AhpHookExecutor {
9090 /// Map A3S Code hook event to AHP event
9191 fn map_event ( & self , event : & HookEvent ) -> Option < AhpEvent > {
9292 let ( event_type, payload) = match event {
93- HookEvent :: PreToolUse ( e) => {
94- ( EventType :: PreAction , serde_json:: json!( {
93+ HookEvent :: PreToolUse ( e) => (
94+ EventType :: PreAction ,
95+ serde_json:: json!( {
9596 "tool" : e. tool,
9697 "arguments" : e. args,
9798 "working_directory" : e. working_directory,
9899 "recent_tools" : e. recent_tools,
99- } ) )
100- }
101- HookEvent :: PostToolUse ( e) => {
102- ( EventType :: PostAction , serde_json:: json!( {
100+ } ) ,
101+ ) ,
102+ HookEvent :: PostToolUse ( e) => (
103+ EventType :: PostAction ,
104+ serde_json:: json!( {
103105 "tool" : e. tool,
104106 "arguments" : e. args,
105107 "result" : {
@@ -108,50 +110,56 @@ impl AhpHookExecutor {
108110 "exit_code" : e. result. exit_code,
109111 "duration_ms" : e. result. duration_ms,
110112 }
111- } ) )
112- }
113- HookEvent :: PrePrompt ( e) => {
114- ( EventType :: PrePrompt , serde_json:: json!( {
113+ } ) ,
114+ ) ,
115+ HookEvent :: PrePrompt ( e) => (
116+ EventType :: PrePrompt ,
117+ serde_json:: json!( {
115118 "prompt" : e. prompt,
116119 "system_prompt" : e. system_prompt,
117120 "message_count" : e. message_count,
118- } ) )
119- }
120- HookEvent :: GenerateStart ( e) => {
121- ( EventType :: PrePrompt , serde_json:: json!( {
121+ } ) ,
122+ ) ,
123+ HookEvent :: GenerateStart ( e) => (
124+ EventType :: PrePrompt ,
125+ serde_json:: json!( {
122126 "prompt" : e. prompt,
123127 "session_id" : e. session_id,
124- } ) )
125- }
126- HookEvent :: PostResponse ( e) => {
127- ( EventType :: PostAction , serde_json:: json!( {
128+ } ) ,
129+ ) ,
130+ HookEvent :: PostResponse ( e) => (
131+ EventType :: PostAction ,
132+ serde_json:: json!( {
128133 "response_text" : e. response_text,
129134 "tool_calls_count" : e. tool_calls_count,
130135 "usage" : e. usage,
131136 "duration_ms" : e. duration_ms,
132- } ) )
133- }
134- HookEvent :: SessionStart ( e) => {
135- ( EventType :: SessionStart , serde_json:: json!( {
137+ } ) ,
138+ ) ,
139+ HookEvent :: SessionStart ( e) => (
140+ EventType :: SessionStart ,
141+ serde_json:: json!( {
136142 "session_id" : e. session_id,
137143 "system_prompt" : e. system_prompt,
138144 "model_provider" : e. model_provider,
139145 "model_name" : e. model_name,
140- } ) )
141- }
142- HookEvent :: SessionEnd ( e) => {
143- ( EventType :: SessionEnd , serde_json:: json!( {
146+ } ) ,
147+ ) ,
148+ HookEvent :: SessionEnd ( e) => (
149+ EventType :: SessionEnd ,
150+ serde_json:: json!( {
144151 "session_id" : e. session_id,
145152 "duration_ms" : e. duration_ms,
146- } ) )
147- }
148- HookEvent :: OnError ( e) => {
149- ( EventType :: Error , serde_json:: json!( {
153+ } ) ,
154+ ) ,
155+ HookEvent :: OnError ( e) => (
156+ EventType :: Error ,
157+ serde_json:: json!( {
150158 "error_type" : format!( "{:?}" , e. error_type) ,
151159 "error_message" : e. error_message,
152160 "context" : e. context,
153- } ) )
154- }
161+ } ) ,
162+ ) ,
155163 // Events not mapped to AHP
156164 HookEvent :: GenerateEnd ( _) | HookEvent :: SkillLoad ( _) | HookEvent :: SkillUnload ( _) => {
157165 return None ;
@@ -184,25 +192,28 @@ impl AhpHookExecutor {
184192 /// Map AHP decision to hook result
185193 fn map_decision ( & self , decision : Decision ) -> HookResult {
186194 match decision {
187- Decision :: Allow { modified_payload, .. } => {
195+ Decision :: Allow {
196+ modified_payload, ..
197+ } => {
188198 if let Some ( modified) = modified_payload {
189199 HookResult :: Continue ( Some ( modified) )
190200 } else {
191201 HookResult :: Continue ( None )
192202 }
193203 }
194- Decision :: Block { reason, .. } => {
195- HookResult :: Block ( reason)
196- }
197- Decision :: Defer { retry_after_ms, reason } => {
204+ Decision :: Block { reason, .. } => HookResult :: Block ( reason) ,
205+ Decision :: Defer {
206+ retry_after_ms,
207+ reason,
208+ } => {
198209 if let Some ( r) = reason {
199210 debug ! ( "AHP defer: {}" , r) ;
200211 }
201212 HookResult :: Retry ( retry_after_ms)
202213 }
203- Decision :: Modify { modified_payload , .. } => {
204- HookResult :: Continue ( Some ( modified_payload) )
205- }
214+ Decision :: Modify {
215+ modified_payload, ..
216+ } => HookResult :: Continue ( Some ( modified_payload ) ) ,
206217 Decision :: Escalate { reason, .. } => {
207218 // Escalate is treated as block for now
208219 // TODO: Implement human-in-the-loop escalation
@@ -238,7 +249,11 @@ impl HookExecutor for AhpHookExecutor {
238249
239250 if is_blocking {
240251 // Send event and wait for decision
241- match self . client . send_event ( ahp_event. event_type , ahp_event. payload ) . await {
252+ match self
253+ . client
254+ . send_event ( ahp_event. event_type , ahp_event. payload )
255+ . await
256+ {
242257 Ok ( decision) => {
243258 debug ! ( "AHP decision: {:?}" , decision) ;
244259 self . map_decision ( decision)
@@ -266,7 +281,7 @@ impl HookExecutor for AhpHookExecutor {
266281#[ cfg( test) ]
267282mod tests {
268283 use super :: * ;
269- use crate :: hooks:: { PreToolUseEvent , ToolResultData , PostToolUseEvent } ;
284+ use crate :: hooks:: { PostToolUseEvent , PreToolUseEvent , ToolResultData } ;
270285
271286 #[ test]
272287 fn test_map_pre_tool_use ( ) {
0 commit comments