mirror of
https://github.com/openai/codex.git
synced 2026-10-19 17:28:46 +00:00
## Description This PR moves review-mode markers onto canonical `TurnItem` lifecycle: - `TurnItem::EnteredReviewMode` - `TurnItem::ExitedReviewMode` Core now emits `ItemStarted` / `ItemCompleted` for both. The completed items map back into the existing `EnteredReviewMode` / `ExitedReviewMode` events, so raw core event consumers and legacy rollout persistence keep seeing the old events. This is the compatibility layer needed before paginated rollouts persist review markers as `ItemCompleted(TurnItem)`. ## Why Review markers were one of the remaining app-server thread items created directly from legacy events. Giving them canonical items lets paginated history persist stable turn/item IDs without changing legacy rollouts. ## What changed - Added canonical review-mode `TurnItem`s and switched review flow to emit their lifecycle. - Added completed-item → legacy review event mappings with stable turn/item IDs. - Switched app-server live notifications to the generic canonical item path and kept legacy replay compatible with old payloads. - Updated `ThreadHistoryBuilder` to replay canonical review items even though review turns still do not emit `TurnStarted`.
83 lines
2.8 KiB
Rust
83 lines
2.8 KiB
Rust
use crate::protocol::ReviewFinding;
|
|
use crate::protocol::ReviewOutputEvent;
|
|
|
|
// These helpers return plain strings that higher layers may style as needed.
|
|
|
|
fn format_location(item: &ReviewFinding) -> String {
|
|
let path = item.code_location.absolute_file_path.display();
|
|
let start = item.code_location.line_range.start;
|
|
let end = item.code_location.line_range.end;
|
|
format!("{path}:{start}-{end}")
|
|
}
|
|
|
|
/// Fallback text used when a review contains no displayable output.
|
|
pub const REVIEW_FALLBACK_MESSAGE: &str = "Reviewer failed to output a response.";
|
|
|
|
/// Format a full review findings block as plain text lines.
|
|
///
|
|
/// - When `selection` is `Some`, each item line includes a checkbox marker:
|
|
/// "[x]" for selected items and "[ ]" for unselected. Missing indices
|
|
/// default to selected.
|
|
/// - When `selection` is `None`, the marker is omitted and a simple bullet is
|
|
/// rendered ("- Title — path:start-end").
|
|
pub fn format_review_findings_block(
|
|
findings: &[ReviewFinding],
|
|
selection: Option<&[bool]>,
|
|
) -> String {
|
|
let mut lines: Vec<String> = Vec::new();
|
|
lines.push(String::new());
|
|
|
|
// Header
|
|
if findings.len() > 1 {
|
|
lines.push("Full review comments:".to_string());
|
|
} else {
|
|
lines.push("Review comment:".to_string());
|
|
}
|
|
|
|
for (idx, item) in findings.iter().enumerate() {
|
|
lines.push(String::new());
|
|
|
|
let title = &item.title;
|
|
let location = format_location(item);
|
|
|
|
if let Some(flags) = selection {
|
|
// Default to selected if index is out of bounds.
|
|
let checked = flags.get(idx).copied().unwrap_or(true);
|
|
let marker = if checked { "[x]" } else { "[ ]" };
|
|
lines.push(format!("- {marker} {title} — {location}"));
|
|
} else {
|
|
lines.push(format!("- {title} — {location}"));
|
|
}
|
|
|
|
for body_line in item.body.lines() {
|
|
lines.push(format!(" {body_line}"));
|
|
}
|
|
}
|
|
|
|
lines.join("\n")
|
|
}
|
|
|
|
/// Render a human-readable review summary suitable for a user-facing message.
|
|
///
|
|
/// Returns either the explanation, the formatted findings block, or both
|
|
/// separated by a blank line. If neither is present, emits a fallback message.
|
|
pub fn render_review_output_text(output: &ReviewOutputEvent) -> String {
|
|
let mut sections = Vec::new();
|
|
let explanation = output.overall_explanation.trim();
|
|
if !explanation.is_empty() {
|
|
sections.push(explanation.to_string());
|
|
}
|
|
if !output.findings.is_empty() {
|
|
let findings = format_review_findings_block(&output.findings, /*selection*/ None);
|
|
let trimmed = findings.trim();
|
|
if !trimmed.is_empty() {
|
|
sections.push(trimmed.to_string());
|
|
}
|
|
}
|
|
if sections.is_empty() {
|
|
REVIEW_FALLBACK_MESSAGE.to_string()
|
|
} else {
|
|
sections.join("\n\n")
|
|
}
|
|
}
|