Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 2 additions & 14 deletions codex-rs/tui/src/chatwidget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ impl RateLimitWarningState {
{
let threshold = RATE_LIMIT_WARNING_THRESHOLDS[self.weekly_index];
warnings.push(format!(
"Weekly usage exceeded {threshold:.0}% of the limit. Run /limits for detailed usage."
"Weekly usage exceeded {threshold:.0}% of the limit. Check /status to review usage."
));
self.weekly_index += 1;
}
Expand All @@ -138,7 +138,7 @@ impl RateLimitWarningState {
{
let threshold = RATE_LIMIT_WARNING_THRESHOLDS[self.hourly_index];
warnings.push(format!(
"Hourly usage exceeded {threshold:.0}% of the limit. Run /limits for detailed usage."
"Hourly usage exceeded {threshold:.0}% of the limit. Check /status to review usage."
));
self.hourly_index += 1;
}
Expand Down Expand Up @@ -988,9 +988,6 @@ impl ChatWidget {
SlashCommand::Status => {
self.add_status_output();
}
SlashCommand::Limits => {
self.add_limits_output();
}
SlashCommand::Mcp => {
self.add_mcp_output();
}
Expand Down Expand Up @@ -1347,15 +1344,6 @@ impl ChatWidget {
self.request_redraw();
}

pub(crate) fn add_limits_output(&mut self) {
if let Some(snapshot) = &self.rate_limit_snapshot {
self.add_to_history(history_cell::new_limits_output(snapshot));
} else {
self.add_to_history(history_cell::new_limits_unavailable());
}
self.request_redraw();
}

pub(crate) fn add_status_output(&mut self) {
let default_usage;
let usage_ref = if let Some(ti) = &self.token_info {
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

112 changes: 0 additions & 112 deletions codex-rs/tui/src/chatwidget/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ use codex_core::protocol::InputMessageKind;
use codex_core::protocol::Op;
use codex_core::protocol::PatchApplyBeginEvent;
use codex_core::protocol::PatchApplyEndEvent;
use codex_core::protocol::RateLimitSnapshotEvent;
use codex_core::protocol::ReviewCodeLocation;
use codex_core::protocol::ReviewFinding;
use codex_core::protocol::ReviewLineRange;
Expand All @@ -40,8 +39,6 @@ use crossterm::event::KeyEvent;
use crossterm::event::KeyModifiers;
use insta::assert_snapshot;
use pretty_assertions::assert_eq;
use ratatui::style::Color;
use ratatui::style::Modifier;
use std::fs::File;
use std::io::BufRead;
use std::io::BufReader;
Expand Down Expand Up @@ -380,115 +377,6 @@ fn lines_to_single_string(lines: &[ratatui::text::Line<'static>]) -> String {
s
}

fn styled_lines_to_string(lines: &[ratatui::text::Line<'static>]) -> String {
let mut out = String::new();
for line in lines {
for span in &line.spans {
let mut tags: Vec<&str> = Vec::new();
if let Some(color) = span.style.fg {
let name = match color {
Color::Black => "black",
Color::Blue => "blue",
Color::Cyan => "cyan",
Color::DarkGray => "dark-gray",
Color::Gray => "gray",
Color::Green => "green",
Color::LightBlue => "light-blue",
Color::LightCyan => "light-cyan",
Color::LightGreen => "light-green",
Color::LightMagenta => "light-magenta",
Color::LightRed => "light-red",
Color::LightYellow => "light-yellow",
Color::Magenta => "magenta",
Color::Red => "red",
Color::Rgb(_, _, _) => "rgb",
Color::Indexed(_) => "indexed",
Color::Reset => "reset",
Color::Yellow => "yellow",
Color::White => "white",
};
tags.push(name);
}
let modifiers = span.style.add_modifier;
if modifiers.contains(Modifier::BOLD) {
tags.push("bold");
}
if modifiers.contains(Modifier::DIM) {
tags.push("dim");
}
if modifiers.contains(Modifier::ITALIC) {
tags.push("italic");
}
if modifiers.contains(Modifier::UNDERLINED) {
tags.push("underlined");
}
if !tags.is_empty() {
out.push('[');
out.push_str(&tags.join("+"));
out.push(']');
}
out.push_str(&span.content);
if !tags.is_empty() {
out.push_str("[/]");
}
}
out.push('\n');
}
out
}

fn sample_rate_limit_snapshot(
primary_used_percent: f64,
weekly_used_percent: f64,
ratio_percent: f64,
) -> RateLimitSnapshotEvent {
RateLimitSnapshotEvent {
primary_used_percent,
weekly_used_percent,
primary_to_weekly_ratio_percent: ratio_percent,
primary_window_minutes: 300,
weekly_window_minutes: 10_080,
}
}

fn capture_limits_snapshot(snapshot: Option<RateLimitSnapshotEvent>) -> String {
let lines = match snapshot {
Some(ref snapshot) => history_cell::new_limits_output(snapshot).display_lines(80),
None => history_cell::new_limits_unavailable().display_lines(80),
};
styled_lines_to_string(&lines)
}

#[test]
fn limits_placeholder() {
let visual = capture_limits_snapshot(None);
assert_snapshot!(visual);
}

#[test]
fn limits_snapshot_basic() {
let visual = capture_limits_snapshot(Some(sample_rate_limit_snapshot(30.0, 60.0, 40.0)));
assert_snapshot!(visual);
}

#[test]
fn limits_snapshot_hourly_remaining() {
let visual = capture_limits_snapshot(Some(sample_rate_limit_snapshot(0.0, 20.0, 10.0)));
assert_snapshot!(visual);
}

#[test]
fn limits_snapshot_mixed_usage() {
let visual = capture_limits_snapshot(Some(sample_rate_limit_snapshot(20.0, 20.0, 10.0)));
assert_snapshot!(visual);
}

#[test]
fn limits_snapshot_weekly_heavy() {
let visual = capture_limits_snapshot(Some(sample_rate_limit_snapshot(98.0, 0.0, 10.0)));
assert_snapshot!(visual);
}

#[test]
fn rate_limit_warnings_emit_thresholds() {
let mut state = RateLimitWarningState::default();
Expand Down
37 changes: 0 additions & 37 deletions codex-rs/tui/src/history_cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ use crate::diff_render::create_diff_summary;
use crate::exec_command::relativize_to_home;
use crate::exec_command::strip_bash_lc_and_escape;
use crate::markdown::append_markdown;
use crate::rate_limits_view::DEFAULT_GRID_CONFIG;
use crate::rate_limits_view::LimitsView;
use crate::rate_limits_view::build_limits_view;
use crate::render::line_utils::line_to_static;
use crate::render::line_utils::prefix_lines;
use crate::render::line_utils::push_owned_lines;
Expand Down Expand Up @@ -229,20 +226,6 @@ impl HistoryCell for PlainHistoryCell {
}
}

#[derive(Debug)]
pub(crate) struct LimitsHistoryCell {
display: LimitsView,
}

impl HistoryCell for LimitsHistoryCell {
fn display_lines(&self, width: u16) -> Vec<Line<'static>> {
let mut lines = self.display.summary_lines.clone();
lines.extend(self.display.gauge_lines(width));
lines.extend(self.display.legend_lines.clone());
lines
}
}

#[derive(Debug)]
pub(crate) struct TranscriptOnlyHistoryCell {
lines: Vec<Line<'static>>,
Expand Down Expand Up @@ -1096,26 +1079,6 @@ pub(crate) fn new_completed_mcp_tool_call(
Box::new(PlainHistoryCell { lines })
}

pub(crate) fn new_limits_output(snapshot: &RateLimitSnapshotEvent) -> LimitsHistoryCell {
LimitsHistoryCell {
display: build_limits_view(snapshot, DEFAULT_GRID_CONFIG),
}
}

pub(crate) fn new_limits_unavailable() -> PlainHistoryCell {
PlainHistoryCell {
lines: vec![
"/limits".magenta().into(),
"".into(),
vec!["Rate limit usage snapshot".bold()].into(),
vec![" Tip: run `/limits` right after Codex replies for freshest numbers.".dim()]
.into(),
vec![" Real usage data is not available yet.".into()].into(),
vec![" Send a message to Codex, then run /limits again.".dim()].into(),
],
}
}

#[allow(clippy::disallowed_methods)]
pub(crate) fn new_warning_event(message: String) -> PlainHistoryCell {
PlainHistoryCell {
Expand Down
1 change: 0 additions & 1 deletion codex-rs/tui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ mod markdown_stream;
mod new_model_popup;
pub mod onboarding;
mod pager_overlay;
mod rate_limits_view;
mod render;
mod resume_picker;
mod session_log;
Expand Down
Loading
Loading