mirror of
https://github.com/openai/codex.git
synced 2026-11-19 07:03:23 +00:00
[codex] Remove unused Rust helpers (#17146)
## Summary Removes high-confidence unused Rust helper functions and exports across `codex-tui`, `codex-shell-command`, and utility crates. The cleanup includes dead TUI helper methods, unused path/string/elapsed/fuzzy-match utilities, an unused Windows PowerShell lookup helper, and the unused terminal palette version counter. This keeps the remaining public surface smaller without changing behavior. ## Validation - `just fmt` - `cargo test -p codex-tui -p codex-shell-command -p codex-utils-elapsed -p codex-utils-fuzzy-match -p codex-utils-string -p codex-utils-path` - `just fix -p codex-tui -p codex-shell-command -p codex-utils-elapsed -p codex-utils-fuzzy-match -p codex-utils-string -p codex-utils-path` - `git diff --check`
This commit is contained in:
1 parent
f3cbe3d385
commit
0c8f3173e4
13 files changed
-157
No files matched your search
@@ -68,19 +68,6 @@ pub fn extract_powershell_command(command: &[String]) -> Option<(&str, &str)> {
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This function attempts to find a valid PowerShell executable on the system.
|
|
||||||
/// It first tries to find pwsh.exe, and if that fails, it tries to find
|
|
||||||
/// powershell.exe.
|
|
||||||
#[cfg(windows)]
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub(crate) fn try_find_powershellish_executable_blocking() -> Option<AbsolutePathBuf> {
|
|
||||||
if let Some(pwsh_path) = try_find_pwsh_executable_blocking() {
|
|
||||||
Some(pwsh_path)
|
|
||||||
} else {
|
|
||||||
try_find_powershell_executable_blocking()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// This function attempts to find a powershell.exe executable on the system.
|
/// This function attempts to find a powershell.exe executable on the system.
|
||||||
pub fn try_find_powershell_executable_blocking() -> Option<AbsolutePathBuf> {
|
pub fn try_find_powershell_executable_blocking() -> Option<AbsolutePathBuf> {
|
||||||
try_find_powershellish_executable_in_path(&["powershell.exe"])
|
try_find_powershellish_executable_in_path(&["powershell.exe"])
|
||||||
|
|||||||
@@ -126,11 +126,6 @@ impl AppCommand {
|
|||||||
Self(Op::RealtimeConversationAudio(params))
|
Self(Op::RealtimeConversationAudio(params))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub(crate) fn realtime_conversation_text(params: ConversationTextParams) -> Self {
|
|
||||||
Self(Op::RealtimeConversationText(params))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn realtime_conversation_close() -> Self {
|
pub(crate) fn realtime_conversation_close() -> Self {
|
||||||
Self(Op::RealtimeConversationClose)
|
Self(Op::RealtimeConversationClose)
|
||||||
}
|
}
|
||||||
@@ -265,16 +260,6 @@ impl AppCommand {
|
|||||||
Self(Op::Review { review_request })
|
Self(Op::Review { review_request })
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub(crate) fn kind(&self) -> &'static str {
|
|
||||||
self.0.kind()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub(crate) fn as_core(&self) -> &Op {
|
|
||||||
&self.0
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn into_core(self) -> Op {
|
pub(crate) fn into_core(self) -> Op {
|
||||||
self.0
|
self.0
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -777,16 +777,6 @@ pub(crate) fn status_account_display_from_auth_mode(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub(crate) fn feedback_audience_from_account_email(
|
|
||||||
account_email: Option<&str>,
|
|
||||||
) -> FeedbackAudience {
|
|
||||||
match account_email {
|
|
||||||
Some(email) if email.ends_with("@openai.com") => FeedbackAudience::OpenAiEmployee,
|
|
||||||
Some(_) | None => FeedbackAudience::External,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn model_preset_from_api_model(model: ApiModel) -> ModelPreset {
|
fn model_preset_from_api_model(model: ApiModel) -> ModelPreset {
|
||||||
let upgrade = model.upgrade.map(|upgrade_id| {
|
let upgrade = model.upgrade.map(|upgrade_id| {
|
||||||
let upgrade_info = model.upgrade_info.clone();
|
let upgrade_info = model.upgrade_info.clone();
|
||||||
|
|||||||
@@ -90,11 +90,6 @@ impl AsciiAnimation {
|
|||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub(crate) fn request_frame(&self) {
|
|
||||||
self.request_frame.schedule_frame();
|
|
||||||
}
|
|
||||||
|
|
||||||
fn frames(&self) -> &'static [&'static str] {
|
fn frames(&self) -> &'static [&'static str] {
|
||||||
self.variants[self.variant_idx]
|
self.variants[self.variant_idx]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4735,14 +4735,6 @@ impl ChatWidget {
|
|||||||
Self::new_with_op_target(common, CodexOpTarget::AppEvent)
|
Self::new_with_op_target(common, CodexOpTarget::AppEvent)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub(crate) fn new_with_op_sender(
|
|
||||||
common: ChatWidgetInit,
|
|
||||||
codex_op_tx: UnboundedSender<Op>,
|
|
||||||
) -> Self {
|
|
||||||
Self::new_with_op_target(common, CodexOpTarget::Direct(codex_op_tx))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn new_with_op_target(common: ChatWidgetInit, codex_op_target: CodexOpTarget) -> Self {
|
fn new_with_op_target(common: ChatWidgetInit, codex_op_target: CodexOpTarget) -> Self {
|
||||||
let ChatWidgetInit {
|
let ChatWidgetInit {
|
||||||
config,
|
config,
|
||||||
|
|||||||
@@ -81,11 +81,6 @@ impl RowBuilder {
|
|||||||
self.flush_current_line(/*explicit_break*/ true);
|
self.flush_current_line(/*explicit_break*/ true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Drain and return all produced rows.
|
|
||||||
pub fn drain_rows(&mut self) -> Vec<Row> {
|
|
||||||
std::mem::take(&mut self.rows)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Return a snapshot of produced rows (non-draining).
|
/// Return a snapshot of produced rows (non-draining).
|
||||||
pub fn rows(&self) -> &[Row] {
|
pub fn rows(&self) -> &[Row] {
|
||||||
&self.rows
|
&self.rows
|
||||||
|
|||||||
@@ -200,15 +200,6 @@ impl<'a> ColumnRenderable<'a> {
|
|||||||
pub fn push(&mut self, child: impl Into<Box<dyn Renderable + 'a>>) {
|
pub fn push(&mut self, child: impl Into<Box<dyn Renderable + 'a>>) {
|
||||||
self.children.push(RenderableItem::Owned(child.into()));
|
self.children.push(RenderableItem::Owned(child.into()));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub fn push_ref<R>(&mut self, child: &'a R)
|
|
||||||
where
|
|
||||||
R: Renderable + 'a,
|
|
||||||
{
|
|
||||||
self.children
|
|
||||||
.push(RenderableItem::Borrowed(child as &'a dyn Renderable));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct FlexChild<'a> {
|
pub struct FlexChild<'a> {
|
||||||
@@ -374,15 +365,6 @@ impl<'a> RowRenderable<'a> {
|
|||||||
self.children
|
self.children
|
||||||
.push((width, RenderableItem::Owned(child.into())));
|
.push((width, RenderableItem::Owned(child.into())));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub fn push_ref<R>(&mut self, width: u16, child: &'a R)
|
|
||||||
where
|
|
||||||
R: Renderable + 'a,
|
|
||||||
{
|
|
||||||
self.children
|
|
||||||
.push((width, RenderableItem::Borrowed(child as &'a dyn Renderable)));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct InsetRenderable<'a> {
|
pub struct InsetRenderable<'a> {
|
||||||
|
|||||||
@@ -1,13 +1,5 @@
|
|||||||
use crate::color::perceptual_distance;
|
use crate::color::perceptual_distance;
|
||||||
use ratatui::style::Color;
|
use ratatui::style::Color;
|
||||||
use std::sync::atomic::AtomicU64;
|
|
||||||
use std::sync::atomic::Ordering;
|
|
||||||
|
|
||||||
static DEFAULT_PALETTE_VERSION: AtomicU64 = AtomicU64::new(0);
|
|
||||||
|
|
||||||
fn bump_palette_version() {
|
|
||||||
DEFAULT_PALETTE_VERSION.fetch_add(1, Ordering::Relaxed);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||||
pub enum StdoutColorLevel {
|
pub enum StdoutColorLevel {
|
||||||
@@ -56,7 +48,6 @@ pub fn best_color(target: (u8, u8, u8)) -> Color {
|
|||||||
|
|
||||||
pub fn requery_default_colors() {
|
pub fn requery_default_colors() {
|
||||||
imp::requery_default_colors();
|
imp::requery_default_colors();
|
||||||
bump_palette_version();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy)]
|
||||||
@@ -77,14 +68,6 @@ pub fn default_bg() -> Option<(u8, u8, u8)> {
|
|||||||
default_colors().map(|c| c.bg)
|
default_colors().map(|c| c.bg)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a monotonic counter that increments whenever `requery_default_colors()` runs
|
|
||||||
/// successfully so cached renderers can know when their styling assumptions (e.g.
|
|
||||||
/// background colors baked into cached transcript rows) are stale and need invalidation.
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub fn palette_version() -> u64 {
|
|
||||||
DEFAULT_PALETTE_VERSION.load(Ordering::Relaxed)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(all(unix, not(test)))]
|
#[cfg(all(unix, not(test)))]
|
||||||
mod imp {
|
mod imp {
|
||||||
use super::DefaultColors;
|
use super::DefaultColors;
|
||||||
|
|||||||
@@ -1,11 +1,4 @@
|
|||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use std::time::Instant;
|
|
||||||
|
|
||||||
/// Returns a string representing the elapsed time since `start_time` like
|
|
||||||
/// "1m 15s" or "1.50s".
|
|
||||||
pub fn format_elapsed(start_time: Instant) -> String {
|
|
||||||
format_duration(start_time.elapsed())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Convert a [`std::time::Duration`] into a human-readable, compact string.
|
/// Convert a [`std::time::Duration`] into a human-readable, compact string.
|
||||||
///
|
///
|
||||||
|
|||||||
@@ -68,15 +68,6 @@ pub fn fuzzy_match(haystack: &str, needle: &str) -> Option<(Vec<usize>, i32)> {
|
|||||||
Some((result_orig_indices, score))
|
Some((result_orig_indices, score))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convenience wrapper to get only the indices for a fuzzy match.
|
|
||||||
pub fn fuzzy_indices(haystack: &str, needle: &str) -> Option<Vec<usize>> {
|
|
||||||
fuzzy_match(haystack, needle).map(|(mut idx, _)| {
|
|
||||||
idx.sort_unstable();
|
|
||||||
idx.dedup();
|
|
||||||
idx
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|||||||
@@ -1,9 +1,5 @@
|
|||||||
//! Functions for environment detection that need to be shared across crates.
|
//! Functions for environment detection that need to be shared across crates.
|
||||||
|
|
||||||
fn env_var_set(key: &str) -> bool {
|
|
||||||
std::env::var(key).is_ok_and(|v| !v.trim().is_empty())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns true if the current process is running under Windows Subsystem for Linux.
|
/// Returns true if the current process is running under Windows Subsystem for Linux.
|
||||||
pub fn is_wsl() -> bool {
|
pub fn is_wsl() -> bool {
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
@@ -21,26 +17,3 @@ pub fn is_wsl() -> bool {
|
|||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true when Codex is likely running in an environment without a usable GUI.
|
|
||||||
///
|
|
||||||
/// This is intentionally conservative and is used by frontends to avoid flows that would try to
|
|
||||||
/// open a browser (e.g. device-code auth fallback).
|
|
||||||
pub fn is_headless_environment() -> bool {
|
|
||||||
if env_var_set("CI")
|
|
||||||
|| env_var_set("SSH_CONNECTION")
|
|
||||||
|| env_var_set("SSH_CLIENT")
|
|
||||||
|| env_var_set("SSH_TTY")
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
|
||||||
{
|
|
||||||
if !env_var_set("DISPLAY") && !env_var_set("WAYLAND_DISPLAY") {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
false
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
//! Path normalization, symlink resolution, and atomic writes shared across Codex crates.
|
//! Path normalization, symlink resolution, and atomic writes shared across Codex crates.
|
||||||
|
|
||||||
pub(crate) mod env;
|
pub(crate) mod env;
|
||||||
pub use env::is_headless_environment;
|
|
||||||
pub use env::is_wsl;
|
pub use env::is_wsl;
|
||||||
|
|
||||||
use codex_utils_absolute_path::AbsolutePathBuf;
|
use codex_utils_absolute_path::AbsolutePathBuf;
|
||||||
|
|||||||
@@ -23,28 +23,6 @@ pub fn take_bytes_at_char_boundary(s: &str, maxb: usize) -> &str {
|
|||||||
&s[..last_ok]
|
&s[..last_ok]
|
||||||
}
|
}
|
||||||
|
|
||||||
// Take a suffix of a &str within a byte budget at a char boundary
|
|
||||||
#[inline]
|
|
||||||
pub fn take_last_bytes_at_char_boundary(s: &str, maxb: usize) -> &str {
|
|
||||||
if s.len() <= maxb {
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
let mut start = s.len();
|
|
||||||
let mut used = 0usize;
|
|
||||||
for (i, ch) in s.char_indices().rev() {
|
|
||||||
let nb = ch.len_utf8();
|
|
||||||
if used + nb > maxb {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
start = i;
|
|
||||||
used += nb;
|
|
||||||
if start == 0 {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
&s[start..]
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sanitize a tag value to comply with metric tag validation rules:
|
/// Sanitize a tag value to comply with metric tag validation rules:
|
||||||
/// only ASCII alphanumeric, '.', '_', '-', and '/' are allowed.
|
/// only ASCII alphanumeric, '.', '_', '-', and '/' are allowed.
|
||||||
pub fn sanitize_metric_tag_value(value: &str) -> String {
|
pub fn sanitize_metric_tag_value(value: &str) -> String {
|
||||||
|
|||||||
Reference in new issue
Block a user