@@ -68,12 +68,15 @@ impl AgentmemoryAdapter {
6868 /// expected by the `agentmemory` REST API. This provides a central, malleable
6969 /// place to adjust mapping logic in the future without touching the hooks engine.
7070 fn format_claude_parity_payload ( & self , event_name : & str , payload : serde_json:: Value ) -> serde_json:: Value {
71- // TODO: As agentmemory evolves, perform explicit property mapping here.
72- // For example, mapping Codex `turn_id` to Claude `message_id` or extracting specific nested fields.
71+ let session_id = payload. get ( "session_id" ) . and_then ( |v| v. as_str ( ) ) . unwrap_or ( "unknown" ) . to_string ( ) ;
72+
73+ let timestamp = chrono:: Utc :: now ( ) . to_rfc3339 ( ) ;
7374
7475 json ! ( {
75- "event" : event_name,
76- "payload" : payload,
76+ "sessionId" : session_id,
77+ "hookType" : event_name,
78+ "timestamp" : timestamp,
79+ "data" : payload,
7780 } )
7881 }
7982
@@ -118,4 +121,26 @@ impl AgentmemoryAdapter {
118121 }
119122 Ok ( ( ) )
120123 }
121- }
124+ }
125+ #[ cfg( test) ]
126+ mod tests {
127+ use super :: * ;
128+ use serde_json:: json;
129+
130+ #[ test]
131+ fn test_format_claude_parity_payload ( ) {
132+ let adapter = AgentmemoryAdapter :: new ( ) ;
133+ let raw_payload = json ! ( {
134+ "session_id" : "1234" ,
135+ "turn_id" : "turn-5" ,
136+ "command" : "echo hello"
137+ } ) ;
138+
139+ let formatted = adapter. format_claude_parity_payload ( "PreToolUse" , raw_payload. clone ( ) ) ;
140+
141+ assert_eq ! ( formatted[ "sessionId" ] , "1234" ) ;
142+ assert_eq ! ( formatted[ "hookType" ] , "PreToolUse" ) ;
143+ assert ! ( formatted. get( "timestamp" ) . is_some( ) ) ;
144+ assert_eq ! ( formatted[ "data" ] , raw_payload) ;
145+ }
146+ }
0 commit comments