mirror of
https://github.com/openai/codex.git
synced 2026-05-05 20:07:02 +00:00
cleanup
This commit is contained in:
@@ -34,12 +34,9 @@ pub struct ApplyModalState {
|
||||
|
||||
use crate::scrollable_diff::ScrollableDiff;
|
||||
use codex_cloud_tasks_api::CloudBackend;
|
||||
use codex_cloud_tasks_api::DiffSummary;
|
||||
use codex_cloud_tasks_api::TaskId;
|
||||
use codex_cloud_tasks_api::TaskSummary;
|
||||
use throbber_widgets_tui::ThrobberState;
|
||||
use tokio::sync::mpsc::UnboundedReceiver;
|
||||
use tokio::sync::mpsc::UnboundedSender;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct App {
|
||||
@@ -65,8 +62,7 @@ pub struct App {
|
||||
// Background enrichment coordination
|
||||
pub list_generation: u64,
|
||||
pub in_flight: std::collections::HashSet<String>,
|
||||
pub summary_cache: std::collections::HashMap<String, (DiffSummary, std::time::Instant)>,
|
||||
pub no_diff_yet: std::collections::HashSet<String>,
|
||||
// Background enrichment caches were planned; currently unused.
|
||||
}
|
||||
|
||||
impl App {
|
||||
@@ -90,8 +86,6 @@ impl App {
|
||||
apply_preflight_inflight: false,
|
||||
list_generation: 0,
|
||||
in_flight: std::collections::HashSet::new(),
|
||||
summary_cache: std::collections::HashMap::new(),
|
||||
no_diff_yet: std::collections::HashSet::new(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,14 +130,7 @@ pub enum AppEvent {
|
||||
env: Option<String>,
|
||||
result: anyhow::Result<Vec<TaskSummary>>,
|
||||
},
|
||||
/// Background diff summary computed for a task (or determined absent)
|
||||
TaskSummaryUpdated {
|
||||
generation: u64,
|
||||
id: TaskId,
|
||||
summary: DiffSummary,
|
||||
no_diff_yet: bool,
|
||||
environment_id: Option<String>,
|
||||
},
|
||||
// Background diff summary events were planned; removed for now to keep code minimal.
|
||||
/// Autodetection of a likely environment id finished
|
||||
EnvironmentAutodetected(anyhow::Result<crate::env_detect::AutodetectSelection>),
|
||||
/// Background completion of environment list fetch
|
||||
@@ -176,9 +163,7 @@ pub enum AppEvent {
|
||||
},
|
||||
}
|
||||
|
||||
pub type AppEventTx = UnboundedSender<AppEvent>;
|
||||
pub type AppEventRx = UnboundedReceiver<AppEvent>;
|
||||
|
||||
// Convenience aliases; currently unused.
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
@@ -19,10 +19,10 @@ async fn main() -> anyhow::Result<()> {
|
||||
AuthMode::ChatGPT,
|
||||
"codex_cloud_tasks_detailcheck".to_string(),
|
||||
);
|
||||
if let Some(auth) = am.auth() {
|
||||
if let Ok(tok) = auth.get_token().await {
|
||||
client = client.with_bearer_token(tok);
|
||||
}
|
||||
if let Some(auth) = am.auth()
|
||||
&& let Ok(tok) = auth.get_token().await
|
||||
{
|
||||
client = client.with_bearer_token(tok);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -77,10 +77,10 @@ async fn main() -> anyhow::Result<()> {
|
||||
.or_else(|| extract_chatgpt_account_id(&token))
|
||||
{
|
||||
println!("auth: ChatGPT-Account-Id: {account_id}");
|
||||
if let Ok(name) = HeaderName::from_bytes(b"ChatGPT-Account-Id") {
|
||||
if let Ok(hv) = HeaderValue::from_str(&account_id) {
|
||||
headers.insert(name, hv);
|
||||
}
|
||||
if let Ok(name) = HeaderName::from_bytes(b"ChatGPT-Account-Id")
|
||||
&& let Ok(hv) = HeaderValue::from_str(&account_id)
|
||||
{
|
||||
headers.insert(name, hv);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,10 +82,10 @@ async fn main() -> anyhow::Result<()> {
|
||||
.or_else(|| extract_chatgpt_account_id(&token))
|
||||
{
|
||||
println!("auth: ChatGPT-Account-Id: {account_id}");
|
||||
if let Ok(name) = HeaderName::from_bytes(b"ChatGPT-Account-Id") {
|
||||
if let Ok(hv) = HeaderValue::from_str(&account_id) {
|
||||
headers.insert(name, hv);
|
||||
}
|
||||
if let Ok(name) = HeaderName::from_bytes(b"ChatGPT-Account-Id")
|
||||
&& let Ok(hv) = HeaderValue::from_str(&account_id)
|
||||
{
|
||||
headers.insert(name, hv);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -141,13 +141,13 @@ async fn main() -> anyhow::Result<()> {
|
||||
}));
|
||||
|
||||
// Optional: starting diff via env var for quick testing
|
||||
if let Ok(diff) = std::env::var("CODEX_STARTING_DIFF") {
|
||||
if !diff.is_empty() {
|
||||
input_items.push(serde_json::json!({
|
||||
"type": "pre_apply_patch",
|
||||
"output_diff": { "diff": diff }
|
||||
}));
|
||||
}
|
||||
if let Ok(diff) = std::env::var("CODEX_STARTING_DIFF")
|
||||
&& !diff.is_empty()
|
||||
{
|
||||
input_items.push(serde_json::json!({
|
||||
"type": "pre_apply_patch",
|
||||
"output_diff": { "diff": diff }
|
||||
}));
|
||||
}
|
||||
|
||||
let request_body = serde_json::json!({
|
||||
|
||||
@@ -174,38 +174,38 @@ fn get_git_origins() -> Vec<String> {
|
||||
let out = std::process::Command::new("git")
|
||||
.args(["config", "--get-regexp", "remote\\..*\\.url"])
|
||||
.output();
|
||||
if let Ok(ok) = out {
|
||||
if ok.status.success() {
|
||||
let s = String::from_utf8_lossy(&ok.stdout);
|
||||
let mut urls = Vec::new();
|
||||
for line in s.lines() {
|
||||
if let Some((_, url)) = line.split_once(' ') {
|
||||
urls.push(url.trim().to_string());
|
||||
}
|
||||
}
|
||||
if !urls.is_empty() {
|
||||
return uniq(urls);
|
||||
if let Ok(ok) = out
|
||||
&& ok.status.success()
|
||||
{
|
||||
let s = String::from_utf8_lossy(&ok.stdout);
|
||||
let mut urls = Vec::new();
|
||||
for line in s.lines() {
|
||||
if let Some((_, url)) = line.split_once(' ') {
|
||||
urls.push(url.trim().to_string());
|
||||
}
|
||||
}
|
||||
if !urls.is_empty() {
|
||||
return uniq(urls);
|
||||
}
|
||||
}
|
||||
// Fallback: git remote -v
|
||||
let out = std::process::Command::new("git")
|
||||
.args(["remote", "-v"])
|
||||
.output();
|
||||
if let Ok(ok) = out {
|
||||
if ok.status.success() {
|
||||
let s = String::from_utf8_lossy(&ok.stdout);
|
||||
let mut urls = Vec::new();
|
||||
for line in s.lines() {
|
||||
let parts: Vec<&str> = line.split_whitespace().collect();
|
||||
if parts.len() >= 2 {
|
||||
urls.push(parts[1].to_string());
|
||||
}
|
||||
}
|
||||
if !urls.is_empty() {
|
||||
return uniq(urls);
|
||||
if let Ok(ok) = out
|
||||
&& ok.status.success()
|
||||
{
|
||||
let s = String::from_utf8_lossy(&ok.stdout);
|
||||
let mut urls = Vec::new();
|
||||
for line in s.lines() {
|
||||
let parts: Vec<&str> = line.split_whitespace().collect();
|
||||
if parts.len() >= 2 {
|
||||
urls.push(parts[1].to_string());
|
||||
}
|
||||
}
|
||||
if !urls.is_empty() {
|
||||
return uniq(urls);
|
||||
}
|
||||
}
|
||||
Vec::new()
|
||||
}
|
||||
|
||||
@@ -29,47 +29,7 @@ pub(crate) fn append_error_log(message: impl AsRef<str>) {
|
||||
}
|
||||
}
|
||||
|
||||
/// Summarize a unified or codex-style patch into counts for UI display.
|
||||
fn summarize_diff(patch: &str) -> codex_cloud_tasks_api::DiffSummary {
|
||||
// Count +/- lines via simple prefix scan (skip headers)
|
||||
let (mut adds, mut dels) = (0usize, 0usize);
|
||||
for line in patch.lines() {
|
||||
if line.starts_with("+++") || line.starts_with("---") || line.starts_with("@@") {
|
||||
continue;
|
||||
}
|
||||
match line.as_bytes().first().copied() {
|
||||
Some(b'+') => adds += 1,
|
||||
Some(b'-') => dels += 1,
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
// Count files: prefer codex patch file ops, else git diff headers, else infer 1 if any changes.
|
||||
let mut files = 0usize;
|
||||
for line in patch.lines() {
|
||||
if line.starts_with("*** Add File:")
|
||||
|| line.starts_with("*** Update File:")
|
||||
|| line.starts_with("*** Delete File:")
|
||||
{
|
||||
files += 1;
|
||||
}
|
||||
}
|
||||
if files == 0 {
|
||||
files = patch
|
||||
.lines()
|
||||
.filter(|l| l.starts_with("diff --git "))
|
||||
.count();
|
||||
}
|
||||
if files == 0 && (adds > 0 || dels > 0) {
|
||||
files = 1;
|
||||
}
|
||||
|
||||
codex_cloud_tasks_api::DiffSummary {
|
||||
files_changed: files,
|
||||
lines_added: adds,
|
||||
lines_removed: dels,
|
||||
}
|
||||
}
|
||||
// (no standalone patch summarizer needed – UI displays raw diffs)
|
||||
|
||||
/// Entry point for the `codex cloud-tasks` subcommand.
|
||||
pub async fn run_main(_cli: Cli, _codex_linux_sandbox_exe: Option<PathBuf>) -> anyhow::Result<()> {
|
||||
@@ -211,7 +171,7 @@ pub async fn run_main(_cli: Cli, _codex_linux_sandbox_exe: Option<PathBuf>) -> a
|
||||
// New list generation; reset background enrichment coordination
|
||||
app.list_generation = app.list_generation.saturating_add(1);
|
||||
app.in_flight.clear();
|
||||
app.no_diff_yet.clear();
|
||||
// reset any in-flight enrichment state
|
||||
|
||||
// Event stream
|
||||
use crossterm::event::Event;
|
||||
@@ -266,21 +226,22 @@ pub async fn run_main(_cli: Cli, _codex_linux_sandbox_exe: Option<PathBuf>) -> a
|
||||
codex_login::AuthMode::ChatGPT,
|
||||
"codex_cloud_tasks_tui".to_string(),
|
||||
);
|
||||
if let Some(auth) = am.auth() {
|
||||
if let Ok(tok) = auth.get_token().await && !tok.is_empty() {
|
||||
let v = format!("Bearer {tok}");
|
||||
if let Ok(hv) = reqwest::header::HeaderValue::from_str(&v) {
|
||||
headers.insert(reqwest::header::AUTHORIZATION, hv);
|
||||
}
|
||||
if let Some(acc) = auth
|
||||
.get_account_id()
|
||||
.or_else(|| extract_chatgpt_account_id(&tok))
|
||||
&& let Ok(name) =
|
||||
reqwest::header::HeaderName::from_bytes(b"ChatGPT-Account-Id")
|
||||
&& let Ok(hv) = reqwest::header::HeaderValue::from_str(&acc)
|
||||
{
|
||||
headers.insert(name, hv);
|
||||
}
|
||||
if let Some(auth) = am.auth()
|
||||
&& let Ok(tok) = auth.get_token().await
|
||||
&& !tok.is_empty()
|
||||
{
|
||||
let v = format!("Bearer {tok}");
|
||||
if let Ok(hv) = reqwest::header::HeaderValue::from_str(&v) {
|
||||
headers.insert(reqwest::header::AUTHORIZATION, hv);
|
||||
}
|
||||
if let Some(acc) = auth
|
||||
.get_account_id()
|
||||
.or_else(|| extract_chatgpt_account_id(&tok))
|
||||
&& let Ok(name) =
|
||||
reqwest::header::HeaderName::from_bytes(b"ChatGPT-Account-Id")
|
||||
&& let Ok(hv) = reqwest::header::HeaderValue::from_str(&acc)
|
||||
{
|
||||
headers.insert(name, hv);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -322,22 +283,23 @@ pub async fn run_main(_cli: Cli, _codex_linux_sandbox_exe: Option<PathBuf>) -> a
|
||||
codex_login::AuthMode::ChatGPT,
|
||||
"codex_cloud_tasks_tui".to_string(),
|
||||
);
|
||||
if let Some(auth) = am.auth() {
|
||||
if let Ok(token) = auth.get_token().await && !token.is_empty() {
|
||||
if let Ok(hv) =
|
||||
reqwest::header::HeaderValue::from_str(&format!("Bearer {token}"))
|
||||
{
|
||||
headers.insert(reqwest::header::AUTHORIZATION, hv);
|
||||
}
|
||||
if let Some(account_id) = auth
|
||||
.get_account_id()
|
||||
.or_else(|| extract_chatgpt_account_id(&token))
|
||||
&& let Ok(name) =
|
||||
reqwest::header::HeaderName::from_bytes(b"ChatGPT-Account-Id")
|
||||
&& let Ok(hv) = reqwest::header::HeaderValue::from_str(&account_id)
|
||||
{
|
||||
headers.insert(name, hv);
|
||||
}
|
||||
if let Some(auth) = am.auth()
|
||||
&& let Ok(token) = auth.get_token().await
|
||||
&& !token.is_empty()
|
||||
{
|
||||
if let Ok(hv) =
|
||||
reqwest::header::HeaderValue::from_str(&format!("Bearer {token}"))
|
||||
{
|
||||
headers.insert(reqwest::header::AUTHORIZATION, hv);
|
||||
}
|
||||
if let Some(account_id) = auth
|
||||
.get_account_id()
|
||||
.or_else(|| extract_chatgpt_account_id(&token))
|
||||
&& let Ok(name) =
|
||||
reqwest::header::HeaderName::from_bytes(b"ChatGPT-Account-Id")
|
||||
&& let Ok(hv) = reqwest::header::HeaderValue::from_str(&account_id)
|
||||
{
|
||||
headers.insert(name, hv);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -388,7 +350,7 @@ pub async fn run_main(_cli: Cli, _codex_linux_sandbox_exe: Option<PathBuf>) -> a
|
||||
let _ = frame_tx.send(Instant::now());
|
||||
|
||||
// Render helper to centralize immediate redraws after handling events.
|
||||
let mut render_if_needed = |terminal: &mut Terminal<CrosstermBackend<std::io::Stdout>>,
|
||||
let render_if_needed = |terminal: &mut Terminal<CrosstermBackend<std::io::Stdout>>,
|
||||
app: &mut app::App,
|
||||
needs_redraw: &mut bool|
|
||||
-> anyhow::Result<()> {
|
||||
@@ -480,22 +442,12 @@ pub async fn run_main(_cli: Cli, _codex_linux_sandbox_exe: Option<PathBuf>) -> a
|
||||
}
|
||||
}
|
||||
}
|
||||
app::AppEvent::TaskSummaryUpdated { generation, id, summary, no_diff_yet, environment_id: _ } => {
|
||||
// Ignore stale generations
|
||||
if generation != app.list_generation { continue; }
|
||||
let id_str = id.0.clone();
|
||||
if let Some(t) = app.tasks.iter_mut().find(|t| t.id.0 == id_str) {
|
||||
t.summary = summary.clone();
|
||||
}
|
||||
app.summary_cache.insert(id_str.clone(), (summary, std::time::Instant::now()));
|
||||
if no_diff_yet { app.no_diff_yet.insert(id_str); } else { app.no_diff_yet.remove(&id.0); }
|
||||
needs_redraw = true;
|
||||
let _ = frame_tx.send(Instant::now());
|
||||
}
|
||||
// (removed TaskSummaryUpdated; unused in this prototype)
|
||||
app::AppEvent::ApplyPreflightFinished { id, title, message, level, skipped, conflicts } => {
|
||||
// Only update if modal is still open and ids match
|
||||
if let Some(m) = app.apply_modal.as_mut() {
|
||||
if m.task_id == id {
|
||||
if let Some(m) = app.apply_modal.as_mut()
|
||||
&& m.task_id == id
|
||||
{
|
||||
m.title = title;
|
||||
m.result_message = Some(message);
|
||||
m.result_level = Some(level);
|
||||
@@ -504,7 +456,6 @@ pub async fn run_main(_cli: Cli, _codex_linux_sandbox_exe: Option<PathBuf>) -> a
|
||||
app.apply_preflight_inflight = false;
|
||||
needs_redraw = true;
|
||||
let _ = frame_tx.send(Instant::now());
|
||||
}
|
||||
}
|
||||
}
|
||||
app::AppEvent::EnvironmentsLoaded(result) => {
|
||||
@@ -543,7 +494,7 @@ pub async fn run_main(_cli: Cli, _codex_linux_sandbox_exe: Option<PathBuf>) -> a
|
||||
app.refresh_inflight = true;
|
||||
app.list_generation = app.list_generation.saturating_add(1);
|
||||
app.in_flight.clear();
|
||||
app.no_diff_yet.clear();
|
||||
// reset spinner state
|
||||
needs_redraw = true;
|
||||
let backend2 = backend.clone();
|
||||
let tx2 = tx.clone();
|
||||
@@ -571,15 +522,16 @@ pub async fn run_main(_cli: Cli, _codex_linux_sandbox_exe: Option<PathBuf>) -> a
|
||||
codex_login::AuthMode::ChatGPT,
|
||||
"codex_cloud_tasks_tui".to_string(),
|
||||
);
|
||||
if let Some(auth) = am.auth() {
|
||||
if let Ok(tok) = auth.get_token().await && !tok.is_empty() {
|
||||
let v = format!("Bearer {tok}");
|
||||
if let Ok(hv) = reqwest::header::HeaderValue::from_str(&v) { headers.insert(reqwest::header::AUTHORIZATION, hv); }
|
||||
if let Some(acc) = auth.get_account_id().or_else(|| extract_chatgpt_account_id(&tok))
|
||||
&& let Ok(name) = reqwest::header::HeaderName::from_bytes(b"ChatGPT-Account-Id")
|
||||
&& let Ok(hv) = reqwest::header::HeaderValue::from_str(&acc) {
|
||||
headers.insert(name, hv);
|
||||
}
|
||||
if let Some(auth) = am.auth()
|
||||
&& let Ok(tok) = auth.get_token().await
|
||||
&& !tok.is_empty()
|
||||
{
|
||||
let v = format!("Bearer {tok}");
|
||||
if let Ok(hv) = reqwest::header::HeaderValue::from_str(&v) { headers.insert(reqwest::header::AUTHORIZATION, hv); }
|
||||
if let Some(acc) = auth.get_account_id().or_else(|| extract_chatgpt_account_id(&tok))
|
||||
&& let Ok(name) = reqwest::header::HeaderName::from_bytes(b"ChatGPT-Account-Id")
|
||||
&& let Ok(hv) = reqwest::header::HeaderValue::from_str(&acc) {
|
||||
headers.insert(name, hv);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -593,7 +545,7 @@ pub async fn run_main(_cli: Cli, _codex_linux_sandbox_exe: Option<PathBuf>) -> a
|
||||
}
|
||||
app::AppEvent::DetailsDiffLoaded { id, title, diff } => {
|
||||
// Only update if the overlay still corresponds to this id.
|
||||
if let Some(ov) = &app.diff_overlay { if ov.task_id != id { continue; } }
|
||||
if let Some(ov) = &app.diff_overlay && ov.task_id != id { continue; }
|
||||
let mut sd = crate::scrollable_diff::ScrollableDiff::new();
|
||||
sd.set_content(diff.lines().map(|s| s.to_string()).collect());
|
||||
app.diff_overlay = Some(app::DiffOverlay{ title, task_id: id, sd, can_apply: true });
|
||||
@@ -602,7 +554,7 @@ pub async fn run_main(_cli: Cli, _codex_linux_sandbox_exe: Option<PathBuf>) -> a
|
||||
needs_redraw = true;
|
||||
}
|
||||
app::AppEvent::DetailsMessagesLoaded { id, title, messages } => {
|
||||
if let Some(ov) = &app.diff_overlay { if ov.task_id != id { continue; } }
|
||||
if let Some(ov) = &app.diff_overlay && ov.task_id != id { continue; }
|
||||
let mut lines = Vec::new();
|
||||
for m in messages { lines.extend(m.lines().map(|s| s.to_string())); lines.push(String::new()); }
|
||||
if lines.is_empty() { lines.push("<no output>".to_string()); }
|
||||
@@ -614,7 +566,7 @@ pub async fn run_main(_cli: Cli, _codex_linux_sandbox_exe: Option<PathBuf>) -> a
|
||||
needs_redraw = true;
|
||||
}
|
||||
app::AppEvent::DetailsFailed { id, title, error } => {
|
||||
if let Some(ov) = &app.diff_overlay { if ov.task_id != id { continue; } }
|
||||
if let Some(ov) = &app.diff_overlay && ov.task_id != id { continue; }
|
||||
append_error_log(format!("details failed for {}: {error}", id.0));
|
||||
let pretty = pretty_lines_from_error(&error);
|
||||
let mut sd = crate::scrollable_diff::ScrollableDiff::new();
|
||||
@@ -777,7 +729,6 @@ pub async fn run_main(_cli: Cli, _codex_linux_sandbox_exe: Option<PathBuf>) -> a
|
||||
KeyCode::Char('y') => {
|
||||
if let Some(m) = app.apply_modal.take() {
|
||||
app.status = format!("Applying '{}'...", m.title);
|
||||
needs_redraw = true;
|
||||
match codex_cloud_tasks_api::CloudBackend::apply_task(&*backend, m.task_id.clone()).await {
|
||||
Ok(outcome) => {
|
||||
app.status = outcome.message.clone();
|
||||
@@ -791,7 +742,6 @@ pub async fn run_main(_cli: Cli, _codex_linux_sandbox_exe: Option<PathBuf>) -> a
|
||||
app.status = format!("Apply failed: {e}");
|
||||
}
|
||||
}
|
||||
needs_redraw = true;
|
||||
}
|
||||
}
|
||||
KeyCode::Char('p') => {
|
||||
@@ -990,7 +940,7 @@ pub async fn run_main(_cli: Cli, _codex_linux_sandbox_exe: Option<PathBuf>) -> a
|
||||
// Resolve selection over filtered set
|
||||
if let Some(state) = app.env_modal.take() {
|
||||
let q = state.query.to_lowercase();
|
||||
let mut filtered: Vec<&app::EnvironmentRow> = app.environments.iter().filter(|r| {
|
||||
let filtered: Vec<&app::EnvironmentRow> = app.environments.iter().filter(|r| {
|
||||
if q.is_empty() { return true; }
|
||||
let mut hay = String::new();
|
||||
if let Some(l) = &r.label { hay.push_str(&l.to_lowercase()); hay.push(' '); }
|
||||
@@ -1021,7 +971,7 @@ pub async fn run_main(_cli: Cli, _codex_linux_sandbox_exe: Option<PathBuf>) -> a
|
||||
app.refresh_inflight = true;
|
||||
app.list_generation = app.list_generation.saturating_add(1);
|
||||
app.in_flight.clear();
|
||||
app.no_diff_yet.clear();
|
||||
// reset spinner state
|
||||
needs_redraw = true;
|
||||
let backend2 = backend.clone();
|
||||
let tx2 = tx.clone();
|
||||
@@ -1059,7 +1009,7 @@ pub async fn run_main(_cli: Cli, _codex_linux_sandbox_exe: Option<PathBuf>) -> a
|
||||
app.refresh_inflight = true;
|
||||
app.list_generation = app.list_generation.saturating_add(1);
|
||||
app.in_flight.clear();
|
||||
app.no_diff_yet.clear();
|
||||
// reset spinner state
|
||||
needs_redraw = true;
|
||||
// Spawn background refresh
|
||||
let backend2 = backend.clone();
|
||||
@@ -1251,8 +1201,9 @@ fn pretty_lines_from_error(raw: &str) -> Vec<String> {
|
||||
}
|
||||
|
||||
// Try to parse the embedded JSON body: find the first '{' after " body=" and decode.
|
||||
if let Some(body_idx) = raw.find(" body=") {
|
||||
if let Some(json_start_rel) = raw[body_idx..].find('{') {
|
||||
if let Some(body_idx) = raw.find(" body=")
|
||||
&& let Some(json_start_rel) = raw[body_idx..].find('{')
|
||||
{
|
||||
let json_start = body_idx + json_start_rel;
|
||||
let json_str = raw[json_start..].trim();
|
||||
if let Ok(v) = serde_json::from_str::<serde_json::Value>(json_str) {
|
||||
@@ -1288,15 +1239,13 @@ fn pretty_lines_from_error(raw: &str) -> Vec<String> {
|
||||
.get("latest_event")
|
||||
.and_then(|e| e.get("text"))
|
||||
.and_then(|s| s.as_str())
|
||||
&& !text.trim().is_empty()
|
||||
{
|
||||
if !text.trim().is_empty() {
|
||||
lines.push(format!("Latest event: {}", text.trim()));
|
||||
}
|
||||
lines.push(format!("Latest event: {}", text.trim()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if lines.len() == 1 {
|
||||
// Parsing yielded nothing; include a trimmed, short raw message tail for context.
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
use codex_tui::ComposerAction;
|
||||
use codex_tui::ComposerInput;
|
||||
|
||||
#[derive(Default)]
|
||||
@@ -24,7 +23,5 @@ impl NewTaskPage {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn can_submit(&self) -> bool {
|
||||
self.env_id.is_some() && !self.submitting
|
||||
}
|
||||
// Additional helpers can be added as usage evolves.
|
||||
}
|
||||
|
||||
@@ -144,15 +144,11 @@ impl ScrollableDiff {
|
||||
out.push(prefix.trim_end().to_string());
|
||||
out_idx.push(raw_idx);
|
||||
line = rest.trim_start().to_string();
|
||||
line_cols = UnicodeWidthStr::width(line.as_str());
|
||||
last_soft_idx = None;
|
||||
// retry add current ch now that line may be shorter
|
||||
} else {
|
||||
if !line.is_empty() {
|
||||
out.push(std::mem::take(&mut line));
|
||||
out_idx.push(raw_idx);
|
||||
line_cols = 0;
|
||||
}
|
||||
} else if !line.is_empty() {
|
||||
out.push(std::mem::take(&mut line));
|
||||
out_idx.push(raw_idx);
|
||||
}
|
||||
}
|
||||
if ch.is_whitespace()
|
||||
|
||||
@@ -150,10 +150,10 @@ pub fn draw_new_task_page(frame: &mut Frame, area: Rect, app: &mut App) {
|
||||
}
|
||||
|
||||
// Place cursor where composer wants it
|
||||
if let Some(page) = app.new_task.as_ref() {
|
||||
if let Some((x, y)) = page.composer.cursor_pos(composer_area) {
|
||||
frame.set_cursor_position((x, y));
|
||||
}
|
||||
if let Some(page) = app.new_task.as_ref()
|
||||
&& let Some((x, y)) = page.composer.cursor_pos(composer_area)
|
||||
{
|
||||
frame.set_cursor_position((x, y));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -627,22 +627,7 @@ fn draw_centered_spinner(
|
||||
draw_inline_spinner(frame, cols[1], state, label);
|
||||
}
|
||||
|
||||
fn style_diff_fragment(src_line: &str, fragment: &str) -> Line<'static> {
|
||||
if src_line.starts_with("@@") {
|
||||
return Line::from(fragment.to_string().magenta().bold());
|
||||
}
|
||||
if src_line.starts_with("diff --git ") || src_line.starts_with("index ") {
|
||||
return Line::from(fragment.to_string().dim());
|
||||
}
|
||||
if src_line.starts_with("+++") || src_line.starts_with("---") {
|
||||
return Line::from(fragment.to_string().dim());
|
||||
}
|
||||
match src_line.as_bytes().first().copied() {
|
||||
Some(b'+') => Line::from(fragment.to_string().green()),
|
||||
Some(b'-') => Line::from(fragment.to_string().red()),
|
||||
_ => Line::from(fragment.to_string()),
|
||||
}
|
||||
}
|
||||
// Styling helpers for diff rendering live inline where used.
|
||||
|
||||
pub fn draw_env_modal(frame: &mut Frame, area: Rect, app: &mut App) {
|
||||
use ratatui::widgets::Wrap;
|
||||
|
||||
Reference in New Issue
Block a user