[feedback] diagnostics (#13292)

- added header logic to display diagnostics on cli
- added logic for collecting env vars

<img width="606" height="327" alt="Screenshot 2026-03-03 at 3 49 31 PM"
src="https://github.com/user-attachments/assets/05e78c56-8cb3-47fa-abaf-3e57f1fdd8e2"
/>

<img width="690" height="353" alt="Screenshot 2026-03-02 at 6 47 54 PM"
src="https://github.com/user-attachments/assets/e470b559-13f4-44d9-897f-bc398943c6d1"
/>
This commit is contained in:
rhan-oai authored and GitHub committed 2026-03-03 16:34:11 -08:00
1 parent 082682a628
commit e951ef4374
10 files changed
+586 -41

No files matched your search

+143 -19
View File
@@ -1,6 +1,8 @@
use std::cell::RefCell;
use std::path::PathBuf;
use codex_feedback::feedback_diagnostics::FEEDBACK_DIAGNOSTICS_ATTACHMENT_FILENAME;
use codex_feedback::feedback_diagnostics::FeedbackDiagnostics;
use crossterm::event::KeyCode;
use crossterm::event::KeyEvent;
use crossterm::event::KeyModifiers;
@@ -19,6 +21,8 @@ use crate::app_event::FeedbackCategory;
use crate::app_event_sender::AppEventSender;
use crate::history_cell;
use crate::render::renderable::Renderable;
use crate::wrapping::RtOptions;
use crate::wrapping::word_wrap_lines;
use codex_protocol::protocol::SessionSource;
use super::CancellationEvent;
@@ -46,7 +50,7 @@ pub(crate) enum FeedbackAudience {
/// both logs and rollout with classification + metadata.
pub(crate) struct FeedbackNoteView {
category: FeedbackCategory,
snapshot: codex_feedback::CodexLogSnapshot,
snapshot: codex_feedback::FeedbackSnapshot,
rollout_path: Option<PathBuf>,
app_event_tx: AppEventSender,
include_logs: bool,
@@ -61,7 +65,7 @@ pub(crate) struct FeedbackNoteView {
impl FeedbackNoteView {
pub(crate) fn new(
category: FeedbackCategory,
snapshot: codex_feedback::CodexLogSnapshot,
snapshot: codex_feedback::FeedbackSnapshot,
rollout_path: Option<PathBuf>,
app_event_tx: AppEventSender,
include_logs: bool,
@@ -87,7 +91,7 @@ impl FeedbackNoteView {
} else {
Some(note.as_str())
};
let log_file_paths = if self.include_logs {
let attachment_paths = if self.include_logs {
self.rollout_path.iter().cloned().collect::<Vec<_>>()
} else {
Vec::new()
@@ -100,7 +104,7 @@ impl FeedbackNoteView {
classification,
reason_opt,
self.include_logs,
&log_file_paths,
&attachment_paths,
Some(SessionSource::Cli),
None,
);
@@ -217,21 +221,21 @@ impl BottomPaneView for FeedbackNoteView {
impl Renderable for FeedbackNoteView {
fn desired_height(&self, width: u16) -> u16 {
1u16 + self.input_height(width) + 3u16
self.intro_lines(width).len() as u16 + self.input_height(width) + 2u16
}
fn cursor_pos(&self, area: Rect) -> Option<(u16, u16)> {
if area.height < 2 || area.width <= 2 {
return None;
}
let intro_height = self.intro_lines(area.width).len() as u16;
let text_area_height = self.input_height(area.width).saturating_sub(1);
if text_area_height == 0 {
return None;
}
let top_line_count = 1u16; // title only
let textarea_rect = Rect {
x: area.x.saturating_add(2),
y: area.y.saturating_add(top_line_count).saturating_add(1),
y: area.y.saturating_add(intro_height).saturating_add(1),
width: area.width.saturating_sub(2),
height: text_area_height,
};
@@ -244,23 +248,26 @@ impl Renderable for FeedbackNoteView {
return;
}
let (title, placeholder) = feedback_title_and_placeholder(self.category);
let intro_lines = self.intro_lines(area.width);
let (_, placeholder) = feedback_title_and_placeholder(self.category);
let input_height = self.input_height(area.width);
// Title line
let title_area = Rect {
x: area.x,
y: area.y,
width: area.width,
height: 1,
};
let title_spans: Vec<Span<'static>> = vec![gutter(), title.bold()];
Paragraph::new(Line::from(title_spans)).render(title_area, buf);
for (offset, line) in intro_lines.iter().enumerate() {
Paragraph::new(line.clone()).render(
Rect {
x: area.x,
y: area.y.saturating_add(offset as u16),
width: area.width,
height: 1,
},
buf,
);
}
// Input line
let input_area = Rect {
x: area.x,
y: area.y.saturating_add(1),
y: area.y.saturating_add(intro_lines.len() as u16),
width: area.width,
height: input_height,
};
@@ -334,6 +341,56 @@ impl FeedbackNoteView {
let text_height = self.textarea.desired_height(usable_width).clamp(1, 8);
text_height.saturating_add(1).min(9)
}
fn intro_lines(&self, width: u16) -> Vec<Line<'static>> {
let (title, _) = feedback_title_and_placeholder(self.category);
let mut lines = vec![Line::from(vec![gutter(), title.bold()])];
if should_show_feedback_connectivity_details(
self.category,
self.snapshot.feedback_diagnostics(),
) {
lines.push(Line::from(vec![gutter()]));
lines.push(Line::from(vec![
gutter(),
"Connectivity diagnostics".bold(),
]));
lines.extend(self.diagnostics_lines(width));
}
lines
}
fn diagnostics_lines(&self, width: u16) -> Vec<Line<'static>> {
let width = usize::from(width.max(1));
let headline_options = RtOptions::new(width)
.initial_indent(Line::from(vec![gutter(), " - ".into()]))
.subsequent_indent(Line::from(vec![gutter(), " ".into()]));
let detail_options = RtOptions::new(width)
.initial_indent(Line::from(vec![gutter(), " - ".dim()]))
.subsequent_indent(Line::from(vec![gutter(), " ".into()]));
let mut lines = Vec::new();
for diagnostic in self.snapshot.feedback_diagnostics().diagnostics() {
lines.extend(word_wrap_lines(
[Line::from(diagnostic.headline.clone())],
headline_options.clone(),
));
for detail in &diagnostic.details {
lines.extend(word_wrap_lines(
[Line::from(detail.clone())],
detail_options.clone(),
));
}
}
lines
}
}
pub(crate) fn should_show_feedback_connectivity_details(
category: FeedbackCategory,
diagnostics: &FeedbackDiagnostics,
) -> bool {
category != FeedbackCategory::GoodResult && !diagnostics.is_empty()
}
fn gutter() -> Span<'static> {
@@ -485,6 +542,7 @@ pub(crate) fn feedback_upload_consent_params(
app_event_tx: AppEventSender,
category: FeedbackCategory,
rollout_path: Option<std::path::PathBuf>,
include_connectivity_diagnostics_attachment: bool,
) -> super::SelectionViewParams {
use super::popup_consts::standard_popup_hint_line;
let yes_action: super::SelectionAction = Box::new({
@@ -521,6 +579,15 @@ pub(crate) fn feedback_upload_consent_params(
{
header_lines.push(Line::from(vec![" • ".into(), name.into()]).into());
}
if include_connectivity_diagnostics_attachment {
header_lines.push(
Line::from(vec![
" • ".into(),
FEEDBACK_DIAGNOSTICS_ATTACHMENT_FILENAME.into(),
])
.into(),
);
}
super::SelectionViewParams {
footer_hint: Some(standard_popup_hint_line()),
@@ -537,7 +604,6 @@ pub(crate) fn feedback_upload_consent_params(
},
super::SelectionItem {
name: "No".to_string(),
description: Some("".to_string()),
actions: vec![no_action],
dismiss_on_select: true,
..Default::default()
@@ -555,6 +621,8 @@ mod tests {
use super::*;
use crate::app_event::AppEvent;
use crate::app_event_sender::AppEventSender;
use codex_feedback::feedback_diagnostics::FeedbackDiagnostic;
use pretty_assertions::assert_eq;
fn render(view: &FeedbackNoteView, width: u16) -> String {
let height = view.desired_height(width);
@@ -635,6 +703,62 @@ mod tests {
insta::assert_snapshot!("feedback_view_safety_check", rendered);
}
#[test]
fn feedback_view_with_connectivity_diagnostics() {
let (tx_raw, _rx) = tokio::sync::mpsc::unbounded_channel::<AppEvent>();
let tx = AppEventSender::new(tx_raw);
let diagnostics = FeedbackDiagnostics::new(vec![
FeedbackDiagnostic {
headline: "Proxy environment variables are set and may affect connectivity."
.to_string(),
details: vec!["HTTP_PROXY = http://proxy.example.com:8080".to_string()],
},
FeedbackDiagnostic {
headline: "OPENAI_BASE_URL is set and may affect connectivity.".to_string(),
details: vec!["OPENAI_BASE_URL = https://example.com/v1".to_string()],
},
]);
let snapshot = codex_feedback::CodexFeedback::new()
.snapshot(None)
.with_feedback_diagnostics(diagnostics);
let view = FeedbackNoteView::new(
FeedbackCategory::Bug,
snapshot,
None,
tx,
false,
FeedbackAudience::External,
);
let rendered = render(&view, 60);
insta::assert_snapshot!("feedback_view_with_connectivity_diagnostics", rendered);
}
#[test]
fn should_show_feedback_connectivity_details_only_for_non_good_result_with_diagnostics() {
let diagnostics = FeedbackDiagnostics::new(vec![FeedbackDiagnostic {
headline: "Proxy environment variables are set and may affect connectivity."
.to_string(),
details: vec!["HTTP_PROXY = http://proxy.example.com:8080".to_string()],
}]);
assert_eq!(
should_show_feedback_connectivity_details(FeedbackCategory::Bug, &diagnostics),
true
);
assert_eq!(
should_show_feedback_connectivity_details(FeedbackCategory::GoodResult, &diagnostics),
false
);
assert_eq!(
should_show_feedback_connectivity_details(
FeedbackCategory::BadResult,
&FeedbackDiagnostics::default()
),
false
);
}
#[test]
fn issue_url_available_for_bug_bad_result_safety_check_and_other() {
let bug_url = issue_url_for_category(