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