cxstatusline 0.10.0 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1683 @@
1
+ diff --git a/codex-rs/chatgpt/src/lib.rs b/codex-rs/chatgpt/src/lib.rs
2
+ index 057478db18..5589621149 100644
3
+ --- a/codex-rs/chatgpt/src/lib.rs
4
+ +++ b/codex-rs/chatgpt/src/lib.rs
5
+ @@ -1,3 +1,5 @@
6
+ +#![recursion_limit = "256"]
7
+ +
8
+ pub mod apply_command;
9
+ mod chatgpt_client;
10
+ pub mod connectors;
11
+ diff --git a/codex-rs/tui/src/app/background_requests.rs b/codex-rs/tui/src/app/background_requests.rs
12
+ index bfa33203da..6bac009cb9 100644
13
+ --- a/codex-rs/tui/src/app/background_requests.rs
14
+ +++ b/codex-rs/tui/src/app/background_requests.rs
15
+ @@ -102,7 +102,8 @@ impl App {
16
+ RateLimitRefreshOrigin::Recovery
17
+ | RateLimitRefreshOrigin::Periodic
18
+ | RateLimitRefreshOrigin::ResetConsume { .. }
19
+ - | RateLimitRefreshOrigin::ResetPicker { .. } => {
20
+ + | RateLimitRefreshOrigin::ResetPicker { .. }
21
+ + | RateLimitRefreshOrigin::CxStatusLine => {
22
+ tokio::time::timeout(RATE_LIMIT_RESET_REQUEST_TIMEOUT, request)
23
+ .await
24
+ .map_err(|_| "account/rateLimits/read timed out in TUI".to_string())
25
+ @@ -1341,7 +1342,92 @@ mod tests {
26
+ use codex_config::types::AuthCredentialsStoreMode;
27
+ use codex_protocol::mcp::Tool;
28
+ use codex_utils_absolute_path::AbsolutePathBuf;
29
+ + use codex_utils_absolute_path::test_support::PathExt;
30
+ use pretty_assertions::assert_eq;
31
+ + use tempfile::tempdir;
32
+ + use wiremock::Mock;
33
+ + use wiremock::MockServer;
34
+ + use wiremock::ResponseTemplate;
35
+ + use wiremock::matchers::method;
36
+ + use wiremock::matchers::path;
37
+ +
38
+ + #[tokio::test(flavor = "current_thread")]
39
+ + async fn cxstatusline_rate_limit_request_times_out() -> Result<()> {
40
+ + let mut app = make_test_app().await;
41
+ + let server = MockServer::start().await;
42
+ + let home = tempdir()?;
43
+ + app.config.codex_home = home.path().to_path_buf().abs();
44
+ + app.config.chatgpt_base_url = server.uri();
45
+ + app.cli_kv_overrides = vec![(
46
+ + "chatgpt_base_url".to_string(),
47
+ + toml::Value::String(server.uri()),
48
+ + )];
49
+ + app.config.cli_auth_credentials_store_mode = AuthCredentialsStoreMode::File;
50
+ + app.config.sqlite = codex_state::SqliteConfig::new_for_testing(home.path().abs());
51
+ + Mock::given(method("GET"))
52
+ + .and(path("/api/codex/config/bundle"))
53
+ + .respond_with(ResponseTemplate::new(/*status_code*/ 200).set_body_string("{}"))
54
+ + .mount(&server)
55
+ + .await;
56
+ + write_chatgpt_auth(
57
+ + home.path(),
58
+ + ChatGptAuthFixture::new("chatgpt-token").account_id("account-123"),
59
+ + AuthCredentialsStoreMode::File,
60
+ + )
61
+ + .expect("write ChatGPT authentication");
62
+ + Mock::given(method("GET"))
63
+ + .and(path("/api/codex/usage"))
64
+ + .respond_with(ResponseTemplate::new(/*status_code*/ 200).set_delay(
65
+ + RATE_LIMIT_RESET_REQUEST_TIMEOUT + std::time::Duration::from_secs(/*secs*/ 1),
66
+ + ))
67
+ + .expect(/*requests*/ 1)
68
+ + .mount(&server)
69
+ + .await;
70
+ + let app_server = crate::start_app_server_for_picker(
71
+ + &app.config,
72
+ + &crate::AppServerTarget::Embedded,
73
+ + app.cli_kv_overrides.clone(),
74
+ + app.loader_overrides.clone(),
75
+ + /*state_db*/ None,
76
+ + app.environment_manager.clone(),
77
+ + )
78
+ + .await?;
79
+ + let (app_event_tx, mut app_events) = tokio::sync::mpsc::unbounded_channel();
80
+ + app.app_event_tx = AppEventSender::new(app_event_tx);
81
+ +
82
+ + app.refresh_rate_limits(&app_server, RateLimitRefreshOrigin::CxStatusLine);
83
+ + tokio::time::timeout(std::time::Duration::from_secs(/*secs*/ 5), async {
84
+ + loop {
85
+ + if server.received_requests().await.is_some_and(|requests| {
86
+ + requests
87
+ + .iter()
88
+ + .any(|request| request.url.path() == "/api/codex/usage")
89
+ + }) {
90
+ + return;
91
+ + }
92
+ + tokio::time::sleep(std::time::Duration::from_millis(/*millis*/ 10)).await;
93
+ + }
94
+ + })
95
+ + .await
96
+ + .expect("cxstatusline request reaches the usage endpoint");
97
+ +
98
+ + tokio::time::pause();
99
+ + tokio::time::advance(RATE_LIMIT_RESET_REQUEST_TIMEOUT).await;
100
+ + tokio::task::yield_now().await;
101
+ +
102
+ + assert!(matches!(
103
+ + app_events.try_recv(),
104
+ + Ok(AppEvent::RateLimitsLoaded {
105
+ + origin: RateLimitRefreshOrigin::CxStatusLine,
106
+ + result: Err(ref error),
107
+ + ..
108
+ + }) if error == "account/rateLimits/read timed out in TUI"
109
+ + ));
110
+ +
111
+ + app_server.shutdown().await?;
112
+ + server.verify().await;
113
+ + Ok(())
114
+ + }
115
+
116
+ #[tokio::test]
117
+ async fn fetch_thread_usage_uses_app_server_auth_after_persisted_account_changes() {
118
+ diff --git a/codex-rs/tui/src/app/event_dispatch.rs b/codex-rs/tui/src/app/event_dispatch.rs
119
+ index 7fc9161a24..dc7ce39f16 100644
120
+ --- a/codex-rs/tui/src/app/event_dispatch.rs
121
+ +++ b/codex-rs/tui/src/app/event_dispatch.rs
122
+ @@ -1691,6 +1691,13 @@ impl App {
123
+ }),
124
+ );
125
+ }
126
+ + RateLimitRefreshOrigin::CxStatusLine => {
127
+ + self.chat_widget.finish_cxstatusline_rate_limit_refresh();
128
+ + for snapshot in snapshots {
129
+ + self.chat_widget.on_rate_limit_snapshot(Some(snapshot));
130
+ + }
131
+ + tui.frame_requester().schedule_frame();
132
+ + }
133
+ }
134
+ }
135
+ Err(err) => {
136
+ @@ -1736,6 +1743,10 @@ impl App {
137
+ Err(err),
138
+ );
139
+ }
140
+ + RateLimitRefreshOrigin::CxStatusLine => {
141
+ + self.chat_widget.finish_cxstatusline_rate_limit_refresh();
142
+ + tui.frame_requester().schedule_frame();
143
+ + }
144
+ }
145
+ }
146
+ }
147
+ diff --git a/codex-rs/tui/src/app/tests/rate_limits.rs b/codex-rs/tui/src/app/tests/rate_limits.rs
148
+ index 460b977b3c..6df58809ce 100644
149
+ --- a/codex-rs/tui/src/app/tests/rate_limits.rs
150
+ +++ b/codex-rs/tui/src/app/tests/rate_limits.rs
151
+ @@ -216,6 +216,7 @@ async fn stale_rate_limit_reads_preserve_newer_workspace_hard_stop_for_every_ori
152
+ "usage",
153
+ "reset-picker",
154
+ "reset-consume",
155
+ + "cxstatusline",
156
+ ] {
157
+ let (mut app, mut app_event_rx, _op_rx) = make_test_app_with_channels().await;
158
+ set_chatgpt_auth(&mut app.chat_widget);
159
+ @@ -270,6 +271,7 @@ async fn stale_rate_limit_reads_preserve_newer_workspace_hard_stop_for_every_ori
160
+ "reset-consume" => RateLimitRefreshOrigin::ResetConsume {
161
+ request_id: app.chat_widget.show_rate_limit_reset_consuming_popup(),
162
+ },
163
+ + "cxstatusline" => RateLimitRefreshOrigin::CxStatusLine,
164
+ _ => unreachable!("unknown refresh origin"),
165
+ };
166
+ let read_generation = app.rate_limit_hard_stop_generation;
167
+ @@ -313,7 +315,7 @@ async fn stale_rate_limit_reads_preserve_newer_workspace_hard_stop_for_every_ori
168
+ "reset-consume" => {
169
+ assert!(popup.contains("Usage reset. You have 0 usage limit resets left."));
170
+ }
171
+ - "startup" | "status" => {}
172
+ + "startup" | "status" | "cxstatusline" => {}
173
+ _ => unreachable!("unknown refresh origin"),
174
+ }
175
+
176
+ @@ -489,6 +491,97 @@ async fn failed_rate_limit_read_preserves_visible_backend_banner() -> Result<()>
177
+ Ok(())
178
+ }
179
+
180
+ +#[tokio::test]
181
+ +async fn cxstatusline_rate_limit_refresh_updates_snapshots_without_status_card() -> Result<()> {
182
+ + let (mut app, mut app_event_rx, _op_rx) = make_test_app_with_channels().await;
183
+ + set_chatgpt_auth(&mut app.chat_widget);
184
+ + let mut tui = crate::tui::test_support::make_test_tui()?;
185
+ + let mut app_server = Box::pin(crate::start_embedded_app_server_for_picker(
186
+ + app.chat_widget.config_ref(),
187
+ + ))
188
+ + .await?;
189
+ + let (request_id, hard_stop_generation) = app
190
+ + .rate_limit_refresh_state
191
+ + .start(
192
+ + RateLimitRefreshOrigin::CxStatusLine,
193
+ + &mut app.rate_limit_hard_stop_generation,
194
+ + )
195
+ + .expect("cxstatusline refresh starts");
196
+ +
197
+ + app.handle_event(
198
+ + &mut tui,
199
+ + &mut app_server,
200
+ + AppEvent::RateLimitsLoaded {
201
+ + request_id,
202
+ + origin: RateLimitRefreshOrigin::CxStatusLine,
203
+ + hard_stop_generation,
204
+ + result: Ok(account_rate_limits_response(rate_limit_snapshot(
205
+ + /*used_percent*/ 89, /*rate_limit_reached_type*/ None,
206
+ + /*spend_control_reached*/ None,
207
+ + ))),
208
+ + },
209
+ + )
210
+ + .await?;
211
+ +
212
+ + assert!(
213
+ + !std::iter::from_fn(|| app_event_rx.try_recv().ok())
214
+ + .any(|event| matches!(event, AppEvent::InsertHistoryCell(_))),
215
+ + "cxstatusline refresh must not create a status card"
216
+ + );
217
+ + let status = render_status_output(&mut app, &mut app_event_rx);
218
+ + assert!(
219
+ + status.contains("11% left"),
220
+ + "expected cxstatusline refresh to update cached limits, got: {status}"
221
+ + );
222
+ +
223
+ + app_server.shutdown().await?;
224
+ + Ok(())
225
+ +}
226
+ +
227
+ +#[tokio::test]
228
+ +async fn cxstatusline_rate_limit_refresh_failure_preserves_last_snapshot() -> Result<()> {
229
+ + let (mut app, mut app_event_rx, _op_rx) = make_test_app_with_channels().await;
230
+ + set_chatgpt_auth(&mut app.chat_widget);
231
+ + app.chat_widget
232
+ + .on_rate_limit_snapshot(Some(rate_limit_snapshot(
233
+ + /*used_percent*/ 89, /*rate_limit_reached_type*/ None,
234
+ + /*spend_control_reached*/ None,
235
+ + )));
236
+ + let mut tui = crate::tui::test_support::make_test_tui()?;
237
+ + let mut app_server = Box::pin(crate::start_embedded_app_server_for_picker(
238
+ + app.chat_widget.config_ref(),
239
+ + ))
240
+ + .await?;
241
+ + let (request_id, hard_stop_generation) = app
242
+ + .rate_limit_refresh_state
243
+ + .start(
244
+ + RateLimitRefreshOrigin::CxStatusLine,
245
+ + &mut app.rate_limit_hard_stop_generation,
246
+ + )
247
+ + .expect("cxstatusline refresh starts");
248
+ +
249
+ + app.handle_event(
250
+ + &mut tui,
251
+ + &mut app_server,
252
+ + AppEvent::RateLimitsLoaded {
253
+ + request_id,
254
+ + origin: RateLimitRefreshOrigin::CxStatusLine,
255
+ + hard_stop_generation,
256
+ + result: Err("offline".to_string()),
257
+ + },
258
+ + )
259
+ + .await?;
260
+ +
261
+ + let status = render_status_output(&mut app, &mut app_event_rx);
262
+ + assert!(
263
+ + status.contains("11% left"),
264
+ + "expected failed cxstatusline refresh to preserve cached limits, got: {status}"
265
+ + );
266
+ +
267
+ + app_server.shutdown().await?;
268
+ + Ok(())
269
+ +}
270
+ +
271
+ #[tokio::test]
272
+ async fn backend_banner_reads_ignore_older_completions() -> Result<()> {
273
+ let (mut app, _events, _ops) = make_test_app_with_channels().await;
274
+ diff --git a/codex-rs/tui/src/app_event.rs b/codex-rs/tui/src/app_event.rs
275
+ index 4dbdc87bf5..32e4abeb3c 100644
276
+ --- a/codex-rs/tui/src/app_event.rs
277
+ +++ b/codex-rs/tui/src/app_event.rs
278
+ @@ -212,6 +212,8 @@ pub(crate) struct PluginRemoteSectionError {
279
+ /// zero reset count so the disabled menu entry can become available without a
280
+ /// restart. A `ResetPicker` refreshes the rate limits and detailed reset-credit
281
+ /// rows before showing redemption choices.
282
+ +/// A `CxStatusLine` refresh updates the renderer payload without creating a
283
+ +/// status card or changing reset-credit state.
284
+ #[derive(Debug, Clone, Copy, PartialEq, Eq)]
285
+ pub(crate) enum RateLimitRefreshOrigin {
286
+ /// Eagerly fetched after bootstrap for `/status` data and reset availability.
287
+ @@ -229,6 +231,8 @@ pub(crate) enum RateLimitRefreshOrigin {
288
+ Recovery,
289
+ /// Background account usage read, scheduled more frequently near exhaustion.
290
+ Periodic,
291
+ + /// Periodically refresh the `CXSTATUSLINE_COMMAND` renderer payload.
292
+ + CxStatusLine,
293
+ }
294
+
295
+ #[derive(Debug, Clone, PartialEq, Eq)]
296
+ diff --git a/codex-rs/tui/src/bottom_pane/chat_composer.rs b/codex-rs/tui/src/bottom_pane/chat_composer.rs
297
+ index 158c39f1c7..6c8515c554 100644
298
+ --- a/codex-rs/tui/src/bottom_pane/chat_composer.rs
299
+ +++ b/codex-rs/tui/src/bottom_pane/chat_composer.rs
300
+ @@ -328,6 +328,7 @@ use super::footer::inset_footer_hint_area;
301
+ use super::footer::max_left_width_for_right;
302
+ use super::footer::passive_footer_status_line;
303
+ use super::footer::render_context_right;
304
+ +use super::footer::render_cxstatusline_block;
305
+ use super::footer::render_footer_from_props;
306
+ use super::footer::render_footer_hint_items;
307
+ use super::footer::render_footer_line;
308
+ @@ -745,6 +746,7 @@ impl ChatComposer {
309
+ status_line_value: None,
310
+ status_line_hyperlink_url: None,
311
+ status_line_enabled: false,
312
+ + cxstatusline_block: Vec::new(),
313
+ side_conversation_context_label: None,
314
+ active_agent_label: None,
315
+ external_editor_key: default_keymap
316
+ @@ -3856,6 +3858,7 @@ impl ChatComposer {
317
+ is_wsl,
318
+ status_line_value: self.footer.status_line_value.clone(),
319
+ status_line_enabled: self.footer.status_line_enabled,
320
+ + cxstatusline_block: self.footer.cxstatusline_block.clone(),
321
+ key_hints: FooterKeyHints {
322
+ agents: self
323
+ .agents_navigation_available()
324
+ @@ -4418,6 +4421,14 @@ impl ChatComposer {
325
+ true
326
+ }
327
+
328
+ + pub(crate) fn set_cxstatusline_block(&mut self, block: Vec<Line<'static>>) -> bool {
329
+ + if self.footer.cxstatusline_block == block {
330
+ + return false;
331
+ + }
332
+ + self.footer.cxstatusline_block = block;
333
+ + true
334
+ + }
335
+ +
336
+ pub(crate) fn set_side_conversation_context_label(&mut self, label: Option<String>) -> bool {
337
+ if self.footer.side_conversation_context_label == label {
338
+ return false;
339
+ @@ -4607,6 +4618,7 @@ impl ChatComposer {
340
+ remote_images: remote_images_rect,
341
+ textarea: textarea_rect,
342
+ popup: popup_rect,
343
+ + cxstatusline,
344
+ footer: footer_rect,
345
+ } = self.layout_with_options(area, options);
346
+ self.render_status_surface(status, buf);
347
+ @@ -4650,6 +4662,7 @@ impl ChatComposer {
348
+ }
349
+ }
350
+ }
351
+ + render_cxstatusline_block(cxstatusline, buf, &self.footer.cxstatusline_block);
352
+ let transcript_hint_area = inset_footer_hint_area(footer_rect);
353
+ let warning_notice = self.warning_notice_layout(transcript_hint_area, options);
354
+ let warning_area = warning_notice.as_ref().map(|(area, _)| *area);
355
+ diff --git a/codex-rs/tui/src/bottom_pane/chat_composer/composer_layout.rs b/codex-rs/tui/src/bottom_pane/chat_composer/composer_layout.rs
356
+ index b79c28b98a..c62c4a620a 100644
357
+ --- a/codex-rs/tui/src/bottom_pane/chat_composer/composer_layout.rs
358
+ +++ b/codex-rs/tui/src/bottom_pane/chat_composer/composer_layout.rs
359
+ @@ -102,6 +102,12 @@ impl ChatComposer {
360
+ (composer, popup, popup)
361
+ };
362
+ footer_rect.y = footer_rect.y.saturating_add(status.height);
363
+ + let cxstatusline = Rect {
364
+ + height: (self.footer.cxstatusline_block.len() as u16).min(footer_rect.height),
365
+ + ..footer_rect
366
+ + };
367
+ + footer_rect.y = footer_rect.y.saturating_add(cxstatusline.height);
368
+ + footer_rect.height = footer_rect.height.saturating_sub(cxstatusline.height);
369
+ // Keep the draft visible when clipped.
370
+ let voice_rows = voice_rows * u16::from(composer_rect.height >= voice_rows + 3);
371
+ let mut textarea_rect = composer_rect.inset(Insets::tlbr(
372
+ @@ -133,6 +139,7 @@ impl ChatComposer {
373
+ remote_images: remote_images_rect,
374
+ textarea: textarea_rect,
375
+ popup: popup_rect,
376
+ + cxstatusline,
377
+ footer: footer_rect,
378
+ }
379
+ }
380
+ diff --git a/codex-rs/tui/src/bottom_pane/chat_composer/footer_state.rs b/codex-rs/tui/src/bottom_pane/chat_composer/footer_state.rs
381
+ index fe4a6dc186..bca54691d0 100644
382
+ --- a/codex-rs/tui/src/bottom_pane/chat_composer/footer_state.rs
383
+ +++ b/codex-rs/tui/src/bottom_pane/chat_composer/footer_state.rs
384
+ @@ -1,6 +1,7 @@
385
+ //! Footer and status-row presentation state for the chat composer.
386
+ //! Owners schedule flash expiry redraws; replacing a draft clears its flash.
387
+ //! One resolved layout supplies the status, input, popup, and hint rectangles to each consumer.
388
+ +//! Renderer-owned status rows reserve their own rectangle above every native footer mode.
389
+ //! Slash-command and unified mention suggestions preserve passive footer content while keeping input.
390
+ //! Interactive transcript footers keep focus over nonempty composer hints. Their owner projects
391
+ //! actual pending chord hints; unrelated hints resume when the transcript interaction closes.
392
+ @@ -39,6 +40,7 @@ pub(super) struct ComposerLayout {
393
+ pub(super) remote_images: Rect,
394
+ pub(super) textarea: Rect,
395
+ pub(super) popup: Rect,
396
+ + pub(super) cxstatusline: Rect,
397
+ pub(super) footer: Rect,
398
+ }
399
+
400
+ @@ -131,16 +133,22 @@ impl super::ChatComposer {
401
+
402
+ pub(super) fn footer_hint_height(&self, width: u16, options: ComposerRenderOptions<'_>) -> u16 {
403
+ if self.show_warning_notice(options) || self.shortcuts_above_composer(options) {
404
+ - return 1;
405
+ + return (self.footer.cxstatusline_block.len() as u16).saturating_add(1);
406
+ }
407
+ options
408
+ .footer
409
+ .map_or_else(
410
+ || {
411
+ self.custom_footer_height()
412
+ + .map(|height| {
413
+ + height.saturating_add(self.footer.cxstatusline_block.len() as u16)
414
+ + })
415
+ .unwrap_or_else(|| footer_height(&self.hint_footer_props(options), width))
416
+ },
417
+ - |footer| footer.text.height().try_into().unwrap_or(u16::MAX),
418
+ + |footer| {
419
+ + let height: u16 = footer.text.height().try_into().unwrap_or(u16::MAX);
420
+ + height.saturating_add(self.footer.cxstatusline_block.len() as u16)
421
+ + },
422
+ )
423
+ .max(u16::from(options.separate_status_line))
424
+ }
425
+ @@ -215,6 +223,7 @@ pub(super) struct FooterState {
426
+ pub(super) status_line_value: Option<Line<'static>>,
427
+ pub(super) status_line_hyperlink_url: Option<String>,
428
+ pub(super) status_line_enabled: bool,
429
+ + pub(super) cxstatusline_block: Vec<Line<'static>>,
430
+ pub(super) side_conversation_context_label: Option<String>,
431
+ pub(super) active_agent_label: Option<String>,
432
+ pub(super) external_editor_key: Option<ShortcutHint>,
433
+ diff --git a/codex-rs/tui/src/bottom_pane/chat_composer/snapshots/codex_tui__bottom_pane__chat_composer__warning_notice__tests__cxstatusline_three_rows_with_warnings.snap b/codex-rs/tui/src/bottom_pane/chat_composer/snapshots/codex_tui__bottom_pane__chat_composer__warning_notice__tests__cxstatusline_three_rows_with_warnings.snap
434
+ new file mode 100644
435
+ index 0000000000..64a85de8e3
436
+ --- /dev/null
437
+ +++ b/codex-rs/tui/src/bottom_pane/chat_composer/snapshots/codex_tui__bottom_pane__chat_composer__warning_notice__tests__cxstatusline_three_rows_with_warnings.snap
438
+ @@ -0,0 +1,12 @@
439
+ +---
440
+ +source: tui/src/bottom_pane/chat_composer/warning_notice_tests.rs
441
+ +expression: "text(&render(&composer, 100, 3))"
442
+ +---
443
+ +
444
+ +› Ask Codex
445
+ +
446
+ + MODEL · ~/project
447
+ + CX row one
448
+ + CX row two
449
+ + CX row three
450
+ + ? for shortcuts ⚠ 3 warnings · f2 to view
451
+ diff --git a/codex-rs/tui/src/bottom_pane/chat_composer/warning_notice_tests.rs b/codex-rs/tui/src/bottom_pane/chat_composer/warning_notice_tests.rs
452
+ index 2e11e17236..6fe9fab4a0 100644
453
+ --- a/codex-rs/tui/src/bottom_pane/chat_composer/warning_notice_tests.rs
454
+ +++ b/codex-rs/tui/src/bottom_pane/chat_composer/warning_notice_tests.rs
455
+ @@ -163,3 +163,161 @@ fn warnings_yield_to_queue_controls_and_complete_navigation_hints() {
456
+ }
457
+ }
458
+ }
459
+ +
460
+ +#[test]
461
+ +fn cxstatusline_rows_survive_warning_and_menu_transitions() {
462
+ + let mut composer = composer();
463
+ + composer.set_cxstatusline_block(vec![
464
+ + "CX row one".into(),
465
+ + "CX row two".into(),
466
+ + "CX row three".into(),
467
+ + ]);
468
+ + for draft in ["", "/", "", "hello", ""] {
469
+ + composer.set_text_content(draft.into(), Vec::new(), Vec::new());
470
+ + for count in [0, 3, 0] {
471
+ + let screen = text(&render(&composer, /*width*/ 100, count));
472
+ + for row in ["CX row one", "CX row two", "CX row three"] {
473
+ + assert!(screen.contains(row), "missing {row}: {screen}");
474
+ + }
475
+ + }
476
+ + }
477
+ + insta::assert_snapshot!(
478
+ + "cxstatusline_three_rows_with_warnings",
479
+ + text(&render(&composer, /*width*/ 100, /*count*/ 3))
480
+ + );
481
+ +}
482
+ +
483
+ +#[test]
484
+ +fn cxstatusline_rows_preserve_transcript_cursor_and_shortcut_help() {
485
+ + let mut composer = composer();
486
+ + composer.set_cxstatusline_block(vec![
487
+ + "CX row one".into(),
488
+ + "CX row two".into(),
489
+ + "CX row three".into(),
490
+ + ]);
491
+ + let footer = TranscriptFooter {
492
+ + text: "transcript input".into(),
493
+ + cursor_column: Some(3),
494
+ + is_interactive: true,
495
+ + };
496
+ + for mode in [FooterMode::ComposerEmpty, FooterMode::ShortcutOverlay] {
497
+ + composer.footer.mode = mode;
498
+ + for transcript in [None, Some(&footer)] {
499
+ + let options = composer.resolve_render_options(ComposerRenderOptions {
500
+ + footer: transcript,
501
+ + ..Default::default()
502
+ + });
503
+ + let area = Rect::new(
504
+ + 0,
505
+ + 0,
506
+ + 100,
507
+ + composer.desired_height_with_options(100, options),
508
+ + );
509
+ + let mut buffer = Buffer::empty(area);
510
+ + composer.render_with_options(area, &mut buffer, None, options);
511
+ + let screen = text(&buffer);
512
+ + for row in ["CX row one", "CX row two", "CX row three"] {
513
+ + assert!(screen.contains(row), "missing {row}: {screen}");
514
+ + }
515
+ + if transcript.is_some() {
516
+ + let row = screen
517
+ + .lines()
518
+ + .position(|line| line.contains("transcript input"))
519
+ + .unwrap();
520
+ + assert_eq!(
521
+ + composer.cursor_pos_with_options(area, options),
522
+ + Some((5, row as u16))
523
+ + );
524
+ + }
525
+ + }
526
+ + }
527
+ +}
528
+ +
529
+ +#[test]
530
+ +fn cxstatusline_rows_survive_real_slash_popup_input_and_resize() {
531
+ + let mut composer = composer();
532
+ + composer.set_collaboration_modes_enabled(true);
533
+ + composer.set_cxstatusline_block(vec![
534
+ + "CX row one".into(),
535
+ + "CX row two".into(),
536
+ + "CX row three".into(),
537
+ + ]);
538
+ + for ch in ['/', 'm'] {
539
+ + composer.handle_key_event(KeyEvent::from(KeyCode::Char(ch)));
540
+ + }
541
+ + composer.handle_key_event(KeyEvent::new(KeyCode::Down, KeyModifiers::NONE));
542
+ + assert!(matches!(composer.popups.active, ActivePopup::Command(_)));
543
+ +
544
+ + for width in [80, 32] {
545
+ + let options = composer.resolve_render_options(ComposerRenderOptions {
546
+ + separate_status_line: true,
547
+ + command_popup_placement: CommandPopupPlacement::AboveComposer,
548
+ + ..Default::default()
549
+ + });
550
+ + let area = Rect::new(
551
+ + 0,
552
+ + 0,
553
+ + width,
554
+ + composer.desired_height_with_options(width, options),
555
+ + );
556
+ + let mut buffer = Buffer::empty(area);
557
+ + composer.render_with_options(area, &mut buffer, None, options);
558
+ + let layout = composer.layout_with_options(area, options);
559
+ + assert!(
560
+ + layout.popup.height > 0,
561
+ + "slash popup should remain open at width {width}: {}",
562
+ + text(&buffer)
563
+ + );
564
+ + assert_eq!(layout.cxstatusline.height, 3);
565
+ + assert_eq!(layout.cxstatusline.bottom(), layout.footer.y);
566
+ + for row in ["CX row one", "CX row two", "CX row three"] {
567
+ + assert!(
568
+ + text(&buffer).contains(row),
569
+ + "missing {row} at width {width}"
570
+ + );
571
+ + }
572
+ + let (x, y) = composer
573
+ + .cursor_pos_with_options(area, options)
574
+ + .expect("input cursor");
575
+ + assert!(
576
+ + x >= area.x && x < area.right(),
577
+ + "cursor x outside width {width}: {x}"
578
+ + );
579
+ + assert!(
580
+ + y >= area.y && y < area.bottom(),
581
+ + "cursor y outside screen: {y}"
582
+ + );
583
+ + }
584
+ +
585
+ + composer.handle_key_event(KeyEvent::new(KeyCode::Esc, KeyModifiers::NONE));
586
+ + assert!(matches!(composer.popups.active, ActivePopup::None));
587
+ + let options = composer.resolve_render_options(ComposerRenderOptions {
588
+ + separate_status_line: true,
589
+ + command_popup_placement: CommandPopupPlacement::AboveComposer,
590
+ + ..Default::default()
591
+ + });
592
+ + let area = Rect::new(0, 0, 80, composer.desired_height_with_options(80, options));
593
+ + let layout = composer.layout_with_options(area, options);
594
+ + assert_eq!(layout.cxstatusline.height, 3);
595
+ +
596
+ + for running in [true, false] {
597
+ + composer.set_task_running(running);
598
+ + let buffer = render(&composer, 80, 0);
599
+ + for row in ["CX row one", "CX row two", "CX row three"] {
600
+ + assert!(
601
+ + text(&buffer).contains(row),
602
+ + "missing {row}, running={running}"
603
+ + );
604
+ + }
605
+ + let layout = composer.layout_with_options(buffer.area, options);
606
+ + let (_, y) = composer
607
+ + .cursor_pos_with_options(buffer.area, options)
608
+ + .expect("input cursor");
609
+ + assert!(
610
+ + y < layout.cxstatusline.y,
611
+ + "cursor overlaps footer, running={running}"
612
+ + );
613
+ + }
614
+ + composer.handle_key_event(KeyEvent::from(KeyCode::Char('x')));
615
+ + assert!(text(&render(&composer, 80, 0)).contains("/mx"));
616
+ +}
617
+ diff --git a/codex-rs/tui/src/bottom_pane/footer.rs b/codex-rs/tui/src/bottom_pane/footer.rs
618
+ index b81f2c3151..92de7cd887 100644
619
+ --- a/codex-rs/tui/src/bottom_pane/footer.rs
620
+ +++ b/codex-rs/tui/src/bottom_pane/footer.rs
621
+ @@ -83,6 +83,9 @@ pub(crate) struct FooterProps {
622
+ pub(crate) quit_shortcut_key: KeyBinding,
623
+ pub(crate) status_line_value: Option<Line<'static>>,
624
+ pub(crate) status_line_enabled: bool,
625
+ + /// Complete renderer-owned rows kept separate from Codex's contextual status line so native
626
+ + /// instructions (Esc, quit, safety) remain visible below them.
627
+ + pub(crate) cxstatusline_block: Vec<Line<'static>>,
628
+ pub(crate) key_hints: FooterKeyHints,
629
+ /// Active thread label shown when the footer is rendering contextual information instead of an
630
+ /// instructional hint.
631
+ @@ -255,14 +258,15 @@ pub(crate) fn footer_height(props: &FooterProps, width: u16) -> u16 {
632
+ | FooterMode::ShortcutOverlay
633
+ | FooterMode::EscHint => false,
634
+ };
635
+ - footer_from_props_lines(
636
+ - props,
637
+ - /*collaboration_mode_indicator*/ None,
638
+ - /*show_cycle_hint*/ false,
639
+ - show_shortcuts_hint,
640
+ - show_queue_hint,
641
+ - )
642
+ - .len() as u16
643
+ + props.cxstatusline_block.len() as u16
644
+ + + footer_from_props_lines(
645
+ + props,
646
+ + /*collaboration_mode_indicator*/ None,
647
+ + /*show_cycle_hint*/ false,
648
+ + show_shortcuts_hint,
649
+ + show_queue_hint,
650
+ + )
651
+ + .len() as u16
652
+ }
653
+
654
+ /// Render a single precomputed footer line.
655
+ @@ -275,6 +279,16 @@ pub(crate) fn render_footer_line(area: Rect, buf: &mut Buffer, line: Line<'stati
656
+ .render(area, buf);
657
+ }
658
+
659
+ +/// Render renderer-owned rows above the native footer content.
660
+ +pub(crate) fn render_cxstatusline_block(area: Rect, buf: &mut Buffer, block: &[Line<'static>]) {
661
+ + Paragraph::new(prefix_lines(
662
+ + block.to_vec(),
663
+ + " ".repeat(FOOTER_INDENT_COLS).into(),
664
+ + " ".repeat(FOOTER_INDENT_COLS).into(),
665
+ + ))
666
+ + .render(area, buf);
667
+ +}
668
+ +
669
+ /// Render footer content directly from `FooterProps`.
670
+ ///
671
+ /// This is intentionally not part of the width-based collapse/fallback logic.
672
+ @@ -1017,12 +1031,49 @@ mod tests {
673
+ );
674
+ }
675
+
676
+ + fn props_with_status_block(rows: usize, mode: FooterMode) -> FooterProps {
677
+ + FooterProps {
678
+ + mode,
679
+ + esc_backtrack_hint: false,
680
+ + is_task_running: false,
681
+ + queue_submissions: false,
682
+ + collaboration_modes_enabled: false,
683
+ + is_wsl: false,
684
+ + quit_shortcut_key: key_hint::ctrl(KeyCode::Char('c')),
685
+ + status_line_value: None,
686
+ + status_line_enabled: false,
687
+ + cxstatusline_block: (0..rows)
688
+ + .map(|row| Line::from(format!("status-{row}")))
689
+ + .collect(),
690
+ + key_hints: FooterKeyHints::default_bindings(),
691
+ + active_agent_label: None,
692
+ + }
693
+ + }
694
+ +
695
+ fn snapshot_footer(name: &str, props: FooterProps) {
696
+ snapshot_footer_with_mode_indicator(
697
+ name, /*width*/ 80, &props, /*collaboration_mode_indicator*/ None,
698
+ );
699
+ }
700
+
701
+ + #[test]
702
+ + fn cxstatusline_block_adds_rows_without_hiding_instruction_footer() {
703
+ + let props = props_with_status_block(3, FooterMode::EscHint);
704
+ + assert_eq!(footer_height(&props, 80), 4);
705
+ +
706
+ + let screen = render_footer_with_mode_indicator_and_context(
707
+ + /*width*/ 80,
708
+ + &props,
709
+ + /*collaboration_mode_indicator*/ None,
710
+ + context_window_line(/*percent*/ None, /*used_tokens*/ None),
711
+ + );
712
+ + let lines = screen.lines().map(str::trim).collect::<Vec<_>>();
713
+ + assert_eq!(&lines[..3], ["status-0", "status-1", "status-2"]);
714
+ + assert!(lines[3].contains("esc"));
715
+ +
716
+ + snapshot_footer("cxstatusline_block_preserves_instruction_footer", props);
717
+ + }
718
+ +
719
+ fn snapshot_footer_with_context(
720
+ name: &str,
721
+ props: FooterProps,
722
+ @@ -1049,6 +1100,26 @@ mod tests {
723
+ terminal
724
+ .draw(|f| {
725
+ let area = Rect::new(0, 0, f.area().width, height);
726
+ + let cxstatusline_height = props.cxstatusline_block.len() as u16;
727
+ + if cxstatusline_height > 0 {
728
+ + let cxstatusline_area = Rect::new(
729
+ + area.x,
730
+ + area.y,
731
+ + area.width,
732
+ + cxstatusline_height.min(area.height),
733
+ + );
734
+ + render_cxstatusline_block(
735
+ + cxstatusline_area,
736
+ + f.buffer_mut(),
737
+ + &props.cxstatusline_block,
738
+ + );
739
+ + }
740
+ + let area = Rect::new(
741
+ + area.x,
742
+ + area.y.saturating_add(cxstatusline_height),
743
+ + area.width,
744
+ + area.height.saturating_sub(cxstatusline_height),
745
+ + );
746
+ let show_cycle_hint = !props.is_task_running;
747
+ let show_shortcuts_hint = match props.mode {
748
+ FooterMode::ComposerEmpty => true,
749
+ @@ -1297,6 +1368,7 @@ mod tests {
750
+ quit_shortcut_key: key_hint::ctrl(KeyCode::Char('c')),
751
+ status_line_value: None,
752
+ status_line_enabled: false,
753
+ + cxstatusline_block: Vec::new(),
754
+ key_hints: FooterKeyHints::default_bindings(),
755
+ active_agent_label: None,
756
+ },
757
+ @@ -1314,6 +1386,7 @@ mod tests {
758
+ quit_shortcut_key: key_hint::ctrl(KeyCode::Char('c')),
759
+ status_line_value: None,
760
+ status_line_enabled: false,
761
+ + cxstatusline_block: Vec::new(),
762
+ key_hints: FooterKeyHints {
763
+ insert_newline: Some(key_hint::shift(KeyCode::Enter).into()),
764
+ ..FooterKeyHints::default_bindings()
765
+ @@ -1334,6 +1407,7 @@ mod tests {
766
+ quit_shortcut_key: key_hint::ctrl(KeyCode::Char('c')),
767
+ status_line_value: None,
768
+ status_line_enabled: false,
769
+ + cxstatusline_block: Vec::new(),
770
+ key_hints: FooterKeyHints::default_bindings(),
771
+ active_agent_label: None,
772
+ },
773
+ @@ -1351,6 +1425,7 @@ mod tests {
774
+ quit_shortcut_key: key_hint::ctrl(KeyCode::Char('c')),
775
+ status_line_value: None,
776
+ status_line_enabled: false,
777
+ + cxstatusline_block: Vec::new(),
778
+ key_hints: FooterKeyHints::default_bindings(),
779
+ active_agent_label: None,
780
+ },
781
+ @@ -1368,6 +1443,7 @@ mod tests {
782
+ quit_shortcut_key: key_hint::ctrl(KeyCode::Char('c')),
783
+ status_line_value: None,
784
+ status_line_enabled: false,
785
+ + cxstatusline_block: Vec::new(),
786
+ key_hints: FooterKeyHints::default_bindings(),
787
+ active_agent_label: None,
788
+ },
789
+ @@ -1385,6 +1461,7 @@ mod tests {
790
+ quit_shortcut_key: key_hint::ctrl(KeyCode::Char('c')),
791
+ status_line_value: None,
792
+ status_line_enabled: false,
793
+ + cxstatusline_block: Vec::new(),
794
+ key_hints: FooterKeyHints::default_bindings(),
795
+ active_agent_label: None,
796
+ },
797
+ @@ -1402,6 +1479,7 @@ mod tests {
798
+ quit_shortcut_key: key_hint::ctrl(KeyCode::Char('c')),
799
+ status_line_value: None,
800
+ status_line_enabled: false,
801
+ + cxstatusline_block: Vec::new(),
802
+ key_hints: FooterKeyHints::default_bindings(),
803
+ active_agent_label: None,
804
+ },
805
+ @@ -1419,6 +1497,7 @@ mod tests {
806
+ quit_shortcut_key: key_hint::ctrl(KeyCode::Char('c')),
807
+ status_line_value: None,
808
+ status_line_enabled: false,
809
+ + cxstatusline_block: Vec::new(),
810
+ key_hints: FooterKeyHints::default_bindings(),
811
+ active_agent_label: None,
812
+ },
813
+ @@ -1436,6 +1515,7 @@ mod tests {
814
+ quit_shortcut_key: key_hint::ctrl(KeyCode::Char('c')),
815
+ status_line_value: None,
816
+ status_line_enabled: false,
817
+ + cxstatusline_block: Vec::new(),
818
+ key_hints: FooterKeyHints::default_bindings(),
819
+ active_agent_label: None,
820
+ },
821
+ @@ -1455,6 +1535,7 @@ mod tests {
822
+ quit_shortcut_key: key_hint::ctrl(KeyCode::Char('c')),
823
+ status_line_value: None,
824
+ status_line_enabled: false,
825
+ + cxstatusline_block: Vec::new(),
826
+ key_hints: FooterKeyHints::default_bindings(),
827
+ active_agent_label: None,
828
+ },
829
+ @@ -1474,6 +1555,7 @@ mod tests {
830
+ quit_shortcut_key: key_hint::ctrl(KeyCode::Char('c')),
831
+ status_line_value: None,
832
+ status_line_enabled: false,
833
+ + cxstatusline_block: Vec::new(),
834
+ key_hints: FooterKeyHints::default_bindings(),
835
+ active_agent_label: None,
836
+ },
837
+ @@ -1489,6 +1571,7 @@ mod tests {
838
+ quit_shortcut_key: key_hint::ctrl(KeyCode::Char('c')),
839
+ status_line_value: None,
840
+ status_line_enabled: false,
841
+ + cxstatusline_block: Vec::new(),
842
+ key_hints: FooterKeyHints::default_bindings(),
843
+ active_agent_label: None,
844
+ };
845
+ @@ -1517,6 +1600,7 @@ mod tests {
846
+ quit_shortcut_key: key_hint::ctrl(KeyCode::Char('c')),
847
+ status_line_value: None,
848
+ status_line_enabled: false,
849
+ + cxstatusline_block: Vec::new(),
850
+ key_hints: FooterKeyHints::default_bindings(),
851
+ active_agent_label: None,
852
+ };
853
+ @@ -1538,6 +1622,7 @@ mod tests {
854
+ quit_shortcut_key: key_hint::ctrl(KeyCode::Char('c')),
855
+ status_line_value: Some(Line::from("Status line content".to_string())),
856
+ status_line_enabled: true,
857
+ + cxstatusline_block: Vec::new(),
858
+ key_hints: FooterKeyHints::default_bindings(),
859
+ active_agent_label: None,
860
+ };
861
+ @@ -1554,6 +1639,7 @@ mod tests {
862
+ quit_shortcut_key: key_hint::ctrl(KeyCode::Char('c')),
863
+ status_line_value: Some(Line::from("Status line content".to_string())),
864
+ status_line_enabled: true,
865
+ + cxstatusline_block: Vec::new(),
866
+ key_hints: FooterKeyHints::default_bindings(),
867
+ active_agent_label: None,
868
+ };
869
+ @@ -1570,6 +1656,7 @@ mod tests {
870
+ quit_shortcut_key: key_hint::ctrl(KeyCode::Char('c')),
871
+ status_line_value: Some(Line::from("Status line content".to_string())),
872
+ status_line_enabled: true,
873
+ + cxstatusline_block: Vec::new(),
874
+ key_hints: FooterKeyHints::default_bindings(),
875
+ active_agent_label: None,
876
+ };
877
+ @@ -1586,6 +1673,7 @@ mod tests {
878
+ quit_shortcut_key: key_hint::ctrl(KeyCode::Char('c')),
879
+ status_line_value: None, // command timed out / empty
880
+ status_line_enabled: true,
881
+ + cxstatusline_block: Vec::new(),
882
+ key_hints: FooterKeyHints::default_bindings(),
883
+ active_agent_label: None,
884
+ };
885
+ @@ -1616,6 +1704,7 @@ mod tests {
886
+ quit_shortcut_key: key_hint::ctrl(KeyCode::Char('c')),
887
+ status_line_value: None,
888
+ status_line_enabled: false,
889
+ + cxstatusline_block: Vec::new(),
890
+ key_hints: FooterKeyHints::default_bindings(),
891
+ active_agent_label: None,
892
+ };
893
+ @@ -1638,6 +1727,7 @@ mod tests {
894
+ quit_shortcut_key: key_hint::ctrl(KeyCode::Char('c')),
895
+ status_line_value: None,
896
+ status_line_enabled: true,
897
+ + cxstatusline_block: Vec::new(),
898
+ key_hints: FooterKeyHints::default_bindings(),
899
+ active_agent_label: None,
900
+ };
901
+ @@ -1663,6 +1753,7 @@ mod tests {
902
+ "Status line content that should truncate before the mode indicator".to_string(),
903
+ )),
904
+ status_line_enabled: true,
905
+ + cxstatusline_block: Vec::new(),
906
+ key_hints: FooterKeyHints::default_bindings(),
907
+ active_agent_label: None,
908
+ };
909
+ @@ -1685,6 +1776,7 @@ mod tests {
910
+ quit_shortcut_key: key_hint::ctrl(KeyCode::Char('c')),
911
+ status_line_value: None,
912
+ status_line_enabled: false,
913
+ + cxstatusline_block: Vec::new(),
914
+ key_hints: FooterKeyHints::default_bindings(),
915
+ active_agent_label: Some("Robie [explorer]".to_string()),
916
+ };
917
+ @@ -1701,6 +1793,7 @@ mod tests {
918
+ quit_shortcut_key: key_hint::ctrl(KeyCode::Char('c')),
919
+ status_line_value: Some(Line::from("Status line content".to_string())),
920
+ status_line_enabled: true,
921
+ + cxstatusline_block: Vec::new(),
922
+ key_hints: FooterKeyHints::default_bindings(),
923
+ active_agent_label: Some("Robie [explorer]".to_string()),
924
+ };
925
+ @@ -1723,6 +1816,7 @@ mod tests {
926
+ .to_string(),
927
+ )),
928
+ status_line_enabled: true,
929
+ + cxstatusline_block: Vec::new(),
930
+ key_hints: FooterKeyHints::default_bindings(),
931
+ active_agent_label: None,
932
+ };
933
+ diff --git a/codex-rs/tui/src/bottom_pane/mod.rs b/codex-rs/tui/src/bottom_pane/mod.rs
934
+ index 3f16d118e1..47884dfbbd 100644
935
+ --- a/codex-rs/tui/src/bottom_pane/mod.rs
936
+ +++ b/codex-rs/tui/src/bottom_pane/mod.rs
937
+ @@ -2289,6 +2289,12 @@ impl BottomPane {
938
+ }
939
+ }
940
+
941
+ + pub(crate) fn set_cxstatusline_block(&mut self, block: Vec<Line<'static>>) {
942
+ + if self.composer.set_cxstatusline_block(block) {
943
+ + self.request_redraw();
944
+ + }
945
+ + }
946
+ +
947
+ /// Updates the contextual footer label and requests a redraw only when it changed.
948
+ ///
949
+ /// This keeps the footer plumbing cheap during thread transitions where `App` may recompute
950
+ diff --git a/codex-rs/tui/src/bottom_pane/shortcut_overlay_tests.rs b/codex-rs/tui/src/bottom_pane/shortcut_overlay_tests.rs
951
+ index fe6ebef45a..b6f34517e4 100644
952
+ --- a/codex-rs/tui/src/bottom_pane/shortcut_overlay_tests.rs
953
+ +++ b/codex-rs/tui/src/bottom_pane/shortcut_overlay_tests.rs
954
+ @@ -23,6 +23,7 @@ fn props() -> FooterProps {
955
+ quit_shortcut_key: key_hint::ctrl(KeyCode::Char('c')),
956
+ status_line_value: None,
957
+ status_line_enabled: false,
958
+ + cxstatusline_block: Vec::new(),
959
+ key_hints: FooterKeyHints {
960
+ agents: Some(key_hint::plain(KeyCode::Left).into()),
961
+ ..FooterKeyHints::default_bindings()
962
+ diff --git a/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__footer__tests__cxstatusline_block_preserves_instruction_footer.snap b/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__footer__tests__cxstatusline_block_preserves_instruction_footer.snap
963
+ new file mode 100644
964
+ index 0000000000..abf66c5ec2
965
+ --- /dev/null
966
+ +++ b/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__footer__tests__cxstatusline_block_preserves_instruction_footer.snap
967
+ @@ -0,0 +1,8 @@
968
+ +---
969
+ +source: tui/src/bottom_pane/footer.rs
970
+ +expression: terminal.backend()
971
+ +---
972
+ +" status-0 "
973
+ +" status-1 "
974
+ +" status-2 "
975
+ +" esc esc to edit previous message "
976
+ diff --git a/codex-rs/tui/src/chatwidget.rs b/codex-rs/tui/src/chatwidget.rs
977
+ index 984a9582cc..6789879cf5 100644
978
+ --- a/codex-rs/tui/src/chatwidget.rs
979
+ +++ b/codex-rs/tui/src/chatwidget.rs
980
+ @@ -821,6 +821,24 @@ pub(crate) struct ChatWidget {
981
+ status_line_workspace_headline_last_requested_at: Option<Instant>,
982
+ // Set after the backend reports the workspace-message feature gate is disabled.
983
+ status_line_workspace_messages_disabled: bool,
984
+ + // cxstatusline: argv of the external renderer from `CXSTATUSLINE_COMMAND`, if set.
985
+ + cxstatusline_command: Option<Vec<String>>,
986
+ + // cxstatusline: last successfully rendered complete block, shared with the render task.
987
+ + cxstatusline_output: Arc<std::sync::Mutex<Option<Vec<Line<'static>>>>>,
988
+ + // cxstatusline: true while a render task is in flight.
989
+ + cxstatusline_pending: Arc<AtomicBool>,
990
+ + // cxstatusline: set by the render task when new output landed - draw it, do not re-spawn.
991
+ + cxstatusline_fresh: Arc<AtomicBool>,
992
+ + // cxstatusline: a refresh arrived while throttled or pending - re-run once possible.
993
+ + cxstatusline_dirty: bool,
994
+ + // cxstatusline: last time a render task was spawned (throttle).
995
+ + cxstatusline_last_spawn_at: Option<Instant>,
996
+ + // cxstatusline: true while the periodic account/rateLimits/read is in flight.
997
+ + cxstatusline_rate_limit_pending: bool,
998
+ + // cxstatusline: last periodic account/rateLimits/read request time (throttle).
999
+ + cxstatusline_rate_limit_last_requested_at: Option<Instant>,
1000
+ + // cxstatusline: captured once so renderer speed calculations cover this TUI session.
1001
+ + cxstatusline_started_at: chrono::DateTime<chrono::Utc>,
1002
+ // Cached backend-estimated cost and bounded refresh state for the current thread.
1003
+ thread_usage: thread_usage::ThreadUsageState,
1004
+ // Current thread-goal status shown in the status line when plan mode is inactive.
1005
+ @@ -1231,6 +1249,7 @@ impl ChatWidget {
1006
+ self.refresh_terminal_title();
1007
+ }
1008
+ self.refresh_status_line_if_workspace_headline_due();
1009
+ + self.cxstatusline_pre_draw_tick();
1010
+ self.refresh_thread_usage_if_settlement_due();
1011
+ }
1012
+
1013
+ diff --git a/codex-rs/tui/src/chatwidget/constructor.rs b/codex-rs/tui/src/chatwidget/constructor.rs
1014
+ index 1c8c63ec78..f72463cbc0 100644
1015
+ --- a/codex-rs/tui/src/chatwidget/constructor.rs
1016
+ +++ b/codex-rs/tui/src/chatwidget/constructor.rs
1017
+ @@ -277,6 +277,19 @@ impl ChatWidget {
1018
+ next_status_line_workspace_headline_request_id: 0,
1019
+ status_line_workspace_headline_last_requested_at: None,
1020
+ status_line_workspace_messages_disabled: false,
1021
+ + cxstatusline_command: std::env::var("CXSTATUSLINE_COMMAND")
1022
+ + .ok()
1023
+ + .filter(|raw| !raw.trim().is_empty())
1024
+ + .and_then(|raw| shlex::split(&raw))
1025
+ + .filter(|argv| !argv.is_empty()),
1026
+ + cxstatusline_output: Arc::new(std::sync::Mutex::new(None)),
1027
+ + cxstatusline_pending: Arc::new(AtomicBool::new(false)),
1028
+ + cxstatusline_fresh: Arc::new(AtomicBool::new(false)),
1029
+ + cxstatusline_dirty: false,
1030
+ + cxstatusline_last_spawn_at: None,
1031
+ + cxstatusline_rate_limit_pending: false,
1032
+ + cxstatusline_rate_limit_last_requested_at: None,
1033
+ + cxstatusline_started_at: chrono::Utc::now(),
1034
+ thread_usage: thread_usage::ThreadUsageState::default(),
1035
+ current_goal_status_indicator: None,
1036
+ current_goal_status: None,
1037
+ diff --git a/codex-rs/tui/src/chatwidget/status_surfaces.rs b/codex-rs/tui/src/chatwidget/status_surfaces.rs
1038
+ index 616dd6df1e..ff3bf1a672 100644
1039
+ --- a/codex-rs/tui/src/chatwidget/status_surfaces.rs
1040
+ +++ b/codex-rs/tui/src/chatwidget/status_surfaces.rs
1041
+ @@ -42,6 +42,16 @@ const TERMINAL_TITLE_ACTION_REQUIRED_INTERVAL: Duration = Duration::from_secs(1)
1042
+ const TERMINAL_TITLE_ACTION_REQUIRED_PREFIX: &str = "[ ! ] Action Required";
1043
+ const TERMINAL_TITLE_ACTION_REQUIRED_PREFIX_HIDDEN: &str = "[ . ] Action Required";
1044
+
1045
+ +/// cxstatusline: minimum spacing between renderer spawns. 18 refresh call sites; one process per
1046
+ +/// call would be waste. Refreshes inside the window coalesce and run once it closes.
1047
+ +const CXSTATUSLINE_MIN_INTERVAL: Duration = Duration::from_millis(200);
1048
+ +
1049
+ +/// cxstatusline: renderer wall-clock budget. Over budget -> killed, last good line kept.
1050
+ +const CXSTATUSLINE_TIMEOUT: Duration = Duration::from_secs(1);
1051
+ +
1052
+ +/// cxstatusline: bounded account-rate-limit freshness for renderer payloads.
1053
+ +const CXSTATUSLINE_RATE_LIMIT_REFRESH_INTERVAL: Duration = Duration::from_secs(/*secs*/ 60);
1054
+ +
1055
+ #[derive(Debug)]
1056
+ /// Parsed status-surface configuration for one refresh pass.
1057
+ ///
1058
+ @@ -159,7 +169,7 @@ impl ChatWidget {
1059
+ }
1060
+
1061
+ fn sync_status_surface_shared_state(&mut self, selections: &StatusSurfaceSelections) {
1062
+ - if !selections.uses_git_branch() {
1063
+ + if !selections.uses_git_branch() && self.cxstatusline_command.is_none() {
1064
+ self.status_line_branch = None;
1065
+ self.status_line_branch_pending = false;
1066
+ self.status_line_branch_lookup_complete = false;
1067
+ @@ -171,7 +181,7 @@ impl ChatWidget {
1068
+ }
1069
+ }
1070
+
1071
+ - if !selections.uses_git_summary() {
1072
+ + if !selections.uses_git_summary() && self.cxstatusline_command.is_none() {
1073
+ self.status_line_git_summary = None;
1074
+ self.status_line_git_summary_pending = false;
1075
+ self.status_line_git_summary_lookup_complete = false;
1076
+ @@ -200,6 +210,12 @@ impl ChatWidget {
1077
+ }
1078
+
1079
+ fn refresh_status_line_from_selections(&mut self, selections: &StatusSurfaceSelections) {
1080
+ + if self.cxstatusline_command.is_some() {
1081
+ + self.cxstatusline_request_render();
1082
+ + if self.cxstatusline_draw_shared_cell() {
1083
+ + return;
1084
+ + }
1085
+ + }
1086
+ let enabled = !selections.status_line_items.is_empty();
1087
+ self.bottom_pane.set_status_line_enabled(enabled);
1088
+ if !enabled {
1089
+ @@ -432,7 +448,7 @@ impl ChatWidget {
1090
+
1091
+ pub(super) fn request_status_line_branch_refresh(&mut self) {
1092
+ let selections = self.status_surface_selections();
1093
+ - if !selections.uses_git_branch() {
1094
+ + if !selections.uses_git_branch() && self.cxstatusline_command.is_none() {
1095
+ return;
1096
+ }
1097
+ let cwd = self.status_line_cwd().to_path_buf();
1098
+ @@ -442,7 +458,7 @@ impl ChatWidget {
1099
+
1100
+ pub(super) fn request_status_line_git_summary_refresh(&mut self) {
1101
+ let selections = self.status_surface_selections();
1102
+ - if !selections.uses_git_summary() {
1103
+ + if !selections.uses_git_summary() && self.cxstatusline_command.is_none() {
1104
+ return;
1105
+ }
1106
+ let cwd = self.status_line_cwd().to_path_buf();
1107
+ @@ -593,6 +609,189 @@ impl ChatWidget {
1108
+ ///
1109
+ /// The resulting `StatusLineBranchUpdated` event carries the lookup cwd so callers can reject
1110
+ /// stale completions after directory changes.
1111
+ + /// cxstatusline: called from `pre_draw_tick`. Draws fresh renderer output without spawning,
1112
+ + /// and replays one coalesced refresh once the throttle window has closed.
1113
+ + pub(super) fn cxstatusline_pre_draw_tick(&mut self) {
1114
+ + if self.cxstatusline_command.is_none() {
1115
+ + return;
1116
+ + }
1117
+ + self.cxstatusline_rate_limit_tick(Instant::now());
1118
+ + if self.cxstatusline_fresh.swap(false, Ordering::AcqRel) {
1119
+ + self.cxstatusline_draw_shared_cell();
1120
+ + }
1121
+ + if !self.cxstatusline_dirty || self.cxstatusline_pending.load(Ordering::Acquire) {
1122
+ + return;
1123
+ + }
1124
+ + if let Some(remaining) = self.cxstatusline_throttle_remaining(Instant::now()) {
1125
+ + self.frame_requester.schedule_frame_in(remaining);
1126
+ + return;
1127
+ + }
1128
+ + self.cxstatusline_dirty = false;
1129
+ + self.refresh_status_line();
1130
+ + }
1131
+ +
1132
+ + /// Requests fresh account limits for renderer payloads at most once per minute.
1133
+ + pub(super) fn cxstatusline_rate_limit_tick(&mut self, now: Instant) {
1134
+ + if self.cxstatusline_command.is_none()
1135
+ + || !self.should_prefetch_rate_limits()
1136
+ + || self.cxstatusline_rate_limit_pending
1137
+ + {
1138
+ + return;
1139
+ + }
1140
+ + if let Some(last_requested_at) = self.cxstatusline_rate_limit_last_requested_at {
1141
+ + let elapsed = now.saturating_duration_since(last_requested_at);
1142
+ + if elapsed < CXSTATUSLINE_RATE_LIMIT_REFRESH_INTERVAL {
1143
+ + self.frame_requester
1144
+ + .schedule_frame_in(CXSTATUSLINE_RATE_LIMIT_REFRESH_INTERVAL - elapsed);
1145
+ + return;
1146
+ + }
1147
+ + }
1148
+ + self.cxstatusline_rate_limit_pending = true;
1149
+ + self.cxstatusline_rate_limit_last_requested_at = Some(now);
1150
+ + self.app_event_tx.send(AppEvent::RefreshRateLimits {
1151
+ + origin: crate::app_event::RateLimitRefreshOrigin::CxStatusLine,
1152
+ + });
1153
+ + self.frame_requester
1154
+ + .schedule_frame_in(CXSTATUSLINE_RATE_LIMIT_REFRESH_INTERVAL);
1155
+ + }
1156
+ +
1157
+ + pub(crate) fn finish_cxstatusline_rate_limit_refresh(&mut self) {
1158
+ + self.cxstatusline_rate_limit_pending = false;
1159
+ + // The completed read changed the payload source; schedule one renderer run.
1160
+ + self.cxstatusline_dirty = true;
1161
+ + }
1162
+ +
1163
+ + /// cxstatusline: draw the last complete shared block, if any. A poisoned lock leaves the
1164
+ + /// already-rendered block untouched, so callers do not replace it with partial/native output.
1165
+ + fn cxstatusline_draw_shared_cell(&mut self) -> bool {
1166
+ + let rendered = match self.cxstatusline_output.lock() {
1167
+ + Ok(guard) => guard.clone(),
1168
+ + Err(_) => return true,
1169
+ + };
1170
+ + let Some(rendered) = rendered else {
1171
+ + return false;
1172
+ + };
1173
+ + self.bottom_pane.set_cxstatusline_block(rendered);
1174
+ + self.bottom_pane.set_status_line_enabled(/*enabled*/ false);
1175
+ + self.set_status_line(/*status_line*/ None);
1176
+ + self.set_status_line_hyperlink(/*url*/ None);
1177
+ + true
1178
+ + }
1179
+ +
1180
+ + fn cxstatusline_throttle_remaining(&self, now: Instant) -> Option<Duration> {
1181
+ + let last = self.cxstatusline_last_spawn_at?;
1182
+ + let elapsed = now.saturating_duration_since(last);
1183
+ + (elapsed < CXSTATUSLINE_MIN_INTERVAL).then(|| CXSTATUSLINE_MIN_INTERVAL - elapsed)
1184
+ + }
1185
+ +
1186
+ + /// cxstatusline: spawn the renderer with a payload v1 snapshot, unless one is in flight or the
1187
+ + /// throttle window is open - then remember to run again. Mirrors `request_status_line_branch`.
1188
+ + fn cxstatusline_request_render(&mut self) {
1189
+ + let Some(argv) = self.cxstatusline_command.clone() else {
1190
+ + return;
1191
+ + };
1192
+ + let now = Instant::now();
1193
+ + if self.cxstatusline_pending.load(Ordering::Acquire)
1194
+ + || self.cxstatusline_throttle_remaining(now).is_some()
1195
+ + {
1196
+ + self.cxstatusline_dirty = true;
1197
+ + self.frame_requester
1198
+ + .schedule_frame_in(CXSTATUSLINE_MIN_INTERVAL);
1199
+ + return;
1200
+ + }
1201
+ + let payload = self.cxstatusline_payload_v1().to_string();
1202
+ + self.cxstatusline_pending.store(true, Ordering::Release);
1203
+ + self.cxstatusline_last_spawn_at = Some(now);
1204
+ + let output = self.cxstatusline_output.clone();
1205
+ + let pending = self.cxstatusline_pending.clone();
1206
+ + let fresh = self.cxstatusline_fresh.clone();
1207
+ + let frame_requester = self.frame_requester.clone();
1208
+ + tokio::spawn(async move {
1209
+ + if let Some(block) = cxstatusline_run(&argv, payload).await
1210
+ + && let Ok(mut guard) = output.lock()
1211
+ + {
1212
+ + *guard = Some(block);
1213
+ + fresh.store(true, Ordering::Release);
1214
+ + }
1215
+ + pending.store(false, Ordering::Release);
1216
+ + frame_requester.schedule_frame();
1217
+ + });
1218
+ + }
1219
+ +
1220
+ + /// cxstatusline: typed snapshot of the git state behind the native git status-line items.
1221
+ + fn cxstatusline_git_v1(&self) -> serde_json::Value {
1222
+ + use serde_json::json;
1223
+ + let summary = self.status_line_git_summary.as_ref();
1224
+ + json!({
1225
+ + "branch": self.status_line_branch.as_deref(),
1226
+ + "changes": summary
1227
+ + .and_then(|summary| summary.branch_change_stats.as_ref())
1228
+ + .map(|stats| json!({ "additions": stats.additions, "deletions": stats.deletions })),
1229
+ + "pr": summary
1230
+ + .and_then(|summary| summary.pull_request.as_ref())
1231
+ + .map(|pull_request| pull_request.number),
1232
+ + })
1233
+ + }
1234
+ +
1235
+ + /// cxstatusline: typed snapshot of the state behind every native status-line item.
1236
+ + /// `null` means "unavailable right now", same as an absent key. Enum-valued fields carry
1237
+ + /// Codex's own serde/strum identifiers (`on-request`, `workspace-write`), never display text.
1238
+ + fn cxstatusline_payload_v1(&self) -> serde_json::Value {
1239
+ + use serde_json::json;
1240
+ + let cwd = self.status_line_cwd().to_path_buf();
1241
+ + let project_root = self.status_line_project_root_for_cwd(&cwd);
1242
+ + let codex_limits = self.rate_limit_snapshots_by_limit_id.get("codex");
1243
+ + let window = |w: Option<(&RateLimitWindowDisplay, bool)>| {
1244
+ + w.map(|(window, _is_secondary)| {
1245
+ + json!({
1246
+ + "used": window.used_percent / 100.0,
1247
+ + "resets_at": window.resets_at_unix.and_then(cxstatusline_iso8601),
1248
+ + })
1249
+ + })
1250
+ + };
1251
+ + let used_tokens = {
1252
+ + let total = self.status_line_total_usage().blended_total();
1253
+ + (total > 0).then_some(total)
1254
+ + };
1255
+ + let usage = self.token_info.as_ref().map(|info| &info.total_token_usage);
1256
+ + let context_tokens = self
1257
+ + .token_info
1258
+ + .as_ref()
1259
+ + .map(|info| info.last_token_usage.tokens_in_context_window());
1260
+ + json!({
1261
+ + "payload_version": 1,
1262
+ + "model": {
1263
+ + "name": self.model_display_name(),
1264
+ + "reasoning": self.reasoning_display_name(),
1265
+ + },
1266
+ + "git": self.cxstatusline_git_v1(),
1267
+ + "usage": {
1268
+ + "context_used": self.status_line_context_used_percent().map(|p| p as f64 / 100.0),
1269
+ + "context_remaining": self.status_line_context_remaining_percent().map(|p| p as f64 / 100.0),
1270
+ + "context_tokens": context_tokens,
1271
+ + "context_window": self.status_line_context_window_size(),
1272
+ + "used_tokens": used_tokens,
1273
+ + "input_tokens": usage.map(|usage| usage.input_tokens),
1274
+ + "output_tokens": usage.map(|usage| usage.output_tokens),
1275
+ + "cached_input_tokens": usage.map(|usage| usage.cached_input_tokens),
1276
+ + "five_hour": window(codex_limits.and_then(five_hour_status_window)),
1277
+ + "weekly": window(codex_limits.and_then(weekly_status_window)),
1278
+ + },
1279
+ + "session": {
1280
+ + "id": self.thread_id.map(|id| id.to_string()),
1281
+ + "cwd": cwd.to_string_lossy(),
1282
+ + "project_root": project_root.map(|p| p.to_string_lossy().into_owned()),
1283
+ + "hostname": os_host_name(),
1284
+ + "approval_mode": self.config.permissions.approval_policy.value().to_string(),
1285
+ + "permissions": self.config.legacy_sandbox_policy().to_string(),
1286
+ + "run_state": self.run_state_status_text().to_lowercase(),
1287
+ + "codex_version": crate::version::CODEX_CLI_VERSION,
1288
+ + "started_at": self.cxstatusline_started_at.to_rfc3339_opts(chrono::SecondsFormat::Secs, /*use_z*/ true),
1289
+ + "thread_title": self.thread_name.clone(),
1290
+ + },
1291
+ + })
1292
+ + }
1293
+ +
1294
+ fn request_status_line_branch(&mut self, cwd: PathBuf) {
1295
+ if self.status_line_branch_pending {
1296
+ return;
1297
+ @@ -1263,3 +1462,48 @@ where
1298
+ }
1299
+ (items, invalid)
1300
+ }
1301
+ +
1302
+ +/// cxstatusline: seconds since the Unix epoch -> RFC 3339 UTC.
1303
+ +fn cxstatusline_iso8601(seconds: i64) -> Option<String> {
1304
+ + chrono::DateTime::<chrono::Utc>::from_timestamp(seconds, 0)
1305
+ + .map(|dt| dt.to_rfc3339_opts(chrono::SecondsFormat::Secs, /*use_z*/ true))
1306
+ +}
1307
+ +
1308
+ +/// cxstatusline: run the external renderer once. `None` on spawn failure, non-zero exit, timeout,
1309
+ +/// malformed, blank, or oversized stdout - the caller keeps the previous complete block.
1310
+ +async fn cxstatusline_run(argv: &[String], payload: String) -> Option<Vec<Line<'static>>> {
1311
+ + use tokio::io::AsyncWriteExt;
1312
+ + let (program, args) = argv.split_first()?;
1313
+ + let mut child = tokio::process::Command::new(program)
1314
+ + .args(args)
1315
+ + .stdin(std::process::Stdio::piped())
1316
+ + .stdout(std::process::Stdio::piped())
1317
+ + .stderr(std::process::Stdio::null())
1318
+ + .kill_on_drop(true)
1319
+ + .spawn()
1320
+ + .ok()?;
1321
+ + let mut stdin = child.stdin.take()?;
1322
+ + stdin.write_all(payload.as_bytes()).await.ok()?;
1323
+ + // Drop closes the pipe so the renderer sees EOF.
1324
+ + drop(stdin);
1325
+ + let output = tokio::time::timeout(CXSTATUSLINE_TIMEOUT, child.wait_with_output())
1326
+ + .await
1327
+ + .ok()?
1328
+ + .ok()?;
1329
+ + if !output.status.success() {
1330
+ + return None;
1331
+ + }
1332
+ + cxstatusline_parse_output(&String::from_utf8_lossy(&output.stdout))
1333
+ +}
1334
+ +
1335
+ +/// Parse all renderer rows before exposing them to the shared block; a malformed block never
1336
+ +/// replaces the last complete render.
1337
+ +pub(super) fn cxstatusline_parse_output(text: &str) -> Option<Vec<Line<'static>>> {
1338
+ + let text = text.strip_suffix('\n').unwrap_or(text);
1339
+ + let rows: Vec<_> = text.split('\n').collect();
1340
+ + ((1..=3).contains(&rows.len()) && rows.iter().all(|line| !line.trim().is_empty())).then(|| {
1341
+ + rows.into_iter()
1342
+ + .map(codex_ansi_escape::ansi_escape_line)
1343
+ + .collect()
1344
+ + })
1345
+ +}
1346
+ diff --git a/codex-rs/tui/src/chatwidget/tests/status_and_layout.rs b/codex-rs/tui/src/chatwidget/tests/status_and_layout.rs
1347
+ index 1c2308a4d1..07e5843f18 100644
1348
+ --- a/codex-rs/tui/src/chatwidget/tests/status_and_layout.rs
1349
+ +++ b/codex-rs/tui/src/chatwidget/tests/status_and_layout.rs
1350
+ @@ -1,5 +1,9 @@
1351
+ +use std::time::Duration;
1352
+ +use std::time::Instant;
1353
+ +
1354
+ use super::helpers::drain_insert_history_transcript;
1355
+ use super::*;
1356
+ +use crate::app_event::RateLimitRefreshOrigin;
1357
+ use crate::bottom_pane::goal_status_indicator_line;
1358
+ use crate::chatwidget::ThreadUsageOutcome;
1359
+ use crate::chatwidget::rate_limits::NUDGE_MODEL_SLUG;
1360
+ @@ -40,6 +44,245 @@ async fn finalized_voice_transcript_renders_beside_the_streamed_cell() {
1361
+ }
1362
+ }
1363
+
1364
+ +struct CxLocalGitRunner;
1365
+ +
1366
+ +impl crate::workspace_command::WorkspaceCommandExecutor for CxLocalGitRunner {
1367
+ + fn run(
1368
+ + &self,
1369
+ + command: crate::workspace_command::WorkspaceCommand,
1370
+ + ) -> std::pin::Pin<
1371
+ + Box<
1372
+ + dyn std::future::Future<
1373
+ + Output = Result<
1374
+ + crate::workspace_command::WorkspaceCommandOutput,
1375
+ + crate::workspace_command::WorkspaceCommandError,
1376
+ + >,
1377
+ + > + Send
1378
+ + + '_,
1379
+ + >,
1380
+ + > {
1381
+ + Box::pin(async move {
1382
+ + // Only local Git runs: PR probes must never contact the owner's GitHub account.
1383
+ + if command.argv.first().map(String::as_str) != Some("git") {
1384
+ + return Ok(crate::workspace_command::WorkspaceCommandOutput {
1385
+ + exit_code: 1,
1386
+ + stdout: String::new(),
1387
+ + stderr: String::new(),
1388
+ + });
1389
+ + }
1390
+ + let mut process = tokio::process::Command::new("git");
1391
+ + process.args(&command.argv[1..]).kill_on_drop(true);
1392
+ + if let Some(cwd) = command.cwd {
1393
+ + process.current_dir(cwd);
1394
+ + }
1395
+ + for (key, value) in command.env {
1396
+ + if let Some(value) = value {
1397
+ + process.env(key, value);
1398
+ + } else {
1399
+ + process.env_remove(key);
1400
+ + }
1401
+ + }
1402
+ + let output = tokio::time::timeout(command.timeout, process.output())
1403
+ + .await
1404
+ + .expect("git timeout")
1405
+ + .expect("git runs");
1406
+ + Ok(crate::workspace_command::WorkspaceCommandOutput {
1407
+ + exit_code: output.status.code().unwrap_or(1),
1408
+ + stdout: String::from_utf8_lossy(&output.stdout).into_owned(),
1409
+ + stderr: String::from_utf8_lossy(&output.stderr).into_owned(),
1410
+ + })
1411
+ + })
1412
+ + }
1413
+ +}
1414
+ +
1415
+ +#[tokio::test]
1416
+ +async fn cxstatusline_git_values_change_after_a_turn() {
1417
+ + let repo = tempfile::tempdir().expect("temp repo");
1418
+ + let git = |args: &[&str]| {
1419
+ + let output = std::process::Command::new("git")
1420
+ + .args(args)
1421
+ + .current_dir(repo.path())
1422
+ + .output()
1423
+ + .expect("git runs");
1424
+ + assert!(
1425
+ + output.status.success(),
1426
+ + "{}",
1427
+ + String::from_utf8_lossy(&output.stderr)
1428
+ + );
1429
+ + };
1430
+ + git(&["init", "-b", "main"]);
1431
+ + git(&[
1432
+ + "-c",
1433
+ + "user.name=Test",
1434
+ + "-c",
1435
+ + "user.email=test@example.com",
1436
+ + "commit",
1437
+ + "--allow-empty",
1438
+ + "-m",
1439
+ + "base",
1440
+ + ]);
1441
+ + let (mut chat, mut rx, _ops) = make_chatwidget_manual(/*model_override*/ None).await;
1442
+ + chat.config.cwd = AbsolutePathBuf::try_from(repo.path().to_path_buf()).expect("absolute cwd");
1443
+ + chat.current_cwd = Some(repo.path().to_path_buf());
1444
+ + chat.local_settings.tui.status_line = Some(vec![]);
1445
+ + chat.local_settings.tui.terminal_title = Some(vec![]);
1446
+ + chat.cxstatusline_command = Some(vec!["unused-renderer".into()]);
1447
+ + // Exercise collection without launching a renderer during completion callbacks.
1448
+ + chat.cxstatusline_pending.store(true, Ordering::Release);
1449
+ + chat.workspace_command_runner = Some(std::sync::Arc::new(CxLocalGitRunner));
1450
+ + for (branch, changes) in [("main", "No changes"), ("feature", "+1 -0")] {
1451
+ + if branch == "feature" {
1452
+ + git(&["checkout", "-b", "feature"]);
1453
+ + std::fs::write(repo.path().join("file"), "one line\n").expect("write change");
1454
+ + git(&["add", "file"]);
1455
+ + git(&[
1456
+ + "-c",
1457
+ + "user.name=Test",
1458
+ + "-c",
1459
+ + "user.email=test@example.com",
1460
+ + "commit",
1461
+ + "-m",
1462
+ + "change",
1463
+ + ]);
1464
+ + }
1465
+ + handle_turn_completed(&mut chat, "turn-1", /*duration_ms*/ None);
1466
+ + assert!(chat.status_line_branch_pending && chat.status_line_git_summary_pending);
1467
+ + tokio::time::timeout(Duration::from_secs(/*secs*/ 10), async {
1468
+ + while chat.status_line_branch_pending || chat.status_line_git_summary_pending {
1469
+ + match rx.recv().await.expect("completion event") {
1470
+ + AppEvent::StatusLineBranchUpdated { cwd, branch } => {
1471
+ + chat.set_status_line_branch(cwd, branch)
1472
+ + }
1473
+ + AppEvent::StatusLineGitSummaryUpdated { cwd, summary } => {
1474
+ + chat.set_status_line_git_summary(cwd, summary)
1475
+ + }
1476
+ + _ => {}
1477
+ + }
1478
+ + }
1479
+ + })
1480
+ + .await
1481
+ + .expect("Git refresh completes");
1482
+ + assert_eq!(chat.status_line_branch.as_deref(), Some(branch));
1483
+ + assert_eq!(
1484
+ + chat.status_line_value_for_item(crate::bottom_pane::StatusLineItem::BranchChanges),
1485
+ + Some(changes.into())
1486
+ + );
1487
+ + }
1488
+ +}
1489
+ +
1490
+ +#[tokio::test]
1491
+ +async fn cxstatusline_git_refresh_does_not_require_native_items() {
1492
+ + for mode in ["disabled", "cx", "native"] {
1493
+ + let (mut chat, _rx, _ops) = make_chatwidget_manual(/*model_override*/ None).await;
1494
+ + install_noop_workspace_command_runner(&mut chat);
1495
+ + chat.local_settings.tui.status_line = Some(if mode == "native" {
1496
+ + vec!["git-branch".into(), "branch-changes".into()]
1497
+ + } else {
1498
+ + vec![]
1499
+ + });
1500
+ + chat.local_settings.tui.terminal_title = Some(vec![]);
1501
+ + chat.cxstatusline_command = (mode == "cx").then(|| vec!["unused-renderer".into()]);
1502
+ + let cwd = chat.config.cwd.to_path_buf();
1503
+ + chat.status_line_branch_cwd = Some(cwd.clone());
1504
+ + chat.status_line_git_summary_cwd = Some(cwd);
1505
+ + chat.status_line_branch_lookup_complete = true;
1506
+ + chat.status_line_git_summary_lookup_complete = true;
1507
+ + chat.request_status_line_branch_refresh();
1508
+ + chat.request_status_line_git_summary_refresh();
1509
+ + assert_eq!(
1510
+ + (
1511
+ + chat.status_line_branch_pending,
1512
+ + chat.status_line_git_summary_pending
1513
+ + ),
1514
+ + (mode != "disabled", mode != "disabled"),
1515
+ + "refresh mode {mode}"
1516
+ + );
1517
+ + }
1518
+ +}
1519
+ +
1520
+ +#[test]
1521
+ +fn cxstatusline_accepts_complete_rows_and_rejects_invalid_blocks() {
1522
+ + assert_eq!(
1523
+ + super::super::status_surfaces::cxstatusline_parse_output("one\ntwo\nthree\n")
1524
+ + .expect("three non-blank rows")
1525
+ + .len(),
1526
+ + 3
1527
+ + );
1528
+ + assert!(super::super::status_surfaces::cxstatusline_parse_output("one\n\nthree\n").is_none());
1529
+ + assert!(super::super::status_surfaces::cxstatusline_parse_output("one\ntwo\n\n").is_none());
1530
+ + assert!(
1531
+ + super::super::status_surfaces::cxstatusline_parse_output("one\ntwo\nthree\nfour\n")
1532
+ + .is_none()
1533
+ + );
1534
+ +}
1535
+ +
1536
+ +#[tokio::test]
1537
+ +async fn cxstatusline_rate_limit_tick_requires_command_and_chatgpt_auth() {
1538
+ + let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
1539
+ + let now = Instant::now();
1540
+ +
1541
+ + chat.cxstatusline_rate_limit_tick(now);
1542
+ + assert!(matches!(
1543
+ + rx.try_recv(),
1544
+ + Err(tokio::sync::mpsc::error::TryRecvError::Empty)
1545
+ + ));
1546
+ +
1547
+ + chat.cxstatusline_command = Some(vec!["renderer".to_string()]);
1548
+ + chat.cxstatusline_rate_limit_tick(now);
1549
+ + assert!(matches!(
1550
+ + rx.try_recv(),
1551
+ + Err(tokio::sync::mpsc::error::TryRecvError::Empty)
1552
+ + ));
1553
+ +
1554
+ + set_chatgpt_auth(&mut chat);
1555
+ + chat.cxstatusline_rate_limit_tick(now);
1556
+ + assert!(matches!(
1557
+ + rx.try_recv(),
1558
+ + Ok(AppEvent::RefreshRateLimits {
1559
+ + origin: RateLimitRefreshOrigin::CxStatusLine,
1560
+ + })
1561
+ + ));
1562
+ +}
1563
+ +
1564
+ +#[tokio::test]
1565
+ +async fn cxstatusline_rate_limit_completion_releases_next_minute_tick() {
1566
+ + let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
1567
+ + chat.cxstatusline_command = Some(vec!["renderer".to_string()]);
1568
+ + set_chatgpt_auth(&mut chat);
1569
+ + let now = Instant::now();
1570
+ +
1571
+ + chat.cxstatusline_rate_limit_tick(now);
1572
+ + assert!(matches!(
1573
+ + rx.try_recv(),
1574
+ + Ok(AppEvent::RefreshRateLimits {
1575
+ + origin: RateLimitRefreshOrigin::CxStatusLine,
1576
+ + })
1577
+ + ));
1578
+ + assert!(chat.cxstatusline_rate_limit_pending);
1579
+ +
1580
+ + chat.cxstatusline_rate_limit_tick(now + Duration::from_secs(/*secs*/ 59));
1581
+ + assert!(matches!(
1582
+ + rx.try_recv(),
1583
+ + Err(tokio::sync::mpsc::error::TryRecvError::Empty)
1584
+ + ));
1585
+ +
1586
+ + chat.finish_cxstatusline_rate_limit_refresh();
1587
+ + assert!(!chat.cxstatusline_rate_limit_pending);
1588
+ + chat.cxstatusline_rate_limit_tick(now + Duration::from_secs(/*secs*/ 59));
1589
+ + assert!(matches!(
1590
+ + rx.try_recv(),
1591
+ + Err(tokio::sync::mpsc::error::TryRecvError::Empty)
1592
+ + ));
1593
+ +
1594
+ + chat.cxstatusline_rate_limit_tick(now + Duration::from_secs(/*secs*/ 60));
1595
+ + assert!(matches!(
1596
+ + rx.try_recv(),
1597
+ + Ok(AppEvent::RefreshRateLimits {
1598
+ + origin: RateLimitRefreshOrigin::CxStatusLine,
1599
+ + })
1600
+ + ));
1601
+ +}
1602
+ +
1603
+ fn enable_test_ambient_pet(chat: &mut ChatWidget) {
1604
+ chat.set_pet_image_support_for_tests(crate::pets::PetImageSupport::Supported(
1605
+ crate::pets::ImageProtocol::Kitty,
1606
+ diff --git a/codex-rs/tui/src/main.rs b/codex-rs/tui/src/main.rs
1607
+ index 5a196d614a..2a1e758644 100644
1608
+ --- a/codex-rs/tui/src/main.rs
1609
+ +++ b/codex-rs/tui/src/main.rs
1610
+ @@ -1,3 +1,4 @@
1611
+ +#![recursion_limit = "256"]
1612
+ use clap::Parser;
1613
+ use codex_arg0::Arg0DispatchPaths;
1614
+ use codex_arg0::arg0_dispatch_or_else;
1615
+ diff --git a/codex-rs/tui/src/status/rate_limits.rs b/codex-rs/tui/src/status/rate_limits.rs
1616
+ index c22868b621..df65a54aa7 100644
1617
+ --- a/codex-rs/tui/src/status/rate_limits.rs
1618
+ +++ b/codex-rs/tui/src/status/rate_limits.rs
1619
+ @@ -72,6 +72,8 @@ pub(crate) struct RateLimitWindowDisplay {
1620
+ pub used_percent: f64,
1621
+ /// Human-readable local reset time.
1622
+ pub resets_at: Option<String>,
1623
+ + /// cxstatusline: raw reset time, seconds since the Unix epoch, when the server provided one.
1624
+ + pub resets_at_unix: Option<i64>,
1625
+ /// Window length in minutes when provided by the server.
1626
+ pub window_minutes: Option<i64>,
1627
+ }
1628
+ @@ -92,6 +94,7 @@ impl RateLimitWindowDisplay {
1629
+ Self {
1630
+ used_percent: f64::from(window.used_percent),
1631
+ resets_at,
1632
+ + resets_at_unix: window.resets_at,
1633
+ window_minutes: window.window_duration_mins,
1634
+ }
1635
+ }
1636
+ @@ -460,6 +463,7 @@ mod tests {
1637
+ RateLimitWindowDisplay {
1638
+ used_percent,
1639
+ resets_at: Some("soon".to_string()),
1640
+ + resets_at_unix: None,
1641
+ window_minutes: Some(300),
1642
+ }
1643
+ }
1644
+ @@ -522,11 +526,13 @@ mod tests {
1645
+ primary: Some(RateLimitWindowDisplay {
1646
+ used_percent: 20.0,
1647
+ resets_at: Some("soon".to_string()),
1648
+ + resets_at_unix: None,
1649
+ window_minutes: Some(60),
1650
+ }),
1651
+ secondary: Some(RateLimitWindowDisplay {
1652
+ used_percent: 40.0,
1653
+ resets_at: Some("later".to_string()),
1654
+ + resets_at_unix: None,
1655
+ window_minutes: Some(2 * 60),
1656
+ }),
1657
+ credits: None,
1658
+ diff --git a/codex-rs/tui/src/status/tests.rs b/codex-rs/tui/src/status/tests.rs
1659
+ index bb65053072..24b18ce7a0 100644
1660
+ --- a/codex-rs/tui/src/status/tests.rs
1661
+ +++ b/codex-rs/tui/src/status/tests.rs
1662
+ @@ -71,6 +71,7 @@ fn stale_monthly_limit_marks_fresh_rolling_snapshot_stale() {
1663
+ primary: Some(RateLimitWindowDisplay {
1664
+ used_percent: 20.0,
1665
+ resets_at: Some("soon".to_string()),
1666
+ + resets_at_unix: None,
1667
+ window_minutes: Some(300),
1668
+ }),
1669
+ secondary: None,
1670
+ @@ -1832,11 +1833,13 @@ async fn transcript_overlay_remeasures_status_after_rate_limit_refresh() {
1671
+ primary: Some(RateLimitWindowDisplay {
1672
+ used_percent: 45.0,
1673
+ resets_at: Some("soon".to_string()),
1674
+ + resets_at_unix: None,
1675
+ window_minutes: Some(300),
1676
+ }),
1677
+ secondary: Some(RateLimitWindowDisplay {
1678
+ used_percent: 30.0,
1679
+ resets_at: Some("later".to_string()),
1680
+ + resets_at_unix: None,
1681
+ window_minutes: Some(10_080),
1682
+ }),
1683
+ credits: None,