1- use chrono:: Utc ;
21use codex_common:: elapsed:: format_elapsed;
32use codex_core:: config:: Config ;
43use codex_core:: protocol:: AgentMessageEvent ;
@@ -37,11 +36,13 @@ pub(crate) struct EventProcessor {
3736 // using .style() with one of these fields. If you need a new style, add a
3837 // new field here.
3938 bold : Style ,
39+ italic : Style ,
4040 dimmed : Style ,
4141
4242 magenta : Style ,
4343 red : Style ,
4444 green : Style ,
45+ cyan : Style ,
4546}
4647
4748impl EventProcessor {
@@ -55,21 +56,25 @@ impl EventProcessor {
5556 call_id_to_command,
5657 call_id_to_patch,
5758 bold : Style :: new ( ) . bold ( ) ,
59+ italic : Style :: new ( ) . italic ( ) ,
5860 dimmed : Style :: new ( ) . dimmed ( ) ,
5961 magenta : Style :: new ( ) . magenta ( ) ,
6062 red : Style :: new ( ) . red ( ) ,
6163 green : Style :: new ( ) . green ( ) ,
64+ cyan : Style :: new ( ) . cyan ( ) ,
6265 call_id_to_tool_call,
6366 }
6467 } else {
6568 Self {
6669 call_id_to_command,
6770 call_id_to_patch,
6871 bold : Style :: new ( ) ,
72+ italic : Style :: new ( ) ,
6973 dimmed : Style :: new ( ) ,
7074 magenta : Style :: new ( ) ,
7175 red : Style :: new ( ) ,
7276 green : Style :: new ( ) ,
77+ cyan : Style :: new ( ) ,
7378 call_id_to_tool_call,
7479 }
7580 }
@@ -94,43 +99,47 @@ struct PatchApplyBegin {
9499 auto_approved : bool ,
95100}
96101
102+ #[ macro_export]
97103macro_rules! ts_println {
98104 ( $( $arg: tt) * ) => { {
99- let now = Utc :: now( ) ;
105+ let now = chrono :: Utc :: now( ) ;
100106 let formatted = now. format( "%Y-%m-%dT%H:%M:%S" ) . to_string( ) ;
101107 print!( "[{}] " , formatted) ;
102108 println!( $( $arg) * ) ;
103109 } } ;
104110}
105111
106- /// Print a concise summary of the effective configuration that will be used
107- /// for the session. This mirrors the information shown in the TUI welcome
108- /// screen.
109- pub ( crate ) fn print_config_summary ( config : & Config , with_ansi : bool ) {
110- let bold = if with_ansi {
111- Style :: new ( ) . bold ( )
112- } else {
113- Style :: new ( )
114- } ;
115-
116- ts_println ! ( "OpenAI Codex (research preview)\n --------" ) ;
117-
118- let entries = vec ! [
119- ( "workdir" , config. cwd. display( ) . to_string( ) ) ,
120- ( "model" , config. model. clone( ) ) ,
121- ( "provider" , config. model_provider_id. clone( ) ) ,
122- ( "approval" , format!( "{:?}" , config. approval_policy) ) ,
123- ( "sandbox" , format!( "{:?}" , config. sandbox_policy) ) ,
124- ] ;
125-
126- for ( key, value) in entries {
127- println ! ( "{} {}" , format!( "{key}: " ) . style( bold) , value) ;
128- }
112+ impl EventProcessor {
113+ /// Print a concise summary of the effective configuration that will be used
114+ /// for the session. This mirrors the information shown in the TUI welcome
115+ /// screen.
116+ pub ( crate ) fn print_config_summary ( & mut self , config : & Config , prompt : & str ) {
117+ ts_println ! ( "OpenAI Codex (research preview)\n --------" ) ;
118+
119+ let entries = vec ! [
120+ ( "workdir" , config. cwd. display( ) . to_string( ) ) ,
121+ ( "model" , config. model. clone( ) ) ,
122+ ( "provider" , config. model_provider_id. clone( ) ) ,
123+ ( "approval" , format!( "{:?}" , config. approval_policy) ) ,
124+ ( "sandbox" , format!( "{:?}" , config. sandbox_policy) ) ,
125+ ] ;
126+
127+ for ( key, value) in entries {
128+ println ! ( "{} {}" , format!( "{key}: " ) . style( self . bold) , value) ;
129+ }
129130
130- println ! ( "--------\n " ) ;
131- }
131+ println ! ( "--------" ) ;
132+
133+ // Echo the prompt that will be sent to the agent so it is visible in the
134+ // transcript/logs before any events come in. Note the prompt may have been
135+ // read from stdin, so it may not be visible in the terminal otherwise.
136+ ts_println ! (
137+ "{}\n {}" ,
138+ "User instructions:" . style( self . bold) . style( self . cyan) ,
139+ prompt
140+ ) ;
141+ }
132142
133- impl EventProcessor {
134143 pub ( crate ) fn process_event ( & mut self , event : Event ) {
135144 let Event { id : _, msg } = event;
136145 match msg {
@@ -145,8 +154,10 @@ impl EventProcessor {
145154 // Ignore.
146155 }
147156 EventMsg :: AgentMessage ( AgentMessageEvent { message } ) => {
148- let prefix = "Agent message:" . style ( self . bold ) ;
149- ts_println ! ( "{prefix} {message}" ) ;
157+ ts_println ! (
158+ "{}\n {message}" ,
159+ "codex" . style( self . bold) . style( self . magenta)
160+ ) ;
150161 }
151162 EventMsg :: ExecCommandBegin ( ExecCommandBeginEvent {
152163 call_id,
@@ -394,7 +405,11 @@ impl EventProcessor {
394405 // Should we exit?
395406 }
396407 EventMsg :: AgentReasoning ( agent_reasoning_event) => {
397- println ! ( "thinking: {}" , agent_reasoning_event. text) ;
408+ ts_println ! (
409+ "{}\n {}" ,
410+ "thinking" . style( self . italic) . style( self . magenta) ,
411+ agent_reasoning_event. text
412+ ) ;
398413 }
399414 EventMsg :: SessionConfigured ( session_configured_event) => {
400415 let SessionConfiguredEvent {
0 commit comments