@@ -106,6 +106,8 @@ pub struct AgentSessionDto {
106106 pub cwd : String ,
107107 pub state : String ,
108108 pub updated_at_unix_ms : u64 ,
109+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
110+ pub metadata : Option < serde_json:: Value > ,
109111}
110112
111113#[ derive( Debug , Clone , Deserialize ) ]
@@ -114,6 +116,7 @@ struct AgentSessionDtoWire {
114116 cwd : String ,
115117 state : String ,
116118 updated_at_unix_ms : u64 ,
119+ metadata : Option < serde_json:: Value > ,
117120}
118121
119122fn legacy_agent_session_id ( cwd : & str ) -> String {
@@ -133,6 +136,7 @@ impl<'de> Deserialize<'de> for AgentSessionDto {
133136 cwd : wire. cwd ,
134137 state : wire. state ,
135138 updated_at_unix_ms : wire. updated_at_unix_ms ,
139+ metadata : wire. metadata ,
136140 } )
137141 }
138142}
@@ -317,5 +321,53 @@ mod tests {
317321 assert_eq ! ( dto. cwd, "/tmp/repo/worktree" ) ;
318322 assert_eq ! ( dto. state, "waiting" ) ;
319323 assert_eq ! ( dto. updated_at_unix_ms, 99 ) ;
324+ assert ! ( dto. metadata. is_none( ) ) ;
325+ }
326+
327+ #[ test]
328+ fn agent_session_dto_deserializes_with_metadata ( ) {
329+ let dto: AgentSessionDto = serde_json:: from_value ( serde_json:: json!( {
330+ "session_id" : "sess-1" ,
331+ "cwd" : "/tmp/test" ,
332+ "state" : "working" ,
333+ "updated_at_unix_ms" : 42_u64 ,
334+ "metadata" : {
335+ "terminal" : { "type" : "tmux" , "server" : "my-project" , "pane_id" : "%42" } ,
336+ "git" : { "branch" : "feat/cool" }
337+ }
338+ } ) )
339+ . expect ( "payload with metadata should deserialize" ) ;
340+
341+ let meta = dto. metadata . expect ( "metadata should be Some" ) ;
342+ assert_eq ! ( meta[ "terminal" ] [ "type" ] , "tmux" ) ;
343+ assert_eq ! ( meta[ "terminal" ] [ "server" ] , "my-project" ) ;
344+ assert_eq ! ( meta[ "terminal" ] [ "pane_id" ] , "%42" ) ;
345+ assert_eq ! ( meta[ "git" ] [ "branch" ] , "feat/cool" ) ;
346+ }
347+
348+ #[ test]
349+ fn agent_session_dto_without_metadata_omits_field_in_json ( ) {
350+ let dto = AgentSessionDto {
351+ session_id : "s1" . to_owned ( ) ,
352+ cwd : "/tmp" . to_owned ( ) ,
353+ state : "idle" . to_owned ( ) ,
354+ updated_at_unix_ms : 0 ,
355+ metadata : None ,
356+ } ;
357+ let json = serde_json:: to_value ( & dto) . expect ( "should serialize" ) ;
358+ assert ! ( json. get( "metadata" ) . is_none( ) , "metadata should be omitted when None" ) ;
359+ }
360+
361+ #[ test]
362+ fn agent_session_dto_with_metadata_includes_field_in_json ( ) {
363+ let dto = AgentSessionDto {
364+ session_id : "s2" . to_owned ( ) ,
365+ cwd : "/tmp" . to_owned ( ) ,
366+ state : "working" . to_owned ( ) ,
367+ updated_at_unix_ms : 1 ,
368+ metadata : Some ( serde_json:: json!( { "foo" : "bar" } ) ) ,
369+ } ;
370+ let json = serde_json:: to_value ( & dto) . expect ( "should serialize" ) ;
371+ assert_eq ! ( json[ "metadata" ] [ "foo" ] , "bar" ) ;
320372 }
321373}
0 commit comments