Add a persistent /daybreak toggle to the TUI (#49858)

## What changed

- Add `/daybreak` with account-aware help and availability messages for broader access for cybersecurity work.
- Save the selection in thread metadata and the `daybreak` default for new threads, restore it on resume, and confirm that it applies to new turns.
- Select `cyberAccessProgram` from the connected server's model catalog. Require a signed-in ChatGPT account, the OpenAI provider, and confirmed model support when Daybreak is enabled, including for faster-model retries. Keep Daybreak disabled for side conversations.

## Testing

Add tests for toggle persistence, turn access-program selection, unsupported-model rejection, side-conversation behavior, command help, and the resumed-thread banner.

GitOrigin-RevId: e3c028b0a6a8e0a862c16fdc766f374aae618ef1
This commit is contained in:
Eric Traut
2026-10-01 04:17:31 +00:00
committed by copyberry
parent f58ed54a9d
commit e1522188e9
51 changed files with 763 additions and 8 deletions
+1
View File
@@ -217,6 +217,7 @@ mod composer_hints;
mod config_persistence;
mod connector_mentions;
mod daemon_menu;
mod daybreak;
mod empty_state_policy;
mod event_dispatch;
mod exit_summary;
@@ -1895,6 +1895,7 @@ enabled = false
app.chat_widget
.handle_thread_session(crate::session_state::ThreadSessionState {
daybreak_enabled: false,
windows_sandbox_host: crate::app::WindowsSandboxHost::Local,
thread_id: ThreadId::new(),
forked_from_id: None,
+118
View File
@@ -0,0 +1,118 @@
//! Persist the user's Daybreak selection for the active thread and new threads.
use super::*;
impl App {
pub(super) async fn persist_daybreak_selection(
&mut self,
app_server: &mut AppServerSession,
thread_id: ThreadId,
enabled: bool,
) {
if self.active_thread_id != Some(thread_id) {
return;
}
if enabled
&& (!self.chat_widget.has_chatgpt_account()
|| self.chat_widget.config_ref().model_provider_id != "openai"
|| !crate::daybreak::available(&self.chat_widget.model_catalog().models))
{
self.chat_widget.add_error_message(
"Daybreak availability could not be confirmed for this account.".into(),
);
return;
}
match app_server
.thread_read(thread_id, /*include_turns*/ false)
.await
{
Ok(thread) if !thread.ephemeral => {
let request_id = app_server.next_request_id();
let response: Result<codex_app_server_protocol::ThreadMetadataUpdateResponse, _> =
app_server
.request_handle()
.request_typed(ClientRequest::ThreadMetadataUpdate {
request_id,
params: codex_app_server_protocol::ThreadMetadataUpdateParams {
thread_id: thread_id.to_string(),
daybreak_enabled: Some(enabled),
project_id: None,
git_info: None,
},
})
.await;
if let Err(error) = response {
self.chat_widget.add_error_message(format!(
"Failed to save Daybreak for this thread: {error}"
));
return;
}
}
Ok(_) => {}
Err(error) => {
self.chat_widget.add_error_message(format!(
"Failed to read the thread to save Daybreak: {error}"
));
return;
}
}
self.chat_widget.set_daybreak_enabled(enabled);
if self.primary_thread_id == Some(thread_id)
&& let Some(session) = self.primary_session_configured.as_mut()
{
session.daybreak_enabled = enabled;
}
if let Some(channel) = self.thread_event_channels.get(&thread_id) {
let mut store = channel.store.lock().await;
if let Some(session) = store.session.as_mut() {
session.daybreak_enabled = enabled;
}
}
self.refresh_status_line();
let edits = vec![crate::config_update::replace_config_value(
"daybreak",
serde_json::json!(enabled),
)];
match self
.persist_model_defaults(
app_server.request_handle(),
edits,
"default Daybreak preference",
)
.await
{
Ok(()) => match crate::config_update::read_effective_config(
app_server.request_handle(),
self.chat_widget
.config_ref()
.cwd
.to_string_lossy()
.into_owned(),
)
.await
{
Ok(response) => {
self.config.daybreak_enabled = response
.config
.additional
.get("daybreak")
.and_then(serde_json::Value::as_bool)
.unwrap_or(false)
}
Err(error) => self.chat_widget.add_error_message(format!(
"Failed to read the default Daybreak preference: {error}"
)),
},
Err(error) => self.chat_widget.add_error_message(format!(
"Failed to save the default Daybreak preference: {error}"
)),
}
self.chat_widget.add_info_message(
format!(
"Daybreak {}. Applies to new turns.",
if enabled { "on" } else { "off" }
),
/*hint*/ None,
);
}
}
+4
View File
@@ -539,6 +539,7 @@ impl App {
self.refresh_in_memory_config_from_disk_best_effort("forking the thread")
.await;
let mut fork_config = self.config.clone();
fork_config.daybreak_enabled = self.chat_widget.daybreak_enabled;
if app_server.uses_remote_workspace() {
fork_config.workspace_roots.clone_from(
&self.chat_widget.config_ref().workspace_roots,
@@ -2447,6 +2448,9 @@ impl App {
}
}
}
AppEvent::PersistDaybreakSelection { thread_id, enabled } => {
self.persist_daybreak_selection(app_server, thread_id, enabled).await;
}
AppEvent::SelectSessionModel { model, effort } => {
self.app_event_tx.send(AppEvent::FollowTranscript);
self.select_session_model(app_server, model, effort).await;
+7
View File
@@ -40,6 +40,13 @@ pub(super) fn overlay_new_session_defaults(
if !has_launch_setting(config, cli_kv_overrides, "model_reasoning_effort") {
config.model_reasoning_effort = defaults.model_reasoning_effort.clone();
}
if !has_launch_setting(config, cli_kv_overrides, "daybreak") {
config.daybreak_enabled = defaults
.additional
.get("daybreak")
.and_then(serde_json::Value::as_bool)
.unwrap_or(false);
}
}
impl App {
@@ -35,6 +35,7 @@ pub(in crate::app) fn user_cell(message: &str) -> Arc<dyn HistoryCell> {
pub(in crate::app) fn attach_thread(app: &mut App, thread_id: ThreadId) {
app.chat_widget.handle_thread_session(ThreadSessionState {
daybreak_enabled: false,
windows_sandbox_host: crate::app::WindowsSandboxHost::Local,
thread_id,
forked_from_id: None,
+14
View File
@@ -85,6 +85,20 @@ impl App {
.add_error_message(format!("Failed to retry with a faster model: {err}"));
return;
}
let eligible_account = self.chat_widget.has_chatgpt_account()
&& self.chat_widget.config_ref().model_provider_id == "openai";
let daybreak_enabled = self.chat_widget.daybreak_enabled
&& !self.chat_widget.side_conversation_active()
&& !self.side_threads.contains_key(&thread_id);
if let Err(message) = crate::daybreak::program_for_turn(
&self.chat_widget.model_catalog().models,
&model,
eligible_account,
daybreak_enabled,
) {
self.chat_widget.add_error_message(message);
return;
}
*turn_model = model.clone();
*effort = Some(ReasoningEffortConfig::Low);
*collaboration_mode = collaboration_mode.as_ref().map(|mode| {
+1
View File
@@ -631,6 +631,7 @@ impl App {
fork_config.model_reasoning_effort = self.chat_widget.current_reasoning_effort();
fork_config.service_tier = self.chat_widget.configured_service_tier();
fork_config.ephemeral = true;
fork_config.daybreak_enabled = false;
fork_config.developer_instructions = Some(Self::side_developer_instructions(
fork_config.developer_instructions.as_deref(),
));
+11 -1
View File
@@ -4575,6 +4575,7 @@ async fn inactive_thread_started_notification_initializes_replay_session() -> Re
let primary_cwd = test_path_buf("/tmp/main").abs();
let shared_root = test_path_buf("/tmp/shared").abs();
let primary_session = ThreadSessionState {
daybreak_enabled: false,
windows_sandbox_host: WindowsSandboxHost::Local,
approval_policy: AskForApproval::OnRequest,
permission_profile: PermissionProfile::workspace_write(),
@@ -4615,7 +4616,7 @@ async fn inactive_thread_started_notification_initializes_replay_session() -> Re
section: None,
section_entered_at: None,
project_id: None,
daybreak_enabled: None,
daybreak_enabled: Some(true),
history_mode: Default::default(),
model_provider: "agent-provider".to_string(),
model: Some("gpt-agent".to_string()),
@@ -4651,6 +4652,7 @@ async fn inactive_thread_started_notification_initializes_replay_session() -> Re
drop(store);
assert_eq!(session.thread_id, agent_thread_id);
assert!(session.daybreak_enabled);
assert_eq!(session.windows_sandbox_host, WindowsSandboxHost::Remote);
assert_eq!(session.thread_name, Some("agent thread".to_string()));
assert_eq!(session.model, "gpt-agent");
@@ -5255,6 +5257,7 @@ async fn side_thread_snapshot_hides_forked_parent_transcript() {
let side_thread_id = ThreadId::new();
let mut store = ThreadEventStore::new(/*capacity*/ 4);
let session = ThreadSessionState {
daybreak_enabled: false,
windows_sandbox_host: crate::app::WindowsSandboxHost::Local,
forked_from_id: Some(parent_thread_id),
fork_parent_title: None,
@@ -5323,6 +5326,7 @@ async fn side_thread_snapshot_skips_session_header_preamble() {
let snapshot = ThreadEventSnapshot {
delegated_turns: Vec::new(),
session: Some(ThreadSessionState {
daybreak_enabled: false,
windows_sandbox_host: crate::app::WindowsSandboxHost::Local,
forked_from_id: Some(parent_thread_id),
fork_parent_title: None,
@@ -5898,6 +5902,7 @@ async fn render_clear_ui_header_after_long_transcript_for_snapshot() -> String {
};
let make_header = |is_first| -> Arc<dyn HistoryCell> {
let session = ThreadSessionState {
daybreak_enabled: false,
windows_sandbox_host: crate::app::WindowsSandboxHost::Local,
thread_id: ThreadId::new(),
forked_from_id: None,
@@ -6508,6 +6513,7 @@ async fn replace_goal_confirmation_snapshot() {
fn test_thread_session(thread_id: ThreadId, cwd: PathBuf) -> ThreadSessionState {
ThreadSessionState {
daybreak_enabled: false,
windows_sandbox_host: crate::app::WindowsSandboxHost::Local,
thread_id,
forked_from_id: None,
@@ -7607,6 +7613,7 @@ async fn backtrack_selection_preserves_selected_prompt_and_requests_branch() {
let make_header = |is_first| {
let session = ThreadSessionState {
daybreak_enabled: false,
windows_sandbox_host: crate::app::WindowsSandboxHost::Local,
thread_id: ThreadId::new(),
forked_from_id: None,
@@ -7680,6 +7687,7 @@ async fn backtrack_selection_preserves_selected_prompt_and_requests_branch() {
let base_id = ThreadId::new();
app.chat_widget
.handle_thread_session(crate::session_state::ThreadSessionState {
daybreak_enabled: false,
windows_sandbox_host: crate::app::WindowsSandboxHost::Local,
thread_id: base_id,
forked_from_id: None,
@@ -8975,6 +8983,7 @@ async fn new_session_requests_shutdown_for_previous_conversation() {
let thread_id = ThreadId::new();
let event = crate::session_state::ThreadSessionState {
daybreak_enabled: false,
windows_sandbox_host: crate::app::WindowsSandboxHost::Local,
thread_id,
forked_from_id: None,
@@ -9734,6 +9743,7 @@ async fn clear_only_ui_reset_preserves_chat_session_state() {
let thread_id = ThreadId::new();
app.chat_widget
.handle_thread_session(crate::session_state::ThreadSessionState {
daybreak_enabled: false,
windows_sandbox_host: crate::app::WindowsSandboxHost::Local,
thread_id,
forked_from_id: None,
@@ -21,6 +21,7 @@ async fn fork_current_session_preserves_conversation_ultra() -> Result<()> {
.expect("create source rollout"),
)?;
app.chat_widget.handle_thread_session(ThreadSessionState {
daybreak_enabled: false,
windows_sandbox_host: crate::app::WindowsSandboxHost::Local,
model: "gpt-5.4".to_string(),
model_provider_id: app.config.model_provider_id.clone(),
@@ -62,12 +63,14 @@ async fn switching_from_ultra_thread_restores_configured_plan_effort() {
app.chat_widget
.set_feature_enabled(Feature::CollaborationModes, /*enabled*/ true);
let ultra_session = ThreadSessionState {
daybreak_enabled: false,
windows_sandbox_host: crate::app::WindowsSandboxHost::Local,
model: "gpt-5.4".to_string(),
reasoning_effort: Some(ReasoningEffortConfig::Ultra),
..test_thread_session(ThreadId::new(), test_path_buf("/tmp/ultra"))
};
let normal_session = ThreadSessionState {
daybreak_enabled: false,
windows_sandbox_host: crate::app::WindowsSandboxHost::Local,
model: "gpt-5.4".to_string(),
reasoning_effort: Some(ReasoningEffortConfig::Medium),
@@ -5,14 +5,17 @@ use crate::chatwidget::UserMessage;
use crate::chatwidget::tests::helpers::normalize_completion_timestamps;
use codex_app_server_client::AppServerEvent;
use codex_app_server_protocol::ModelSafetyBufferingUpdatedNotification;
use codex_app_server_protocol::ThreadSettingsUpdateParams;
use codex_model_provider_info::ModelProviderInfo;
use codex_protocol::models::ManagedFileSystemPermissions;
use codex_protocol::openai_models::ModelAccessPrograms;
use codex_protocol::openai_models::ToolMode;
use codex_protocol::permissions::FileSystemAccessMode;
use codex_protocol::permissions::FileSystemPath;
use codex_protocol::permissions::FileSystemSandboxEntry;
use codex_protocol::permissions::FileSystemSpecialPath;
use codex_protocol::permissions::NetworkSandboxPolicy;
use codex_protocol::turn_input::CyberAccessProgram;
use codex_utils_absolute_path::test_support::PathExt;
use core_test_support::responses;
use core_test_support::responses::ev_assistant_message;
@@ -528,6 +531,11 @@ async fn run_safety_retry(
.filter(|model| matches!(model.slug.as_str(), CURRENT_MODEL | FASTER_MODEL))
{
model.tool_mode = Some(ToolMode::Direct);
if scenario == SafetyRetryScenario::UnsupportedPermissions && model.slug == FASTER_MODEL {
model.available_access_programs = Some(ModelAccessPrograms {
cyber: vec![CyberAccessProgram::Standard],
});
}
}
let model_catalog_path = codex_home.path().join("models.json");
std::fs::write(&model_catalog_path, serde_json::to_vec(&model_catalog)?)?;
@@ -556,6 +564,16 @@ goals = true
app.config.codex_home = codex_home.path().to_path_buf().abs();
app.config.sqlite = codex_state::SqliteConfig::new_for_testing(codex_home.path().abs());
app.config.model = Some(CURRENT_MODEL.to_string());
if scenario == SafetyRetryScenario::UnsupportedPermissions {
app.model_catalog = Arc::new(ModelCatalog::new(
model_catalog
.models
.iter()
.cloned()
.map(Into::into)
.collect(),
));
}
app.config.model_catalog = Some(model_catalog);
app.config.model_provider_id = MODEL_PROVIDER_ID.to_string();
app.config.model_provider = ModelProviderInfo {
@@ -752,6 +770,53 @@ goals = true
while app_event_rx.try_recv().is_ok() {}
if scenario == SafetyRetryScenario::UnsupportedPermissions {
app_server
.thread_settings_update(ThreadSettingsUpdateParams {
thread_id: source_thread_id.to_string(),
effort: Some(ReasoningEffortConfig::Low),
..Default::default()
})
.await?;
let mut settings = next_thread_settings_updated(&mut app_server, source_thread_id).await;
settings.thread_settings.model_provider = "openai".to_string();
app.chat_widget.on_thread_settings_updated(settings);
app.chat_widget.update_account_state(
/*status_account_display*/ None, /*plan_type*/ None,
/*has_chatgpt_account*/ true, /*has_codex_backend_auth*/ false,
);
app.chat_widget.set_daybreak_enabled(/*enabled*/ true);
Box::pin(app.retry_safety_buffered_turn(
&mut tui,
&mut app_server,
SafetyBufferedRetry {
thread_id: source_thread_id,
turn_id: active_turn_id.clone(),
model: FASTER_MODEL.to_string(),
turn: active_turn.clone(),
prompt: UserMessage::from(RETRY_PROMPT),
},
))
.await;
assert_eq!(app.chat_widget.thread_id(), Some(source_thread_id));
let source = app_server
.thread_read(source_thread_id, /*include_turns*/ true)
.await?;
assert_eq!(
source.turns.last().map(|turn| &turn.status),
Some(&TurnStatus::InProgress)
);
let error_cell = std::iter::from_fn(|| app_event_rx.try_recv().ok())
.find_map(|event| match event {
AppEvent::InsertHistoryCell(cell) => Some(cell),
_ => None,
})
.expect("unsupported Daybreak model should be added to history");
insta::assert_snapshot!(
lines_to_single_string(&error_cell.display_lines(/*width*/ 200)),
@"■ Daybreak support for model gpt-5.6-luna could not be confirmed by the connected server. Use /daybreak to turn it off, or choose a compatible model and server."
);
app.chat_widget.set_daybreak_enabled(/*enabled*/ false);
let extra_root =
AbsolutePathBuf::resolve_path_against_base("extra", app.config.cwd.as_path());
let permission_profile = PermissionProfile::Managed {
@@ -43,6 +43,153 @@ use tokio_tungstenite::tungstenite::Message;
pub(super) type RecordedRequests = Arc<Mutex<Vec<JSONRPCRequest>>>;
pub(super) type RecordingAppServer = (AppServerSession, RecordedRequests, JoinHandle<Result<()>>);
#[tokio::test]
async fn daybreak_command_persists_and_confirms_each_selection() -> Result<()> {
use codex_protocol::openai_models::ModelAccessPrograms;
use codex_protocol::turn_input::CyberAccessProgram;
let (mut app, mut events, mut ops) = make_test_app_with_channels().await;
let (mut server, requests, proxy) = start_recording_app_server(
&app.config,
/*blocked_thread_list*/ None,
/*failed_thread_name*/ None,
)
.await?;
let mut enabled_config = app.config.clone();
enabled_config.daybreak_enabled = true;
let startup = crate::app_server_session::start_thread_with_request_handle(
server.request_handle(),
&app.local_settings,
enabled_config.clone(),
crate::app_server_session::ThreadParamsMode::Embedded,
/*remote_cwd_override*/ None,
server.thread_tool_transport(),
/*model_provider_override*/ None,
)
.await?;
assert!(startup.session.daybreak_enabled);
enabled_config.ephemeral = true;
let ephemeral = server.start_thread(&enabled_config).await?;
assert!(ephemeral.session.daybreak_enabled);
let starts = recorded_params(&requests, "thread/start");
assert_eq!(starts[0]["daybreakEnabled"], true);
assert!(starts[1]["daybreakEnabled"].is_null());
let started = server.start_thread(&app.config).await?;
let thread_id = started.session.thread_id;
app.active_thread_id = Some(thread_id);
app.chat_widget.handle_thread_session_quiet(started.session);
app.chat_widget.update_account_state(
/*status_account_display*/ None, /*plan_type*/ None,
/*has_chatgpt_account*/ true, /*has_codex_backend_auth*/ true,
);
app.chat_widget.open_model_popup();
let request_id = std::iter::from_fn(|| events.try_recv().ok())
.find_map(|event| match event {
AppEvent::FetchModels { request_id } => Some(request_id),
_ => None,
})
.expect("model catalog request");
let mut model = crate::test_support::TEST_MODEL_PRESETS[0].clone();
model.model = app.chat_widget.current_model().to_string();
model.available_access_programs = Some(ModelAccessPrograms {
cyber: vec![
CyberAccessProgram::Standard,
CyberAccessProgram::DaybreakBlue,
],
});
let mut unsupported_model = model.clone();
unsupported_model.model = "standard-only".into();
unsupported_model.available_access_programs = Some(ModelAccessPrograms {
cyber: vec![CyberAccessProgram::Standard],
});
app.chat_widget
.on_models_loaded(request_id, Ok(vec![model, unsupported_model]));
app.chat_widget
.handle_key_event(KeyEvent::from(KeyCode::Esc));
let mut tui = crate::tui::test_support::make_test_tui()?;
let mut confirmations = Vec::new();
for enabled in [true, false] {
app.chat_widget.insert_str("/daybreak");
app.chat_widget
.handle_key_event(KeyEvent::from(KeyCode::Esc));
app.chat_widget
.handle_key_event(KeyEvent::from(KeyCode::Enter));
let selection = std::iter::from_fn(|| events.try_recv().ok())
.find(|event| matches!(event, AppEvent::PersistDaybreakSelection { .. }))
.expect("Daybreak selection event");
app.handle_event(&mut tui, &mut server, selection).await?;
confirmations.push(next_history_message(&mut events));
assert_eq!(
server
.thread_read(thread_id, /*include_turns*/ false)
.await?
.daybreak_enabled,
Some(enabled)
);
assert_eq!(app.config.daybreak_enabled, enabled);
let writes = recorded_params(&requests, "config/batchWrite");
let edit = &writes.last().expect("config write")["edits"][0];
assert_eq!(edit["keyPath"], "daybreak");
assert_eq!(edit["value"], enabled);
}
insta::assert_snapshot!("daybreak_toggle_confirmations", confirmations.join("\n\n"));
app.chat_widget.set_daybreak_enabled(/*enabled*/ true);
app.chat_widget
.handle_key_event(KeyEvent::from(KeyCode::Esc));
app.chat_widget
.apply_external_edit("side prompt".to_string());
app.chat_widget
.handle_key_event(KeyEvent::from(KeyCode::Enter));
let turn = next_user_turn_op(&mut ops);
let mut unsupported_turn = turn.clone();
let Op::UserTurn { model, .. } = &mut unsupported_turn else {
unreachable!("expected user turn");
};
*model = "standard-only".into();
while events.try_recv().is_ok() {}
app.submit_thread_op(&mut server, thread_id, unsupported_turn)
.await?;
assert!(recorded_params(&requests, "turn/start").is_empty());
assert!(next_history_message(&mut events).contains("Daybreak support for model standard-only"));
app.chat_widget
.set_side_conversation_active(/*active*/ true);
app.submit_thread_op(&mut server, thread_id, turn.clone())
.await?;
app.chat_widget
.set_side_conversation_active(/*active*/ false);
app.submit_thread_op(&mut server, thread_id, turn.clone())
.await?;
let background_thread_id = server.start_thread(&app.config).await?.session.thread_id;
app.side_threads.insert(
background_thread_id,
crate::app::side::SideThreadState::new(thread_id),
);
app.submit_thread_op(&mut server, background_thread_id, turn)
.await?;
let turns = recorded_params(&requests, "turn/start");
assert_eq!(turns.len(), 3);
assert_eq!(turns[0]["cyberAccessProgram"], "standard");
assert_eq!(turns[1]["cyberAccessProgram"], "daybreakBlue");
assert_eq!(turns[2]["cyberAccessProgram"], "standard");
app.chat_widget.set_daybreak_enabled(/*enabled*/ false);
while events.try_recv().is_ok() {}
let missing_thread_id = ThreadId::new();
app.active_thread_id = Some(missing_thread_id);
app.persist_daybreak_selection(&mut server, missing_thread_id, /*enabled*/ true)
.await;
assert!(next_history_message(&mut events).contains("Failed to read the thread"));
assert!(!app.chat_widget.daybreak_enabled);
assert!(!app.config.daybreak_enabled);
server.shutdown().await?;
proxy.await??;
Ok(())
}
async fn complete_managed_worktree_creation(
app: &mut App,
tui: &mut crate::tui::Tui,
@@ -0,0 +1,7 @@
---
source: tui/src/app/tests/session_lifecycle_requests.rs
expression: "confirmations.join(\"\\n\\n\")"
---
• Daybreak on. Applies to new turns.
• Daybreak off. Applies to new turns.
+1
View File
@@ -662,6 +662,7 @@ mod tests {
fn test_thread_session(thread_id: ThreadId, cwd: PathBuf) -> ThreadSessionState {
ThreadSessionState {
daybreak_enabled: false,
windows_sandbox_host: crate::app::WindowsSandboxHost::Local,
thread_id,
forked_from_id: None,
+24
View File
@@ -826,6 +826,28 @@ impl App {
}
}
if should_start_turn {
let eligible_account = self.chat_widget.has_chatgpt_account()
&& self.chat_widget.config_ref().model_provider_id == "openai";
let enabled = self.chat_widget.daybreak_enabled
&& !self.chat_widget.side_conversation_active()
&& !self.side_threads.contains_key(&thread_id);
let cyber_access_program = match crate::daybreak::program_for_turn(
&self.chat_widget.model_catalog().models,
model,
eligible_account,
enabled,
) {
Ok(program) => program,
Err(message) => {
if !self
.chat_widget
.handle_turn_start_rejection(message.clone())
{
self.chat_widget.add_error_message(message);
}
return Ok(true);
}
};
let config = self.chat_widget.config_ref();
let selected_profile =
self.pending_server_profiles.get(&thread_id).or_else(|| {
@@ -892,6 +914,7 @@ impl App {
collaboration_mode.clone(),
*personality,
final_output_json_schema.clone(),
cyber_access_program.map(Into::into),
)
.await?;
if self.active_thread_id == Some(thread_id)
@@ -1398,6 +1421,7 @@ impl App {
) -> Option<ThreadSessionState> {
let mut session = self.primary_session_configured.clone()?;
session.thread_id = thread_id;
session.daybreak_enabled = notification.thread.daybreak_enabled.unwrap_or(false);
session.windows_sandbox_host = crate::windows_sandbox::host_from_environments(
notification.thread.environments.as_deref(),
);
@@ -83,10 +83,12 @@ impl App {
// thread-scoped state from the currently active session.
session.collaboration_mode = None;
session.personality = None;
session.daybreak_enabled = false;
}
session
} else {
ThreadSessionState {
daybreak_enabled: false,
windows_sandbox_host: crate::app::WindowsSandboxHost::Local,
thread_id,
forked_from_id: None,
@@ -115,6 +117,7 @@ impl App {
session.windows_sandbox_host =
crate::windows_sandbox::host_from_environments(thread.environments.as_deref());
session.thread_id = thread_id;
session.daybreak_enabled = thread.daybreak_enabled.unwrap_or(false);
session.thread_name = thread.name.clone();
session.model_provider_id = thread.model_provider.clone();
session.set_cwd_retargeting_implicit_runtime_workspace_root(thread.cwd.clone());
@@ -172,6 +175,7 @@ mod tests {
fn test_thread_session(thread_id: ThreadId, cwd: PathBuf) -> ThreadSessionState {
ThreadSessionState {
daybreak_enabled: false,
windows_sandbox_host: crate::app::WindowsSandboxHost::Local,
thread_id,
forked_from_id: None,
+6
View File
@@ -1264,6 +1264,12 @@ pub(crate) enum AppEvent {
service_tier: Option<String>,
},
/// Persist the current thread's Daybreak preference and the new-thread default.
PersistDaybreakSelection {
thread_id: ThreadId,
enabled: bool,
},
/// Fetch the current catalog even when cached models produce no picker.
FetchModels {
request_id: uuid::Uuid,
+20 -5
View File
@@ -772,6 +772,7 @@ impl AppServerSession {
.model_provider_override
.clone()
.or(params.model_provider);
params.daybreak_enabled = (config.daybreak_enabled && !config.ephemeral).then_some(true);
if let Some(selected_profile) = selected_profile {
params.runtime_workspace_roots = None;
params.permissions = Some(selected_profile.profile_id.clone());
@@ -1052,6 +1053,9 @@ impl AppServerSession {
if let Some(permissions) = selected_permissions {
started.session.permission_profile = permissions;
}
if presentation == ForkPresentation::SideConversation {
started.session.daybreak_enabled = false;
}
started.session.fork_parent_title = fork_parent.and_then(|thread| thread.name);
if self.task_tools_available(thread_id) {
started.task_tools_available = true;
@@ -1325,6 +1329,7 @@ impl AppServerSession {
collaboration_mode: Option<codex_protocol::config_types::CollaborationMode>,
personality: Option<codex_protocol::config_types::Personality>,
output_schema: Option<serde_json::Value>,
cyber_access_program: Option<codex_app_server_protocol::CyberAccessProgram>,
) -> Result<TurnStartResponse> {
let request_id = self.next_request_id();
let (sandbox_policy, permissions) =
@@ -1357,7 +1362,7 @@ impl AppServerSession {
output_schema,
collaboration_mode,
multi_agent_mode: None,
cyber_access_program: None,
cyber_access_program,
},
})
.await
@@ -1721,6 +1726,7 @@ pub(crate) async fn start_thread_with_request_handle(
/*session_start_source*/ None,
);
params.model_provider = model_provider_override.or(params.model_provider);
params.daybreak_enabled = (config.daybreak_enabled && !config.ephemeral).then_some(true);
thread_tool_transport.configure(&mut params);
let (response, _history_support, task_tools_available) =
request_thread_start_with_history_fallback(&request_handle, request_id, params)
@@ -2319,7 +2325,7 @@ async fn thread_session_state_from_thread_start_response(
config,
thread_params_mode,
);
thread_session_state_from_thread_response(
let mut session = thread_session_state_from_thread_response(
&response.thread.id,
crate::windows_sandbox::host_from_environments(response.thread.environments.as_deref()),
response.thread.forked_from_id.clone(),
@@ -2339,7 +2345,12 @@ async fn thread_session_state_from_thread_start_response(
config.personality,
local_settings,
)
.await
.await?;
session.daybreak_enabled = response
.thread
.daybreak_enabled
.unwrap_or(response.thread.ephemeral && config.daybreak_enabled);
Ok(session)
}
async fn thread_session_state_from_thread_resume_response(
@@ -2376,6 +2387,7 @@ async fn thread_session_state_from_thread_resume_response(
)
.await?;
session.collaboration_mode = response.collaboration_mode.clone().map(Box::new);
session.daybreak_enabled = response.thread.daybreak_enabled.unwrap_or(false);
Ok(session)
}
@@ -2391,7 +2403,7 @@ async fn thread_session_state_from_thread_fork_response(
config,
thread_params_mode,
);
thread_session_state_from_thread_response(
let mut session = thread_session_state_from_thread_response(
&response.thread.id,
crate::windows_sandbox::host_from_environments(response.thread.environments.as_deref()),
response.thread.forked_from_id.clone(),
@@ -2411,7 +2423,9 @@ async fn thread_session_state_from_thread_fork_response(
config.personality,
local_settings,
)
.await
.await?;
session.daybreak_enabled = response.thread.daybreak_enabled.unwrap_or(false);
Ok(session)
}
fn display_permission_profile_from_thread_response(
@@ -2476,6 +2490,7 @@ async fn thread_session_state_from_thread_response(
);
let (log_id, entry_count) = codex_message_history::history_metadata(&history_config).await;
Ok(ThreadSessionState {
daybreak_enabled: false,
windows_sandbox_host,
thread_id,
forked_from_id,
@@ -138,6 +138,7 @@ stream_max_retries = 0
/*collaboration_mode*/ None,
/*personality*/ None,
/*output_schema*/ None,
/*cyber_access_program*/ None,
)
.await?;
tokio::time::timeout(std::time::Duration::from_secs(/*secs*/ 30), async {
@@ -96,6 +96,7 @@ stream_max_retries = 0
/*collaboration_mode*/ None,
/*personality*/ None,
/*output_schema*/ None,
/*cyber_access_program*/ None,
)
.await?;
tokio::time::timeout(std::time::Duration::from_secs(/*secs*/ 30), async {
@@ -89,6 +89,7 @@ fn complete_token_occurrences_before(textarea: &TextArea, token: &str, before: u
#[derive(Default)]
pub(super) struct PopupState {
pub(super) active: ActivePopup,
pub(super) daybreak_command_description: Option<&'static str>,
pub(super) dismissed_command_token: Option<String>,
pub(super) dismissed_file_token: Option<DismissedToken>,
pub(super) current_file_query: Option<String>,
@@ -176,6 +176,7 @@ impl<'a> SlashInput<'a> {
plugins_command_enabled: self.command_flags.plugins_command_enabled,
token_activity_command_enabled: self.command_flags.token_activity_command_enabled,
service_tier_commands_enabled: self.command_flags.service_tier_commands_enabled,
daybreak_command_description: self.command_flags.daybreak_command_description,
goal_command_enabled: self.command_flags.goal_command_enabled,
voice_command_enabled: self.command_flags.voice_command_enabled,
worktrees_enabled: self.command_flags.worktrees_enabled,
@@ -214,6 +215,7 @@ impl ChatComposer {
plugins_command_enabled: self.plugins_command_enabled,
token_activity_command_enabled: self.token_activity_command_enabled,
service_tier_commands_enabled: self.service_tier_commands_enabled,
daybreak_command_description: self.popups.daybreak_command_description,
goal_command_enabled: self.goal_command_enabled,
voice_command_enabled: self.voice_command_enabled,
worktrees_enabled: self.worktrees_enabled,
@@ -222,6 +224,10 @@ impl ChatComposer {
}
}
pub fn set_daybreak_command_description(&mut self, description: Option<&'static str>) {
self.popups.daybreak_command_description = description;
}
pub fn set_worktrees_enabled(&mut self, enabled: bool) {
self.worktrees_enabled = enabled;
}
+12 -1
View File
@@ -36,6 +36,7 @@ pub(crate) struct CommandPopup {
command_filter: String,
commands: Vec<CommandItem>,
state: ScrollState,
daybreak_command_description: Option<&'static str>,
}
#[derive(Clone, Copy, Debug, Default)]
@@ -45,6 +46,7 @@ pub(crate) struct CommandPopupFlags {
pub(crate) plugins_command_enabled: bool,
pub(crate) token_activity_command_enabled: bool,
pub(crate) service_tier_commands_enabled: bool,
pub(crate) daybreak_command_description: Option<&'static str>,
pub(crate) goal_command_enabled: bool,
pub(crate) voice_command_enabled: bool,
pub(crate) worktrees_enabled: bool,
@@ -60,6 +62,7 @@ impl From<CommandPopupFlags> for BuiltinCommandFlags {
plugins_command_enabled: value.plugins_command_enabled,
token_activity_command_enabled: value.token_activity_command_enabled,
service_tier_commands_enabled: value.service_tier_commands_enabled,
daybreak_command_description: value.daybreak_command_description,
goal_command_enabled: value.goal_command_enabled,
voice_command_enabled: value.voice_command_enabled,
worktrees_enabled: value.worktrees_enabled,
@@ -88,6 +91,7 @@ impl CommandPopup {
command_filter: String::new(),
commands,
state: ScrollState::new(),
daybreak_command_description: flags.daybreak_command_description,
}
}
@@ -207,7 +211,13 @@ impl CommandPopup {
.enumerate()
.map(|(index, (item, indices))| {
let name = format!("/{}", item.command());
let description = item.description().to_string();
let description = if matches!(item, CommandItem::Builtin(SlashCommand::Daybreak)) {
self.daybreak_command_description
.unwrap_or(item.description())
} else {
item.description()
}
.to_string();
GenericDisplayRow {
category_tag: None,
name,
@@ -608,6 +618,7 @@ mod tests {
plugins_command_enabled: false,
token_activity_command_enabled: false,
service_tier_commands_enabled: false,
daybreak_command_description: None,
goal_command_enabled: false,
voice_command_enabled: false,
worktrees_enabled: true,
+5
View File
@@ -609,6 +609,11 @@ impl BottomPane {
self.request_redraw();
}
pub fn set_daybreak_command_description(&mut self, description: Option<&'static str>) {
self.composer.set_daybreak_command_description(description);
self.request_redraw();
}
pub fn set_service_tier_commands(&mut self, commands: Vec<ServiceTierCommand>) {
self.composer.set_service_tier_commands(commands);
self.request_redraw();
@@ -60,6 +60,7 @@ pub(crate) struct BuiltinCommandFlags {
pub(crate) plugins_command_enabled: bool,
pub(crate) token_activity_command_enabled: bool,
pub(crate) service_tier_commands_enabled: bool,
pub(crate) daybreak_command_description: Option<&'static str>,
pub(crate) goal_command_enabled: bool,
pub(crate) voice_command_enabled: bool,
pub(crate) worktrees_enabled: bool,
@@ -79,6 +80,9 @@ pub(crate) fn builtins_for_input(flags: BuiltinCommandFlags) -> Vec<(&'static st
.filter(|(_, cmd)| flags.goal_command_enabled || *cmd != SlashCommand::Goal)
.filter(|(_, cmd)| flags.worktrees_enabled || *cmd != SlashCommand::Worktree)
.filter(|(_, cmd)| flags.voice_command_enabled || *cmd != SlashCommand::Voice)
.filter(|(_, cmd)| {
flags.daybreak_command_description.is_some() || *cmd != SlashCommand::Daybreak
})
.filter(|(_, cmd)| !flags.side_conversation_active || cmd.available_in_side_conversation())
.collect()
}
@@ -119,6 +123,7 @@ pub(crate) fn find_builtin_command(name: &str, flags: BuiltinCommandFlags) -> Op
})?;
builtins_for_input(BuiltinCommandFlags {
token_activity_command_enabled: true,
daybreak_command_description: Some(""),
side_conversation_active: false,
..flags
})
@@ -171,6 +176,7 @@ mod tests {
plugins_command_enabled: true,
token_activity_command_enabled: true,
service_tier_commands_enabled: true,
daybreak_command_description: Some(""),
goal_command_enabled: true,
voice_command_enabled: true,
worktrees_enabled: true,
+1
View File
@@ -515,6 +515,7 @@ pub(crate) enum ExternalEditorState {
pub(crate) struct ChatWidget {
pub(crate) empty_state_animation:
std::cell::RefCell<crate::empty_state_animation::EmptyStateAnimation>,
pub(crate) daybreak_enabled: bool,
app_event_tx: AppEventSender,
codex_op_target: CodexOpTarget,
bottom_pane: BottomPane,
@@ -97,6 +97,7 @@ impl ChatWidget {
);
let mut widget = Self {
empty_state_animation: std::cell::RefCell::new(empty_state_animation),
daybreak_enabled: false,
app_event_tx: app_event_tx.clone(),
frame_requester: frame_requester.clone(),
codex_op_target,
@@ -38,6 +38,7 @@ impl ChatWidget {
return false;
}
Arc::make_mut(&mut self.model_catalog).models = presets;
self.set_daybreak_enabled(self.daybreak_enabled);
self.refresh_effective_service_tier();
self.refresh_model_dependent_surfaces();
true
@@ -71,6 +71,8 @@ impl ChatWidget {
let connector_scope_changed = previous_thread_id != Some(session.thread_id)
|| self.config.cwd.as_path() != session.cwd.as_path();
self.thread_id = Some(session.thread_id);
self.daybreak_enabled = session.daybreak_enabled
&& !matches!(display, SessionConfiguredDisplay::SideConversation);
#[cfg(target_os = "windows")]
if self.windows_sandbox_local_server
&& matches!(self.codex_op_target, CodexOpTarget::AppEvent)
@@ -106,6 +108,10 @@ impl ChatWidget {
self.current_cwd = Some(session.cwd.to_path_buf());
self.config.cwd = session.cwd.clone();
self.config.model_provider_id = session.model_provider_id.clone();
self.set_daybreak_enabled(self.daybreak_enabled);
if self.daybreak_enabled && previous_thread_id != self.thread_id {
self.add_info_message("Daybreak is on for new turns.".into(), /*hint*/ None);
}
if connector_scope_changed {
self.invalidate_connector_scope();
}
+20
View File
@@ -5,6 +5,25 @@ use crate::app_event::AppEvent;
use crate::chatwidget::rate_limits::RATE_LIMIT_SWITCH_PROMPT_VIEW_ID;
impl ChatWidget {
pub(crate) fn set_daybreak_enabled(&mut self, enabled: bool) {
self.daybreak_enabled = enabled;
self.bottom_pane
.set_daybreak_command_description(self.daybreak_command_description());
}
pub(super) fn daybreak_command_description(&self) -> Option<&'static str> {
if self.daybreak_enabled {
Some("Disable broader access for cybersecurity work")
} else if !self.has_chatgpt_account || self.config.model_provider_id != "openai" {
None
} else {
match crate::daybreak::availability(&self.model_catalog.models) {
Some(true) => Some("Enable broader access for cybersecurity work"),
Some(false) => Some("Learn about broader access for cybersecurity work"),
None => Some("Manage broader access for cybersecurity work"),
}
}
}
/// Set the approval policy in the widget's config copy.
pub(crate) fn set_approval_policy(&mut self, policy: AskForApproval) {
if let Err(err) = self
@@ -232,6 +251,7 @@ impl ChatWidget {
self.status_account_display = status_account_display;
self.plan_type = plan_type;
self.has_chatgpt_account = has_chatgpt_account;
self.set_daybreak_enabled(self.daybreak_enabled);
self.has_codex_backend_auth = has_codex_backend_auth;
self.bottom_pane
.set_connectors_enabled(self.connectors_enabled());
@@ -188,6 +188,36 @@ impl ChatWidget {
}
match cmd {
SlashCommand::Daybreak => {
if !self.daybreak_enabled {
if !self.has_chatgpt_account || self.config.model_provider_id != "openai" {
self.add_error_message("Daybreak requires a signed-in ChatGPT account and the OpenAI provider.".into());
return;
}
if !crate::daybreak::available(&self.model_catalog.models) {
if crate::daybreak::availability(&self.model_catalog.models) == Some(false)
{
self.add_info_message(
"Daybreak is not available for this account. Apply at https://openai.com/form/enterprise-trusted-access-for-cyber/. Learn more at https://help.openai.com/en/articles/20001326.".into(),
/*hint*/ None,
);
} else {
self.add_error_message("Daybreak availability could not be determined from the connected host's model catalog.".into());
}
return;
}
}
let Some(thread_id) = self.thread_id else {
self.add_error_message(
"Daybreak is unavailable until the thread starts.".into(),
);
return;
};
self.app_event_tx.send(AppEvent::PersistDaybreakSelection {
thread_id,
enabled: !self.daybreak_enabled,
});
}
SlashCommand::Feedback => {
if !self.config.feedback_enabled {
let params = crate::bottom_pane::feedback_disabled_params();
@@ -1204,6 +1234,7 @@ impl ChatWidget {
token_activity_command_enabled: self.has_codex_backend_auth,
goal_command_enabled: self.config.features.enabled(Feature::Goals),
service_tier_commands_enabled: self.fast_mode_enabled(),
daybreak_command_description: self.daybreak_command_description(),
voice_command_enabled: self.realtime_conversation_available_for_thread,
worktrees_enabled: self.config.features.enabled(Feature::Worktrees)
&& self.local_worktree_operations,
@@ -1242,6 +1273,7 @@ impl ChatWidget {
| SlashCommand::Copy
| SlashCommand::Raw
| SlashCommand::Vim
| SlashCommand::Daybreak
| SlashCommand::Diff
| SlashCommand::App
| SlashCommand::Rename
@@ -0,0 +1,5 @@
---
source: tui/src/chatwidget/tests/slash_commands.rs
expression: "lines_to_single_string(&cells[0])"
---
■ Daybreak availability could not be determined from the connected host's model catalog.
@@ -0,0 +1,5 @@
---
source: tui/src/chatwidget/tests/slash_commands.rs
expression: "render_bottom_popup(&chat, 80).lines().next().unwrap()"
---
› /daybreak Disable broader access for cybersecurity work
@@ -0,0 +1,5 @@
---
source: tui/src/chatwidget/tests/slash_commands.rs
expression: "render_bottom_popup(&chat, 80).lines().next().unwrap()"
---
› /daybreak Enable broader access for cybersecurity work
@@ -0,0 +1,5 @@
---
source: tui/src/chatwidget/tests/slash_commands.rs
expression: "render_bottom_popup(&chat, 80).lines().next().unwrap()"
---
› /daybreak Learn about broader access for cybersecurity work
@@ -0,0 +1,6 @@
---
source: tui/src/chatwidget/tests/slash_commands.rs
assertion_line: 2194
expression: "lines_to_single_string(&cells[0])"
---
■ Daybreak requires a signed-in ChatGPT account and the OpenAI provider.
@@ -0,0 +1,5 @@
---
source: tui/src/chatwidget/tests/slash_commands.rs
expression: "lines_to_single_string(&cells[0])"
---
• Daybreak is not available for this account. Apply at https://openai.com/form/enterprise-trusted-access-for-cyber/. Learn more at https://help.openai.com/en/articles/20001326.
@@ -45,6 +45,7 @@ fn thread_settings_for_test(
fn configured_thread_session(thread_id: ThreadId) -> crate::session_state::ThreadSessionState {
crate::session_state::ThreadSessionState {
daybreak_enabled: false,
windows_sandbox_host: crate::app::WindowsSandboxHost::Local,
thread_id,
forked_from_id: None,
@@ -421,6 +421,7 @@ async fn submission_preserves_text_elements_and_local_images() {
let thread_id = ThreadId::new();
let rollout_file = NamedTempFile::new().unwrap();
let configured = crate::session_state::ThreadSessionState {
daybreak_enabled: false,
windows_sandbox_host: crate::app::WindowsSandboxHost::Local,
thread_id,
forked_from_id: None,
@@ -531,6 +532,7 @@ async fn submission_includes_configured_active_permission_profile() {
};
let expected_active_permission_profile = ActivePermissionProfile::new("custom");
let configured = crate::session_state::ThreadSessionState {
daybreak_enabled: false,
windows_sandbox_host: crate::app::WindowsSandboxHost::Local,
thread_id,
forked_from_id: None,
@@ -587,6 +589,7 @@ async fn submission_omits_active_permission_profile_for_legacy_snapshot() {
file_system: ManagedFileSystemPermissions::Unrestricted,
};
let configured = crate::session_state::ThreadSessionState {
daybreak_enabled: false,
windows_sandbox_host: crate::app::WindowsSandboxHost::Local,
thread_id,
forked_from_id: None,
@@ -633,6 +636,7 @@ async fn submission_with_remote_and_local_images_keeps_local_placeholder_numberi
let thread_id = ThreadId::new();
let rollout_file = NamedTempFile::new().unwrap();
let configured = crate::session_state::ThreadSessionState {
daybreak_enabled: false,
windows_sandbox_host: crate::app::WindowsSandboxHost::Local,
thread_id,
forked_from_id: None,
@@ -734,6 +738,7 @@ async fn enter_with_only_remote_images_submits_user_turn() {
let thread_id = ThreadId::new();
let rollout_file = NamedTempFile::new().unwrap();
let configured = crate::session_state::ThreadSessionState {
daybreak_enabled: false,
windows_sandbox_host: crate::app::WindowsSandboxHost::Local,
thread_id,
forked_from_id: None,
@@ -804,6 +809,7 @@ async fn shift_enter_with_only_remote_images_does_not_submit_user_turn() {
let thread_id = ThreadId::new();
let rollout_file = NamedTempFile::new().unwrap();
let configured = crate::session_state::ThreadSessionState {
daybreak_enabled: false,
windows_sandbox_host: crate::app::WindowsSandboxHost::Local,
thread_id,
forked_from_id: None,
@@ -846,6 +852,7 @@ async fn enter_with_only_remote_images_does_not_submit_when_modal_is_active() {
let thread_id = ThreadId::new();
let rollout_file = NamedTempFile::new().unwrap();
let configured = crate::session_state::ThreadSessionState {
daybreak_enabled: false,
windows_sandbox_host: crate::app::WindowsSandboxHost::Local,
thread_id,
forked_from_id: None,
@@ -888,6 +895,7 @@ async fn enter_with_only_remote_images_does_not_submit_when_input_disabled() {
let thread_id = ThreadId::new();
let rollout_file = NamedTempFile::new().unwrap();
let configured = crate::session_state::ThreadSessionState {
daybreak_enabled: false,
windows_sandbox_host: crate::app::WindowsSandboxHost::Local,
thread_id,
forked_from_id: None,
@@ -933,6 +941,7 @@ async fn submission_prefers_selected_duplicate_skill_path() {
let thread_id = ThreadId::new();
let rollout_file = NamedTempFile::new().unwrap();
let configured = crate::session_state::ThreadSessionState {
daybreak_enabled: false,
windows_sandbox_host: crate::app::WindowsSandboxHost::Local,
thread_id,
forked_from_id: None,
@@ -1481,6 +1481,7 @@ async fn bang_shell_enter_while_task_running_submits_run_user_shell_command() {
let thread_id = ThreadId::new();
let rollout_file = NamedTempFile::new().unwrap();
let configured = crate::session_state::ThreadSessionState {
daybreak_enabled: false,
windows_sandbox_host: crate::app::WindowsSandboxHost::Local,
thread_id,
forked_from_id: None,
@@ -20,6 +20,7 @@ async fn resumed_initial_messages_render_history() {
let thread_id = ThreadId::new();
let rollout_file = NamedTempFile::new().unwrap();
let configured = crate::session_state::ThreadSessionState {
daybreak_enabled: true,
windows_sandbox_host: crate::app::WindowsSandboxHost::Local,
thread_id,
forked_from_id: None,
@@ -44,6 +45,7 @@ async fn resumed_initial_messages_render_history() {
};
chat.handle_thread_session(configured);
assert!(chat.daybreak_enabled);
replay_user_message_text(
&mut chat,
"user-1",
@@ -77,6 +79,7 @@ async fn resumed_initial_messages_render_history() {
text_blob.contains("assistant reply"),
"expected replayed agent message",
);
insta::assert_snapshot!("resumed_daybreak_banner", merged_lines[0]);
}
#[tokio::test]
@@ -135,6 +138,7 @@ async fn restored_conversation_ultra_remains_selected_after_switching_to_plan()
chat.set_plan_mode_reasoning_effort(Some(ReasoningEffortConfig::High));
chat.handle_thread_session(crate::session_state::ThreadSessionState {
daybreak_enabled: false,
windows_sandbox_host: crate::app::WindowsSandboxHost::Local,
thread_id: ThreadId::new(),
forked_from_id: None,
@@ -423,6 +427,7 @@ async fn replayed_user_message_preserves_text_elements_and_local_images() {
let thread_id = ThreadId::new();
let rollout_file = NamedTempFile::new().unwrap();
let configured = crate::session_state::ThreadSessionState {
daybreak_enabled: false,
windows_sandbox_host: crate::app::WindowsSandboxHost::Local,
thread_id,
forked_from_id: None,
@@ -496,6 +501,7 @@ async fn replayed_user_message_preserves_remote_image_urls() {
let thread_id = ThreadId::new();
let rollout_file = NamedTempFile::new().unwrap();
let configured = crate::session_state::ThreadSessionState {
daybreak_enabled: false,
windows_sandbox_host: crate::app::WindowsSandboxHost::Local,
thread_id,
forked_from_id: None,
@@ -603,6 +609,7 @@ async fn session_configured_syncs_widget_config_permissions_and_cwd() {
.expect("permission profile should project to legacy sandbox policy");
let expected_sandbox = SandboxPolicy::from(expected_core_sandbox);
let configured = crate::session_state::ThreadSessionState {
daybreak_enabled: false,
windows_sandbox_host: crate::app::WindowsSandboxHost::Local,
thread_id: ThreadId::new(),
forked_from_id: None,
@@ -677,6 +684,7 @@ async fn session_configured_preserves_profile_workspace_roots() {
let session_permission_profile = PermissionProfile::workspace_write()
.materialize_project_roots_with_workspace_roots(&session_effective_workspace_roots);
let configured = crate::session_state::ThreadSessionState {
daybreak_enabled: false,
windows_sandbox_host: crate::app::WindowsSandboxHost::Local,
thread_id: ThreadId::new(),
forked_from_id: None,
@@ -725,6 +733,7 @@ async fn session_configured_external_sandbox_keeps_external_runtime_policy() {
network_access: NetworkAccess::Restricted,
};
let configured = crate::session_state::ThreadSessionState {
daybreak_enabled: false,
windows_sandbox_host: crate::app::WindowsSandboxHost::Local,
thread_id: ThreadId::new(),
forked_from_id: None,
@@ -767,6 +776,7 @@ async fn replayed_user_message_with_only_remote_images_renders_history_cell() {
let thread_id = ThreadId::new();
let rollout_file = NamedTempFile::new().unwrap();
let configured = crate::session_state::ThreadSessionState {
daybreak_enabled: false,
windows_sandbox_host: crate::app::WindowsSandboxHost::Local,
thread_id,
forked_from_id: None,
@@ -828,6 +838,7 @@ async fn replayed_user_message_with_only_local_images_renders_history_cell() {
let thread_id = ThreadId::new();
let rollout_file = NamedTempFile::new().unwrap();
let configured = crate::session_state::ThreadSessionState {
daybreak_enabled: false,
windows_sandbox_host: crate::app::WindowsSandboxHost::Local,
thread_id,
forked_from_id: None,
@@ -1183,6 +1194,7 @@ async fn replayed_reasoning_item_preserves_summary_parts_and_hides_raw_reasoning
let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
chat.config.show_raw_agent_reasoning = false;
chat.handle_thread_session(crate::session_state::ThreadSessionState {
daybreak_enabled: false,
windows_sandbox_host: crate::app::WindowsSandboxHost::Local,
thread_id: ThreadId::new(),
forked_from_id: None,
@@ -1235,6 +1247,7 @@ async fn replayed_reasoning_item_shows_raw_reasoning_when_enabled() {
let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
chat.config.show_raw_agent_reasoning = true;
chat.handle_thread_session(crate::session_state::ThreadSessionState {
daybreak_enabled: false,
windows_sandbox_host: crate::app::WindowsSandboxHost::Local,
thread_id: ThreadId::new(),
forked_from_id: None,
@@ -769,6 +769,7 @@ async fn required_windows_sandbox_setup_defers_configured_initial_prompt() {
create_initial_user_message(Some(initial_prompt.clone()), Vec::new(), Vec::new());
chat.handle_thread_session(crate::session_state::ThreadSessionState {
daybreak_enabled: false,
windows_sandbox_host: crate::app::WindowsSandboxHost::Local,
thread_id: ThreadId::new(),
forked_from_id: None,
@@ -1213,6 +1214,7 @@ async fn permissions_selection_marks_auto_review_current_after_session_configure
.set_enabled(Feature::GuardianApproval, /*enabled*/ true);
chat.handle_thread_session(crate::session_state::ThreadSessionState {
daybreak_enabled: false,
windows_sandbox_host: crate::app::WindowsSandboxHost::Local,
thread_id: ThreadId::new(),
forked_from_id: None,
@@ -1267,6 +1269,7 @@ async fn permissions_selection_marks_auto_review_current_with_custom_workspace_w
let permission_profile = app_server_workspace_write_profile(extra_root);
chat.handle_thread_session(crate::session_state::ThreadSessionState {
daybreak_enabled: false,
windows_sandbox_host: crate::app::WindowsSandboxHost::Local,
thread_id: ThreadId::new(),
forked_from_id: None,
@@ -15,6 +15,7 @@ fn paste_hidden_plan_shell_payload(chat: &mut ChatWidget) -> String {
fn plan_test_session(thread_id: ThreadId) -> crate::session_state::ThreadSessionState {
crate::session_state::ThreadSessionState {
daybreak_enabled: false,
windows_sandbox_host: crate::app::WindowsSandboxHost::Local,
thread_id,
forked_from_id: None,
@@ -1261,6 +1262,7 @@ async fn submit_user_message_emits_structured_plugin_mentions_from_bindings() {
let thread_id = ThreadId::new();
let rollout_file = NamedTempFile::new().unwrap();
let configured = crate::session_state::ThreadSessionState {
daybreak_enabled: false,
windows_sandbox_host: crate::app::WindowsSandboxHost::Local,
thread_id,
forked_from_id: None,
@@ -2150,6 +2150,79 @@ async fn slash_copy_picker_remains_available_from_parent_owned_threads() {
);
}
#[tokio::test]
async fn slash_daybreak_offers_an_application_when_unavailable() {
let (mut chat, mut rx, _ops) = make_chatwidget_manual(/*model_override*/ None).await;
chat.has_chatgpt_account = true;
chat.config.model_provider_id = "openai".into();
let mut model = crate::test_support::TEST_MODEL_PRESETS[0].clone();
model.available_access_programs = Some(codex_protocol::openai_models::ModelAccessPrograms {
cyber: vec![codex_protocol::turn_input::CyberAccessProgram::Standard],
});
chat.model_catalog = std::sync::Arc::new(ModelCatalog::new(vec![model.clone()]));
chat.set_daybreak_enabled(/*enabled*/ false);
chat.bottom_pane
.set_composer_text("/daybreak".to_string(), Vec::new(), Vec::new());
assert_chatwidget_snapshot!(
"slash_daybreak_help_unavailable",
render_bottom_popup(&chat, /*width*/ 80)
.lines()
.next()
.unwrap()
);
chat.dispatch_command(SlashCommand::Daybreak);
let cells = drain_insert_history(&mut rx);
assert_chatwidget_snapshot!(
"slash_daybreak_unavailable",
lines_to_single_string(&cells[0])
);
chat.model_catalog = std::sync::Arc::new(ModelCatalog::new(Vec::new()));
chat.dispatch_command(SlashCommand::Daybreak);
let cells = drain_insert_history(&mut rx);
assert_chatwidget_snapshot!(
"slash_daybreak_catalog_unknown",
lines_to_single_string(&cells[0])
);
chat.has_chatgpt_account = false;
chat.dispatch_command(SlashCommand::Daybreak);
let cells = drain_insert_history(&mut rx);
assert_chatwidget_snapshot!(
"slash_daybreak_signed_out",
lines_to_single_string(&cells[0])
);
chat.has_chatgpt_account = true;
model
.available_access_programs
.as_mut()
.unwrap()
.cyber
.push(codex_protocol::turn_input::CyberAccessProgram::DaybreakBlue);
chat.model_catalog = std::sync::Arc::new(ModelCatalog::new(vec![model]));
for (enabled, name) in [
(false, "slash_daybreak_help_enable"),
(true, "slash_daybreak_help_disable"),
] {
chat.set_daybreak_enabled(enabled);
chat.bottom_pane
.set_composer_text(String::new(), Vec::new(), Vec::new());
chat.bottom_pane
.set_composer_text("/daybreak".to_string(), Vec::new(), Vec::new());
assert_chatwidget_snapshot!(
name,
render_bottom_popup(&chat, /*width*/ 80)
.lines()
.next()
.unwrap()
);
}
}
#[tokio::test]
async fn slash_copy_reports_when_no_agent_response_exists() {
let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
@@ -0,0 +1,5 @@
---
source: tui/src/chatwidget/tests/history_replay.rs
expression: "merged_lines[0]"
---
• Daybreak is on for new turns.
@@ -4292,6 +4292,7 @@ async fn session_configured_clears_goal_status_footer() {
let rollout_file = NamedTempFile::new().unwrap();
chat.handle_thread_session(crate::session_state::ThreadSessionState {
daybreak_enabled: false,
windows_sandbox_host: crate::app::WindowsSandboxHost::Local,
thread_id: ThreadId::new(),
forked_from_id: None,
+58 -1
View File
@@ -1,9 +1,37 @@
//! Choose cyber refusal guidance from the connected host's model catalog.
//! Account-scoped Daybreak eligibility and per-turn program selection.
//! Pending or failed discovery never implies access.
use codex_protocol::openai_models::ModelAccessPrograms;
use codex_protocol::openai_models::ModelPreset;
use codex_protocol::turn_input::CyberAccessProgram;
pub(crate) fn program_for_turn(
models: &[ModelPreset],
model: &str,
eligible_account: bool,
enabled: bool,
) -> Result<Option<CyberAccessProgram>, String> {
if !eligible_account {
return if enabled {
Err("Daybreak requires a signed-in ChatGPT account and the OpenAI provider. Turn it off to continue.".into())
} else {
Ok(None)
};
}
let programs = models
.iter()
.find(|entry| entry.model == model)
.and_then(|entry| entry.available_access_programs.as_ref());
if enabled {
programs
.and_then(codex_protocol::openai_models::ModelAccessPrograms::daybreak)
.map(Some)
.ok_or_else(|| format!("Daybreak support for model {model} could not be confirmed by the connected server. Use /daybreak to turn it off, or choose a compatible model and server."))
} else {
Ok(programs.and_then(codex_protocol::openai_models::ModelAccessPrograms::standard))
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub(crate) enum Notice {
Apply,
@@ -31,6 +59,35 @@ pub(crate) fn notice_for_model(models: &[ModelPreset], model: &str) -> Notice {
}
}
pub(crate) fn available(models: &[ModelPreset]) -> bool {
models.iter().any(|model| {
model
.available_access_programs
.as_ref()
.and_then(codex_protocol::openai_models::ModelAccessPrograms::daybreak)
.is_some()
})
}
/// Missing or empty program lists do not establish that the account lacks access.
pub(crate) fn availability(models: &[ModelPreset]) -> Option<bool> {
if available(models) {
return Some(true);
}
if models.is_empty() {
return None;
}
models
.iter()
.all(|model| {
model
.available_access_programs
.as_ref()
.is_some_and(|programs| !programs.cyber.is_empty())
})
.then_some(false)
}
#[cfg(test)]
#[path = "daybreak_tests.rs"]
mod tests;
+33
View File
@@ -2,6 +2,39 @@ use super::*;
use codex_protocol::openai_models::ModelAccessPrograms;
use pretty_assertions::assert_eq;
#[test]
fn turn_program_uses_catalog_and_preserves_legacy_models() {
let mut model = crate::test_support::TEST_MODEL_PRESETS[0].clone();
model.available_access_programs = Some(ModelAccessPrograms {
cyber: vec![
CyberAccessProgram::Standard,
CyberAccessProgram::DaybreakBlue,
],
});
let models = vec![model.clone()];
for (name, enabled, expected) in [
(
model.model.as_str(),
true,
Some(CyberAccessProgram::DaybreakBlue),
),
(
model.model.as_str(),
false,
Some(CyberAccessProgram::Standard),
),
("unlisted-model", false, None),
] {
assert_eq!(
program_for_turn(&models, name, /*eligible_account*/ true, enabled),
Ok(expected)
);
}
for (name, eligible_account) in [("unlisted-model", true), (model.model.as_str(), false)] {
assert!(program_for_turn(&models, name, eligible_account, /*enabled*/ true).is_err());
}
}
#[test]
fn refusal_guidance_uses_the_model_catalog() {
let mut model = crate::test_support::TEST_MODEL_PRESETS[0].clone();
+1
View File
@@ -603,6 +603,7 @@ fn image_generation_call_renders_saved_path() {
fn session_configured_event(model: &str) -> ThreadSessionState {
ThreadSessionState {
daybreak_enabled: false,
windows_sandbox_host: crate::app::WindowsSandboxHost::Local,
thread_id: ThreadId::new(),
forked_from_id: None,
+1
View File
@@ -28,6 +28,7 @@ pub(crate) struct MessageHistoryMetadata {
#[derive(Debug, Clone, PartialEq)]
pub(crate) struct ThreadSessionState {
pub(crate) daybreak_enabled: bool,
pub(crate) windows_sandbox_host: crate::app::WindowsSandboxHost,
pub(crate) thread_id: ThreadId,
pub(crate) forked_from_id: Option<ThreadId>,
+3
View File
@@ -13,6 +13,7 @@ pub enum SlashCommand {
// DO NOT ALPHA-SORT! Enum order is presentation order in the popup, so
// more frequently used commands should be listed first.
Model,
Daybreak,
Ide,
Permissions,
Keymap,
@@ -129,6 +130,7 @@ impl SlashCommand {
SlashCommand::MemoryDrop => "DO NOT USE",
SlashCommand::MemoryUpdate => "DO NOT USE",
SlashCommand::Model => "choose what model and reasoning effort to use",
SlashCommand::Daybreak => "turn Daybreak on or off",
SlashCommand::Ide => {
"include current selection, open files, and other context from your IDE"
}
@@ -264,6 +266,7 @@ impl SlashCommand {
SlashCommand::Diff
| SlashCommand::Resume
| SlashCommand::Model
| SlashCommand::Daybreak
| SlashCommand::Permissions
| SlashCommand::Copy
| SlashCommand::Raw