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