@@ -16,7 +16,10 @@ pub(super) fn run(command: AcpCommand) -> anyhow::Result<()> {
1616
1717 let events = load_acp_events ( & memory, session. as_deref ( ) , limit) ?;
1818 if json {
19- println ! ( "{}" , serde_json:: to_string_pretty( & events) ?) ;
19+ println ! (
20+ "{}" ,
21+ serde_json:: to_string_pretty( & build_acp_events_json( & events) ?) ?
22+ ) ;
2023 } else {
2124 for event in events {
2225 let session = event
@@ -42,7 +45,10 @@ pub(super) fn run(command: AcpCommand) -> anyhow::Result<()> {
4245
4346 let checkpoints = load_acp_checkpoints ( & memory, & session) ?;
4447 if json {
45- println ! ( "{}" , serde_json:: to_string_pretty( & checkpoints) ?) ;
48+ println ! (
49+ "{}" ,
50+ serde_json:: to_string_pretty( & build_acp_checkpoints_json( & checkpoints) ?) ?
51+ ) ;
4652 } else if checkpoints. is_empty ( ) {
4753 println ! ( "no checkpoints for session {}" , session) ;
4854 } else {
@@ -66,3 +72,53 @@ pub(super) fn run(command: AcpCommand) -> anyhow::Result<()> {
6672 }
6773 }
6874}
75+
76+ fn build_acp_events_json ( events : & [ serde_json:: Value ] ) -> anyhow:: Result < serde_json:: Value > {
77+ Ok ( serde_json:: to_value ( events) ?)
78+ }
79+
80+ fn build_acp_checkpoints_json (
81+ checkpoints : & [ serde_json:: Value ] ,
82+ ) -> anyhow:: Result < serde_json:: Value > {
83+ Ok ( serde_json:: to_value ( checkpoints) ?)
84+ }
85+
86+ #[ cfg( test) ]
87+ mod tests {
88+ use super :: * ;
89+ use serde_json:: json;
90+
91+ #[ test]
92+ fn build_acp_events_json_keeps_expected_shape ( ) {
93+ let events = vec ! [
94+ json!( { "session_id" : "s-1" , "event_type" : "tool.failed" , "created_at" : 123 } ) ,
95+ json!( { "session_id" : "s-2" , "event_type" : "tool.succeeded" , "created_at" : 124 } ) ,
96+ ] ;
97+
98+ let out = build_acp_events_json ( & events) . unwrap ( ) ;
99+ assert_eq ! (
100+ out,
101+ json!( [
102+ { "session_id" : "s-1" , "event_type" : "tool.failed" , "created_at" : 123 } ,
103+ { "session_id" : "s-2" , "event_type" : "tool.succeeded" , "created_at" : 124 }
104+ ] )
105+ ) ;
106+ }
107+
108+ #[ test]
109+ fn build_acp_checkpoints_json_keeps_expected_shape ( ) {
110+ let checkpoints = vec ! [
111+ json!( { "channel" : "email" , "cursor" : "42" , "updated_at" : 1000 } ) ,
112+ json!( { "channel" : "slack" , "cursor" : "43" , "updated_at" : 1001 } ) ,
113+ ] ;
114+
115+ let out = build_acp_checkpoints_json ( & checkpoints) . unwrap ( ) ;
116+ assert_eq ! (
117+ out,
118+ json!( [
119+ { "channel" : "email" , "cursor" : "42" , "updated_at" : 1000 } ,
120+ { "channel" : "slack" , "cursor" : "43" , "updated_at" : 1001 }
121+ ] )
122+ ) ;
123+ }
124+ }
0 commit comments