mirror of
https://github.com/openai/codex.git
synced 2026-11-15 21:50:46 +00:00
Add experimental thread job scheduler for /loop
This commit is contained in:
+103
-3
@@ -30,6 +30,8 @@ use crate::history_cell;
|
||||
use crate::history_cell::HistoryCell;
|
||||
#[cfg(not(debug_assertions))]
|
||||
use crate::history_cell::UpdateAvailableHistoryCell;
|
||||
use crate::job_scheduler::format_job_summary;
|
||||
use crate::job_scheduler::parse_job_spec;
|
||||
use crate::model_catalog::ModelCatalog;
|
||||
use crate::model_migration::ModelMigrationOutcome;
|
||||
use crate::model_migration::migration_copy_for_models;
|
||||
@@ -1942,6 +1944,26 @@ impl App {
|
||||
});
|
||||
}
|
||||
|
||||
fn parse_thread_job_spec(&mut self, thread_id: ThreadId, spec: String) {
|
||||
let config = self.config.clone();
|
||||
let target = match self.remote_app_server_url.clone() {
|
||||
Some(websocket_url) => crate::AppServerTarget::Remote {
|
||||
websocket_url,
|
||||
auth_token: self.remote_app_server_auth_token.clone(),
|
||||
},
|
||||
None => crate::AppServerTarget::Embedded,
|
||||
};
|
||||
let app_event_tx = self.app_event_tx.clone();
|
||||
tokio::spawn(async move {
|
||||
let result = parse_job_spec(config, target, spec.clone()).await;
|
||||
app_event_tx.send(AppEvent::ThreadJobSpecParsed {
|
||||
thread_id,
|
||||
spec,
|
||||
result,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/// Process the completed MCP inventory fetch: clear the loading spinner, then
|
||||
/// render either the full tool/resource listing or an error into chat history.
|
||||
///
|
||||
@@ -3123,11 +3145,20 @@ impl App {
|
||||
app_server: &mut AppServerSession,
|
||||
started: AppServerStartedThread,
|
||||
) -> Result<()> {
|
||||
let thread_id = started.session.thread_id;
|
||||
self.reset_thread_event_state();
|
||||
let init = self.chatwidget_init_for_forked_or_resumed_thread(tui, self.config.clone());
|
||||
self.replace_chat_widget(ChatWidget::new_with_app_event(init));
|
||||
self.enqueue_primary_thread_session(started.session, started.turns)
|
||||
.await?;
|
||||
if self.config.features.enabled(Feature::JobScheduler) {
|
||||
match app_server.thread_job_list(thread_id).await {
|
||||
Ok(jobs) => self.chat_widget.on_thread_jobs_updated(jobs),
|
||||
Err(err) => {
|
||||
tracing::warn!(%err, "failed to load thread jobs while attaching thread");
|
||||
}
|
||||
}
|
||||
}
|
||||
self.backfill_loaded_subagent_threads(app_server).await;
|
||||
Ok(())
|
||||
}
|
||||
@@ -4009,6 +4040,69 @@ impl App {
|
||||
|
||||
tui.frame_requester().schedule_frame();
|
||||
}
|
||||
AppEvent::OpenThreadJobs { thread_id } => {
|
||||
match app_server.thread_job_list(thread_id).await {
|
||||
Ok(jobs) => self.chat_widget.open_thread_jobs_popup(thread_id, jobs),
|
||||
Err(err) => {
|
||||
self.chat_widget
|
||||
.add_error_message(format!("Failed to load thread jobs: {err}"));
|
||||
}
|
||||
}
|
||||
}
|
||||
AppEvent::CreateThreadJobFromSpec { thread_id, spec } => {
|
||||
self.parse_thread_job_spec(thread_id, spec);
|
||||
}
|
||||
AppEvent::ThreadJobSpecParsed {
|
||||
thread_id,
|
||||
spec,
|
||||
result,
|
||||
} => match result {
|
||||
Ok(parsed) => match app_server
|
||||
.thread_job_create(
|
||||
thread_id,
|
||||
parsed.cron_expression.clone(),
|
||||
parsed.prompt.clone(),
|
||||
parsed.run_once,
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(job) => {
|
||||
let summary =
|
||||
format_job_summary(&job.cron_expression, job.run_once, &job.prompt);
|
||||
self.chat_widget.add_info_message(
|
||||
format!("Created thread job from `/loop {spec}`."),
|
||||
Some(summary),
|
||||
);
|
||||
}
|
||||
Err(err) => {
|
||||
self.chat_widget
|
||||
.add_error_message(format!("Failed to create thread job: {err}"));
|
||||
}
|
||||
},
|
||||
Err(err) => {
|
||||
self.chat_widget
|
||||
.add_error_message(format!("Failed to parse `/loop {spec}`: {err}"));
|
||||
}
|
||||
},
|
||||
AppEvent::DeleteThreadJob { thread_id, id } => {
|
||||
match app_server.thread_job_delete(thread_id, id.clone()).await {
|
||||
Ok(true) => {
|
||||
self.chat_widget.add_info_message(
|
||||
format!("Deleted thread job `{id}`."),
|
||||
/*hint*/ None,
|
||||
);
|
||||
}
|
||||
Ok(false) => {
|
||||
self.chat_widget
|
||||
.add_error_message(format!("No thread job matched `{id}`."));
|
||||
}
|
||||
Err(err) => {
|
||||
self.chat_widget.add_error_message(format!(
|
||||
"Failed to delete thread job `{id}`: {err}"
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
AppEvent::InsertHistoryCell(cell) => {
|
||||
let cell: Arc<dyn HistoryCell> = cell.into();
|
||||
if let Some(Overlay::Transcript(t)) = &mut self.overlay {
|
||||
@@ -7431,6 +7525,14 @@ mod tests {
|
||||
let codex_home = tempdir()?;
|
||||
app.config.codex_home = codex_home.path().to_path_buf();
|
||||
let guardian_approvals = guardian_approvals_mode();
|
||||
app.config
|
||||
.features
|
||||
.set_enabled(Feature::GuardianApproval, /*enabled*/ false)?;
|
||||
app.chat_widget
|
||||
.set_feature_enabled(Feature::GuardianApproval, /*enabled*/ false);
|
||||
app.config.approvals_reviewer = ApprovalsReviewer::User;
|
||||
app.chat_widget
|
||||
.set_approvals_reviewer(ApprovalsReviewer::User);
|
||||
|
||||
app.update_feature_flags(vec![(Feature::GuardianApproval, true)])
|
||||
.await;
|
||||
@@ -7518,9 +7620,7 @@ mod tests {
|
||||
let config_toml = "approvals_reviewer = \"guardian_subagent\"\napproval_policy = \"on-request\"\nsandbox_mode = \"workspace-write\"\n\n[features]\nguardian_approval = true\n";
|
||||
std::fs::write(config_toml_path.as_path(), config_toml)?;
|
||||
let user_config = toml::from_str::<TomlValue>(config_toml)?;
|
||||
app.config.config_layer_stack = app
|
||||
.config
|
||||
.config_layer_stack
|
||||
app.config.config_layer_stack = codex_core::config_loader::ConfigLayerStack::default()
|
||||
.with_user_config(&config_toml_path, user_config);
|
||||
app.config
|
||||
.features
|
||||
|
||||
@@ -329,6 +329,8 @@ fn server_notification_thread_target(
|
||||
ServerNotification::ThreadNameUpdated(notification) => {
|
||||
Some(notification.thread_id.as_str())
|
||||
}
|
||||
ServerNotification::ThreadJobFired(notification) => Some(notification.thread_id.as_str()),
|
||||
ServerNotification::ThreadJobUpdated(notification) => Some(notification.thread_id.as_str()),
|
||||
ServerNotification::ThreadTokenUsageUpdated(notification) => {
|
||||
Some(notification.thread_id.as_str())
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ use crate::bottom_pane::ApprovalRequest;
|
||||
use crate::bottom_pane::StatusLineItem;
|
||||
use crate::bottom_pane::TerminalTitleItem;
|
||||
use crate::history_cell::HistoryCell;
|
||||
use crate::job_scheduler::ParsedJobSpec;
|
||||
|
||||
use codex_core::config::types::ApprovalsReviewer;
|
||||
use codex_features::Feature;
|
||||
@@ -108,6 +109,30 @@ pub(crate) enum AppEvent {
|
||||
/// Fork the current session into a new thread.
|
||||
ForkCurrentSession,
|
||||
|
||||
/// List jobs for the specified thread and open the management UI.
|
||||
OpenThreadJobs {
|
||||
thread_id: ThreadId,
|
||||
},
|
||||
|
||||
/// Parse a `/loop <spec>` input into structured job params.
|
||||
CreateThreadJobFromSpec {
|
||||
thread_id: ThreadId,
|
||||
spec: String,
|
||||
},
|
||||
|
||||
/// Result of parsing a `/loop <spec>` input.
|
||||
ThreadJobSpecParsed {
|
||||
thread_id: ThreadId,
|
||||
spec: String,
|
||||
result: Result<ParsedJobSpec, String>,
|
||||
},
|
||||
|
||||
/// Delete one job from the specified thread.
|
||||
DeleteThreadJob {
|
||||
thread_id: ThreadId,
|
||||
id: String,
|
||||
},
|
||||
|
||||
/// Request to exit the application.
|
||||
///
|
||||
/// Use `ShutdownFirst` for user-initiated quits so core cleanup runs and the
|
||||
|
||||
@@ -30,6 +30,13 @@ use codex_app_server_protocol::ThreadCompactStartParams;
|
||||
use codex_app_server_protocol::ThreadCompactStartResponse;
|
||||
use codex_app_server_protocol::ThreadForkParams;
|
||||
use codex_app_server_protocol::ThreadForkResponse;
|
||||
use codex_app_server_protocol::ThreadJob;
|
||||
use codex_app_server_protocol::ThreadJobCreateParams;
|
||||
use codex_app_server_protocol::ThreadJobCreateResponse;
|
||||
use codex_app_server_protocol::ThreadJobDeleteParams;
|
||||
use codex_app_server_protocol::ThreadJobDeleteResponse;
|
||||
use codex_app_server_protocol::ThreadJobListParams;
|
||||
use codex_app_server_protocol::ThreadJobListResponse;
|
||||
use codex_app_server_protocol::ThreadListParams;
|
||||
use codex_app_server_protocol::ThreadListResponse;
|
||||
use codex_app_server_protocol::ThreadLoadedListParams;
|
||||
@@ -297,6 +304,18 @@ impl AppServerSession {
|
||||
started_thread_from_start_response(response, config).await
|
||||
}
|
||||
|
||||
pub(crate) async fn start_ephemeral_thread(&mut self, config: &Config) -> Result<Thread> {
|
||||
let request_id = self.next_request_id();
|
||||
let mut params = thread_start_params_from_config(config, self.thread_params_mode());
|
||||
params.ephemeral = Some(true);
|
||||
let response: ThreadStartResponse = self
|
||||
.client
|
||||
.request_typed(ClientRequest::ThreadStart { request_id, params })
|
||||
.await
|
||||
.wrap_err("thread/start failed for ephemeral TUI session")?;
|
||||
Ok(response.thread)
|
||||
}
|
||||
|
||||
pub(crate) async fn resume_thread(
|
||||
&mut self,
|
||||
config: Config,
|
||||
@@ -393,6 +412,65 @@ impl AppServerSession {
|
||||
Ok(response.thread)
|
||||
}
|
||||
|
||||
pub(crate) async fn thread_job_create(
|
||||
&mut self,
|
||||
thread_id: ThreadId,
|
||||
cron_expression: String,
|
||||
prompt: String,
|
||||
run_once: Option<bool>,
|
||||
) -> Result<ThreadJob> {
|
||||
let request_id = self.next_request_id();
|
||||
let response: ThreadJobCreateResponse = self
|
||||
.client
|
||||
.request_typed(ClientRequest::ThreadJobCreate {
|
||||
request_id,
|
||||
params: ThreadJobCreateParams {
|
||||
thread_id: thread_id.to_string(),
|
||||
cron_expression,
|
||||
prompt,
|
||||
run_once,
|
||||
},
|
||||
})
|
||||
.await
|
||||
.wrap_err("thread/job/create failed in TUI")?;
|
||||
Ok(response.job)
|
||||
}
|
||||
|
||||
pub(crate) async fn thread_job_delete(
|
||||
&mut self,
|
||||
thread_id: ThreadId,
|
||||
id: String,
|
||||
) -> Result<bool> {
|
||||
let request_id = self.next_request_id();
|
||||
let response: ThreadJobDeleteResponse = self
|
||||
.client
|
||||
.request_typed(ClientRequest::ThreadJobDelete {
|
||||
request_id,
|
||||
params: ThreadJobDeleteParams {
|
||||
thread_id: thread_id.to_string(),
|
||||
id,
|
||||
},
|
||||
})
|
||||
.await
|
||||
.wrap_err("thread/job/delete failed in TUI")?;
|
||||
Ok(response.deleted)
|
||||
}
|
||||
|
||||
pub(crate) async fn thread_job_list(&mut self, thread_id: ThreadId) -> Result<Vec<ThreadJob>> {
|
||||
let request_id = self.next_request_id();
|
||||
let response: ThreadJobListResponse = self
|
||||
.client
|
||||
.request_typed(ClientRequest::ThreadJobList {
|
||||
request_id,
|
||||
params: ThreadJobListParams {
|
||||
thread_id: thread_id.to_string(),
|
||||
},
|
||||
})
|
||||
.await
|
||||
.wrap_err("thread/job/list failed in TUI")?;
|
||||
Ok(response.data)
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub(crate) async fn turn_start(
|
||||
&mut self,
|
||||
|
||||
@@ -328,6 +328,7 @@ pub(crate) struct ChatComposer {
|
||||
collaboration_mode_indicator: Option<CollaborationModeIndicator>,
|
||||
connectors_enabled: bool,
|
||||
plugins_command_enabled: bool,
|
||||
job_scheduler_command_enabled: bool,
|
||||
fast_command_enabled: bool,
|
||||
personality_command_enabled: bool,
|
||||
realtime_conversation_enabled: bool,
|
||||
@@ -367,6 +368,7 @@ impl ChatComposer {
|
||||
collaboration_modes_enabled: self.collaboration_modes_enabled,
|
||||
connectors_enabled: self.connectors_enabled,
|
||||
plugins_command_enabled: self.plugins_command_enabled,
|
||||
job_scheduler_command_enabled: self.job_scheduler_command_enabled,
|
||||
fast_command_enabled: self.fast_command_enabled,
|
||||
personality_command_enabled: self.personality_command_enabled,
|
||||
realtime_conversation_enabled: self.realtime_conversation_enabled,
|
||||
@@ -449,6 +451,7 @@ impl ChatComposer {
|
||||
collaboration_mode_indicator: None,
|
||||
connectors_enabled: false,
|
||||
plugins_command_enabled: false,
|
||||
job_scheduler_command_enabled: false,
|
||||
fast_command_enabled: false,
|
||||
personality_command_enabled: false,
|
||||
realtime_conversation_enabled: false,
|
||||
@@ -487,6 +490,10 @@ impl ChatComposer {
|
||||
self.plugins_command_enabled = enabled;
|
||||
}
|
||||
|
||||
pub fn set_job_scheduler_command_enabled(&mut self, enabled: bool) {
|
||||
self.job_scheduler_command_enabled = enabled;
|
||||
}
|
||||
|
||||
/// Toggle composer-side image paste handling.
|
||||
///
|
||||
/// This only affects whether image-like paste content is converted into attachments; the
|
||||
@@ -3063,6 +3070,7 @@ impl ChatComposer {
|
||||
let collaboration_modes_enabled = self.collaboration_modes_enabled;
|
||||
let connectors_enabled = self.connectors_enabled;
|
||||
let plugins_command_enabled = self.plugins_command_enabled;
|
||||
let job_scheduler_command_enabled = self.job_scheduler_command_enabled;
|
||||
let fast_command_enabled = self.fast_command_enabled;
|
||||
let personality_command_enabled = self.personality_command_enabled;
|
||||
let realtime_conversation_enabled = self.realtime_conversation_enabled;
|
||||
@@ -3071,6 +3079,7 @@ impl ChatComposer {
|
||||
collaboration_modes_enabled,
|
||||
connectors_enabled,
|
||||
plugins_command_enabled,
|
||||
job_scheduler_command_enabled,
|
||||
fast_command_enabled,
|
||||
personality_command_enabled,
|
||||
realtime_conversation_enabled,
|
||||
|
||||
@@ -33,6 +33,7 @@ pub(crate) struct CommandPopupFlags {
|
||||
pub(crate) collaboration_modes_enabled: bool,
|
||||
pub(crate) connectors_enabled: bool,
|
||||
pub(crate) plugins_command_enabled: bool,
|
||||
pub(crate) job_scheduler_command_enabled: bool,
|
||||
pub(crate) fast_command_enabled: bool,
|
||||
pub(crate) personality_command_enabled: bool,
|
||||
pub(crate) realtime_conversation_enabled: bool,
|
||||
@@ -46,6 +47,7 @@ impl From<CommandPopupFlags> for slash_commands::BuiltinCommandFlags {
|
||||
collaboration_modes_enabled: value.collaboration_modes_enabled,
|
||||
connectors_enabled: value.connectors_enabled,
|
||||
plugins_command_enabled: value.plugins_command_enabled,
|
||||
job_scheduler_command_enabled: value.job_scheduler_command_enabled,
|
||||
fast_command_enabled: value.fast_command_enabled,
|
||||
personality_command_enabled: value.personality_command_enabled,
|
||||
realtime_conversation_enabled: value.realtime_conversation_enabled,
|
||||
@@ -355,6 +357,7 @@ mod tests {
|
||||
connectors_enabled: false,
|
||||
plugins_command_enabled: false,
|
||||
fast_command_enabled: false,
|
||||
job_scheduler_command_enabled: false,
|
||||
personality_command_enabled: true,
|
||||
realtime_conversation_enabled: false,
|
||||
audio_device_selection_enabled: false,
|
||||
@@ -375,6 +378,7 @@ mod tests {
|
||||
connectors_enabled: false,
|
||||
plugins_command_enabled: false,
|
||||
fast_command_enabled: false,
|
||||
job_scheduler_command_enabled: false,
|
||||
personality_command_enabled: true,
|
||||
realtime_conversation_enabled: false,
|
||||
audio_device_selection_enabled: false,
|
||||
@@ -395,6 +399,7 @@ mod tests {
|
||||
connectors_enabled: false,
|
||||
plugins_command_enabled: false,
|
||||
fast_command_enabled: false,
|
||||
job_scheduler_command_enabled: false,
|
||||
personality_command_enabled: false,
|
||||
realtime_conversation_enabled: false,
|
||||
audio_device_selection_enabled: false,
|
||||
@@ -422,6 +427,7 @@ mod tests {
|
||||
connectors_enabled: false,
|
||||
plugins_command_enabled: false,
|
||||
fast_command_enabled: false,
|
||||
job_scheduler_command_enabled: false,
|
||||
personality_command_enabled: true,
|
||||
realtime_conversation_enabled: false,
|
||||
audio_device_selection_enabled: false,
|
||||
@@ -442,6 +448,7 @@ mod tests {
|
||||
connectors_enabled: false,
|
||||
plugins_command_enabled: false,
|
||||
fast_command_enabled: false,
|
||||
job_scheduler_command_enabled: false,
|
||||
personality_command_enabled: true,
|
||||
realtime_conversation_enabled: true,
|
||||
audio_device_selection_enabled: false,
|
||||
|
||||
@@ -270,6 +270,11 @@ impl BottomPane {
|
||||
self.request_redraw();
|
||||
}
|
||||
|
||||
pub fn set_job_scheduler_command_enabled(&mut self, enabled: bool) {
|
||||
self.composer.set_job_scheduler_command_enabled(enabled);
|
||||
self.request_redraw();
|
||||
}
|
||||
|
||||
pub fn take_mention_bindings(&mut self) -> Vec<MentionBinding> {
|
||||
self.composer.take_mention_bindings()
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ pub(crate) struct BuiltinCommandFlags {
|
||||
pub(crate) collaboration_modes_enabled: bool,
|
||||
pub(crate) connectors_enabled: bool,
|
||||
pub(crate) plugins_command_enabled: bool,
|
||||
pub(crate) job_scheduler_command_enabled: bool,
|
||||
pub(crate) fast_command_enabled: bool,
|
||||
pub(crate) personality_command_enabled: bool,
|
||||
pub(crate) realtime_conversation_enabled: bool,
|
||||
@@ -33,6 +34,7 @@ pub(crate) fn builtins_for_input(flags: BuiltinCommandFlags) -> Vec<(&'static st
|
||||
})
|
||||
.filter(|(_, cmd)| flags.connectors_enabled || *cmd != SlashCommand::Apps)
|
||||
.filter(|(_, cmd)| flags.plugins_command_enabled || *cmd != SlashCommand::Plugins)
|
||||
.filter(|(_, cmd)| flags.job_scheduler_command_enabled || *cmd != SlashCommand::Loop)
|
||||
.filter(|(_, cmd)| flags.fast_command_enabled || *cmd != SlashCommand::Fast)
|
||||
.filter(|(_, cmd)| flags.personality_command_enabled || *cmd != SlashCommand::Personality)
|
||||
.filter(|(_, cmd)| flags.realtime_conversation_enabled || *cmd != SlashCommand::Realtime)
|
||||
@@ -66,6 +68,7 @@ mod tests {
|
||||
collaboration_modes_enabled: true,
|
||||
connectors_enabled: true,
|
||||
plugins_command_enabled: true,
|
||||
job_scheduler_command_enabled: true,
|
||||
fast_command_enabled: true,
|
||||
personality_command_enabled: true,
|
||||
realtime_conversation_enabled: true,
|
||||
|
||||
@@ -345,6 +345,7 @@ use crate::status_indicator_widget::STATUS_DETAILS_DEFAULT_MAX_LINES;
|
||||
use crate::status_indicator_widget::StatusDetailsCapitalization;
|
||||
use crate::text_formatting::truncate_text;
|
||||
use crate::tui::FrameRequester;
|
||||
use codex_app_server_protocol::ThreadJob;
|
||||
mod interrupts;
|
||||
use self::interrupts::InterruptManager;
|
||||
mod session_header;
|
||||
@@ -839,6 +840,7 @@ pub(crate) struct ChatWidget {
|
||||
thread_id: Option<ThreadId>,
|
||||
thread_name: Option<String>,
|
||||
forked_from: Option<ThreadId>,
|
||||
thread_jobs: Vec<ThreadJob>,
|
||||
frame_requester: FrameRequester,
|
||||
// Whether to include the initial welcome banner on session configured
|
||||
show_welcome_banner: bool,
|
||||
@@ -1949,6 +1951,7 @@ impl ChatWidget {
|
||||
self.thread_id = Some(event.session_id);
|
||||
self.thread_name = event.thread_name.clone();
|
||||
self.forked_from = event.forked_from_id;
|
||||
self.thread_jobs.clear();
|
||||
self.current_rollout_path = event.rollout_path.clone();
|
||||
self.current_cwd = Some(event.cwd.clone());
|
||||
match AbsolutePathBuf::try_from(event.cwd.clone()) {
|
||||
@@ -1996,6 +1999,7 @@ impl ChatWidget {
|
||||
self.refresh_model_display();
|
||||
self.refresh_status_surfaces();
|
||||
self.sync_fast_command_enabled();
|
||||
self.sync_job_scheduler_command_enabled();
|
||||
self.sync_personality_command_enabled();
|
||||
self.sync_plugins_command_enabled();
|
||||
self.refresh_plugin_mentions();
|
||||
@@ -2400,6 +2404,9 @@ impl ChatWidget {
|
||||
if self.has_queued_follow_up_messages() {
|
||||
return;
|
||||
}
|
||||
if !self.thread_jobs.is_empty() {
|
||||
return;
|
||||
}
|
||||
if self.active_mode_kind() != ModeKind::Plan {
|
||||
return;
|
||||
}
|
||||
@@ -4763,6 +4770,7 @@ impl ChatWidget {
|
||||
thread_id: None,
|
||||
thread_name: None,
|
||||
forked_from: None,
|
||||
thread_jobs: Vec::new(),
|
||||
queued_user_messages: VecDeque::new(),
|
||||
rejected_steers_queue: VecDeque::new(),
|
||||
pending_steers: VecDeque::new(),
|
||||
@@ -4821,6 +4829,7 @@ impl ChatWidget {
|
||||
.bottom_pane
|
||||
.set_collaboration_modes_enabled(/*enabled*/ true);
|
||||
widget.sync_fast_command_enabled();
|
||||
widget.sync_job_scheduler_command_enabled();
|
||||
widget.sync_personality_command_enabled();
|
||||
widget.sync_plugins_command_enabled();
|
||||
widget
|
||||
@@ -5147,6 +5156,14 @@ impl ChatWidget {
|
||||
SlashCommand::Review => {
|
||||
self.open_review_popup();
|
||||
}
|
||||
SlashCommand::Loop => {
|
||||
let Some(thread_id) = self.thread_id else {
|
||||
self.add_error_message("No active thread is available.".to_string());
|
||||
return;
|
||||
};
|
||||
self.app_event_tx
|
||||
.send(AppEvent::OpenThreadJobs { thread_id });
|
||||
}
|
||||
SlashCommand::Rename => {
|
||||
self.session_telemetry
|
||||
.counter("codex.thread.rename", /*inc*/ 1, &[]);
|
||||
@@ -5537,6 +5554,27 @@ impl ChatWidget {
|
||||
}));
|
||||
self.bottom_pane.drain_pending_submission_state();
|
||||
}
|
||||
SlashCommand::Loop if !trimmed.is_empty() => {
|
||||
let Some(thread_id) = self.thread_id else {
|
||||
self.add_error_message("No active thread is available.".to_string());
|
||||
return;
|
||||
};
|
||||
let Some((prepared_args, _prepared_elements)) = self
|
||||
.bottom_pane
|
||||
.prepare_inline_args_submission(/*record_history*/ false)
|
||||
else {
|
||||
return;
|
||||
};
|
||||
self.add_info_message(
|
||||
format!("Scheduling `/loop {prepared_args}`..."),
|
||||
Some("Parsing the spec and creating the thread job.".to_string()),
|
||||
);
|
||||
self.app_event_tx.send(AppEvent::CreateThreadJobFromSpec {
|
||||
thread_id,
|
||||
spec: prepared_args,
|
||||
});
|
||||
self.bottom_pane.drain_pending_submission_state();
|
||||
}
|
||||
SlashCommand::SandboxReadRoot if !trimmed.is_empty() => {
|
||||
let Some((prepared_args, _prepared_elements)) = self
|
||||
.bottom_pane
|
||||
@@ -6397,6 +6435,10 @@ impl ChatWidget {
|
||||
}
|
||||
}
|
||||
}
|
||||
ServerNotification::ThreadJobUpdated(notification) => {
|
||||
self.on_thread_jobs_updated(notification.jobs);
|
||||
}
|
||||
ServerNotification::ThreadJobFired(_) => {}
|
||||
ServerNotification::TurnStarted(_) => {
|
||||
self.last_non_retry_error = None;
|
||||
if !matches!(replay_kind, Some(ReplayKind::ResumeInitialMessages)) {
|
||||
@@ -9372,6 +9414,9 @@ impl ChatWidget {
|
||||
if feature == Feature::FastMode {
|
||||
self.sync_fast_command_enabled();
|
||||
}
|
||||
if feature == Feature::JobScheduler {
|
||||
self.sync_job_scheduler_command_enabled();
|
||||
}
|
||||
if feature == Feature::Personality {
|
||||
self.sync_personality_command_enabled();
|
||||
}
|
||||
@@ -9612,6 +9657,11 @@ impl ChatWidget {
|
||||
.set_fast_command_enabled(self.fast_mode_enabled());
|
||||
}
|
||||
|
||||
fn sync_job_scheduler_command_enabled(&mut self) {
|
||||
self.bottom_pane
|
||||
.set_job_scheduler_command_enabled(self.config.features.enabled(Feature::JobScheduler));
|
||||
}
|
||||
|
||||
fn sync_personality_command_enabled(&mut self) {
|
||||
self.bottom_pane
|
||||
.set_personality_command_enabled(self.config.features.enabled(Feature::Personality));
|
||||
@@ -9933,6 +9983,56 @@ impl ChatWidget {
|
||||
self.request_redraw();
|
||||
}
|
||||
|
||||
pub(crate) fn on_thread_jobs_updated(&mut self, jobs: Vec<ThreadJob>) {
|
||||
self.thread_jobs = jobs;
|
||||
}
|
||||
|
||||
pub(crate) fn open_thread_jobs_popup(&mut self, thread_id: ThreadId, jobs: Vec<ThreadJob>) {
|
||||
self.thread_jobs = jobs.clone();
|
||||
if jobs.is_empty() {
|
||||
self.add_info_message(
|
||||
"No thread jobs are currently scheduled.".to_string(),
|
||||
Some("Use `/loop <spec>` to create one.".to_string()),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
let items = jobs
|
||||
.into_iter()
|
||||
.map(|job| {
|
||||
let job_id = job.id.clone();
|
||||
let actions: Vec<SelectionAction> = vec![Box::new(move |tx| {
|
||||
tx.send(AppEvent::DeleteThreadJob {
|
||||
thread_id,
|
||||
id: job_id.clone(),
|
||||
});
|
||||
})];
|
||||
let name = if job.run_once {
|
||||
format!("{} • one-shot", job.cron_expression)
|
||||
} else {
|
||||
job.cron_expression.clone()
|
||||
};
|
||||
SelectionItem {
|
||||
name,
|
||||
description: Some(job.prompt),
|
||||
selected_description: Some("Delete this job.".to_string()),
|
||||
is_current: false,
|
||||
actions,
|
||||
dismiss_on_select: true,
|
||||
..Default::default()
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
self.bottom_pane.show_selection_view(SelectionViewParams {
|
||||
title: Some("Thread jobs".to_string()),
|
||||
subtitle: Some("Select a job to delete it.".to_string()),
|
||||
footer_hint: Some(standard_popup_hint_line()),
|
||||
items,
|
||||
..Default::default()
|
||||
});
|
||||
self.request_redraw();
|
||||
}
|
||||
|
||||
pub(crate) fn add_plain_history_lines(&mut self, lines: Vec<Line<'static>>) {
|
||||
self.add_boxed_history(Box::new(PlainHistoryCell::new(lines)));
|
||||
self.request_redraw();
|
||||
|
||||
-18
@@ -1,18 +0,0 @@
|
||||
---
|
||||
source: tui/src/chatwidget/tests.rs
|
||||
assertion_line: 9607
|
||||
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. Guardian Approvals Same workspace-write permissions as Default, but
|
||||
eligible `on-request` approvals are routed through
|
||||
the guardian reviewer subagent.
|
||||
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
|
||||
-10
@@ -1,10 +0,0 @@
|
||||
---
|
||||
source: tui/src/chatwidget/tests.rs
|
||||
assertion_line: 12789
|
||||
expression: combined
|
||||
---
|
||||
• Running UserPromptSubmit hook: checking go-workflow input policy
|
||||
|
||||
UserPromptSubmit hook (stopped)
|
||||
warning: go-workflow must start from PlanMode
|
||||
stop: prompt blocked
|
||||
@@ -200,14 +200,14 @@ use tokio::sync::mpsc::unbounded_channel;
|
||||
use toml::Value as TomlValue;
|
||||
|
||||
async fn test_config() -> Config {
|
||||
// Use base defaults to avoid depending on host state.
|
||||
let codex_home = std::env::temp_dir();
|
||||
ConfigBuilder::default()
|
||||
.codex_home(codex_home.clone())
|
||||
.fallback_cwd(Some(PathBuf::from(test_path_display("/tmp/project"))))
|
||||
.build()
|
||||
.await
|
||||
.expect("config")
|
||||
// Start from built-in defaults so test feature state does not inherit
|
||||
// host config layers or managed requirements from the machine.
|
||||
let mut config = Config::load_default_with_cli_overrides(Vec::new()).expect("config");
|
||||
config.codex_home = std::env::temp_dir();
|
||||
config.cwd =
|
||||
AbsolutePathBuf::try_from(PathBuf::from(test_path_display("/tmp/project"))).expect("cwd");
|
||||
config.config_layer_stack = codex_core::config_loader::ConfigLayerStack::default();
|
||||
config
|
||||
}
|
||||
|
||||
fn test_project_path() -> PathBuf {
|
||||
@@ -2123,6 +2123,7 @@ async fn make_chatwidget_manual(
|
||||
pending_turn_copyable_output: None,
|
||||
running_commands: HashMap::new(),
|
||||
collab_agent_metadata: HashMap::new(),
|
||||
thread_jobs: Vec::new(),
|
||||
pending_collab_spawn_requests: HashMap::new(),
|
||||
suppressed_exec_calls: HashSet::new(),
|
||||
skills_all: Vec::new(),
|
||||
@@ -9741,6 +9742,7 @@ async fn approvals_selection_popup_snapshot() {
|
||||
let (mut chat, _rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
||||
|
||||
chat.config.notices.hide_full_access_warning = None;
|
||||
chat.set_feature_enabled(Feature::GuardianApproval, /*enabled*/ false);
|
||||
chat.open_approvals_popup();
|
||||
|
||||
let popup = render_bottom_popup(&chat, /*width*/ 80);
|
||||
@@ -10409,6 +10411,7 @@ async fn permissions_selection_history_snapshot_after_mode_switch() {
|
||||
chat.set_windows_sandbox_mode(Some(WindowsSandboxModeToml::Unelevated));
|
||||
}
|
||||
chat.config.notices.hide_full_access_warning = Some(true);
|
||||
chat.set_feature_enabled(Feature::GuardianApproval, /*enabled*/ false);
|
||||
|
||||
chat.open_permissions_popup();
|
||||
chat.handle_key_event(KeyEvent::from(KeyCode::Down));
|
||||
@@ -10509,6 +10512,7 @@ async fn permissions_selection_hides_guardian_approvals_when_feature_disabled()
|
||||
chat.set_windows_sandbox_mode(Some(WindowsSandboxModeToml::Unelevated));
|
||||
}
|
||||
chat.config.notices.hide_full_access_warning = Some(true);
|
||||
chat.set_feature_enabled(Feature::GuardianApproval, /*enabled*/ false);
|
||||
|
||||
chat.open_permissions_popup();
|
||||
let popup = render_bottom_popup(&chat, /*width*/ 120);
|
||||
@@ -10529,6 +10533,7 @@ async fn permissions_selection_hides_guardian_approvals_when_feature_disabled_ev
|
||||
chat.set_windows_sandbox_mode(Some(WindowsSandboxModeToml::Unelevated));
|
||||
}
|
||||
chat.config.notices.hide_full_access_warning = Some(true);
|
||||
chat.set_feature_enabled(Feature::GuardianApproval, /*enabled*/ false);
|
||||
chat.config.approvals_reviewer = ApprovalsReviewer::GuardianSubagent;
|
||||
chat.config
|
||||
.permissions
|
||||
@@ -10765,6 +10770,7 @@ async fn permissions_full_access_history_cell_emitted_only_after_confirmation()
|
||||
chat.set_windows_sandbox_mode(Some(WindowsSandboxModeToml::Unelevated));
|
||||
}
|
||||
chat.config.notices.hide_full_access_warning = None;
|
||||
chat.set_feature_enabled(Feature::GuardianApproval, /*enabled*/ false);
|
||||
|
||||
chat.open_permissions_popup();
|
||||
chat.handle_key_event(KeyEvent::from(KeyCode::Down));
|
||||
|
||||
@@ -0,0 +1,158 @@
|
||||
use crate::AppServerTarget;
|
||||
use crate::start_app_server_for_picker;
|
||||
use codex_app_server_client::AppServerEvent;
|
||||
use codex_app_server_protocol::ServerNotification;
|
||||
use codex_app_server_protocol::ThreadItem;
|
||||
use codex_core::config::Config;
|
||||
use codex_protocol::user_input::UserInput;
|
||||
use serde::Deserialize;
|
||||
use serde_json::json;
|
||||
use tracing::warn;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub(crate) struct ParsedJobSpec {
|
||||
pub(crate) cron_expression: String,
|
||||
pub(crate) prompt: String,
|
||||
pub(crate) run_once: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct ParsedJobSpecResponse {
|
||||
cron_expression: String,
|
||||
prompt: String,
|
||||
run_once: Option<bool>,
|
||||
}
|
||||
|
||||
impl ParsedJobSpecResponse {
|
||||
fn into_parsed(self) -> std::result::Result<ParsedJobSpec, String> {
|
||||
let cron_expression = self.cron_expression.trim().to_string();
|
||||
let prompt = self.prompt.trim().to_string();
|
||||
if cron_expression.is_empty() {
|
||||
return Err("Could not determine a supported schedule from /loop input.".to_string());
|
||||
}
|
||||
if prompt.is_empty() {
|
||||
return Err("Could not determine a prompt from /loop input.".to_string());
|
||||
}
|
||||
Ok(ParsedJobSpec {
|
||||
cron_expression,
|
||||
prompt,
|
||||
run_once: self.run_once,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) async fn parse_job_spec(
|
||||
config: Config,
|
||||
target: AppServerTarget,
|
||||
spec: String,
|
||||
) -> std::result::Result<ParsedJobSpec, String> {
|
||||
let mut app_server = start_app_server_for_picker(&config, &target)
|
||||
.await
|
||||
.map_err(|err| format!("Failed to start parser session: {err}"))?;
|
||||
let result = async {
|
||||
let thread = app_server
|
||||
.start_ephemeral_thread(&config)
|
||||
.await
|
||||
.map_err(|err| format!("Failed to start parser thread: {err}"))?;
|
||||
|
||||
let output_schema = json!({
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"cronExpression": { "type": "string" },
|
||||
"prompt": { "type": "string" },
|
||||
"runOnce": { "type": ["boolean", "null"] }
|
||||
},
|
||||
"required": ["cronExpression", "prompt", "runOnce"],
|
||||
"additionalProperties": false
|
||||
});
|
||||
|
||||
let parser_prompt = format!(
|
||||
"{}\n{}",
|
||||
concat!(
|
||||
"Convert the user's /loop spec into JSON with keys cronExpression, prompt, and runOnce.\n",
|
||||
"Only emit valid JSON matching the schema.\n",
|
||||
"Supported cronExpression values for this client are:\n",
|
||||
"- @after-turn\n",
|
||||
"- @every <N>s\n",
|
||||
"- @every <N>m\n",
|
||||
"- @every <N>h\n",
|
||||
"- @every <N>d\n",
|
||||
"Use @after-turn when no explicit interval is present.\n",
|
||||
"Set runOnce to true only when the user clearly asked for a one-shot run.\n",
|
||||
"Keep stop conditions and job intent inside prompt.\n",
|
||||
"If the schedule request is unsupported by the allowed cronExpression formats, return an empty cronExpression.\n",
|
||||
"User spec:"
|
||||
),
|
||||
spec
|
||||
);
|
||||
|
||||
app_server
|
||||
.turn_start(
|
||||
codex_protocol::ThreadId::from_string(&thread.id)
|
||||
.map_err(|err| format!("Parser thread id was invalid: {err}"))?,
|
||||
vec![UserInput::Text {
|
||||
text: parser_prompt,
|
||||
text_elements: Vec::new(),
|
||||
}],
|
||||
config.cwd.to_path_buf(),
|
||||
config.permissions.approval_policy.value(),
|
||||
config.approvals_reviewer,
|
||||
config.permissions.sandbox_policy.get().clone(),
|
||||
config.model.clone().unwrap_or_default(),
|
||||
/*effort*/ None,
|
||||
/*summary*/ None,
|
||||
config.service_tier.map(Some),
|
||||
/*collaboration_mode*/ None,
|
||||
config.personality,
|
||||
Some(output_schema),
|
||||
)
|
||||
.await
|
||||
.map_err(|err| format!("Failed to run /loop parser prompt: {err}"))?;
|
||||
|
||||
let mut final_message = None;
|
||||
while let Some(event) = app_server.next_event().await {
|
||||
match event {
|
||||
AppServerEvent::ServerNotification(ServerNotification::ItemCompleted(
|
||||
notification,
|
||||
)) => {
|
||||
if let ThreadItem::AgentMessage { text, .. } = notification.item {
|
||||
final_message = Some(text);
|
||||
}
|
||||
}
|
||||
AppServerEvent::ServerNotification(ServerNotification::TurnCompleted(
|
||||
notification,
|
||||
)) => {
|
||||
if notification.turn.error.is_some() {
|
||||
return Err("The /loop parser turn failed.".to_string());
|
||||
}
|
||||
break;
|
||||
}
|
||||
AppServerEvent::Disconnected { message } => {
|
||||
return Err(format!("The /loop parser session disconnected: {message}"));
|
||||
}
|
||||
AppServerEvent::Lagged { .. }
|
||||
| AppServerEvent::ServerNotification(_)
|
||||
| AppServerEvent::ServerRequest(_) => {}
|
||||
}
|
||||
}
|
||||
|
||||
let response =
|
||||
final_message.ok_or_else(|| "The /loop parser returned no output.".to_string())?;
|
||||
let parsed: ParsedJobSpecResponse = serde_json::from_str(&response)
|
||||
.map_err(|err| format!("Invalid /loop parser JSON: {err}"))?;
|
||||
parsed.into_parsed()
|
||||
}
|
||||
.await;
|
||||
|
||||
if let Err(err) = app_server.shutdown().await {
|
||||
warn!(%err, "failed to shut down temporary /loop parser session");
|
||||
}
|
||||
|
||||
result
|
||||
}
|
||||
|
||||
pub(crate) fn format_job_summary(cron_expression: &str, run_once: bool, prompt: &str) -> String {
|
||||
let mode = if run_once { "one-shot" } else { "recurring" };
|
||||
format!("{cron_expression} ({mode}) -> {prompt}")
|
||||
}
|
||||
@@ -113,6 +113,7 @@ mod frames;
|
||||
mod get_git_diff;
|
||||
mod history_cell;
|
||||
pub mod insert_history;
|
||||
mod job_scheduler;
|
||||
mod key_hint;
|
||||
mod line_truncation;
|
||||
pub mod live_wrap;
|
||||
|
||||
@@ -23,6 +23,7 @@ pub enum SlashCommand {
|
||||
Experimental,
|
||||
Skills,
|
||||
Review,
|
||||
Loop,
|
||||
Rename,
|
||||
New,
|
||||
Resume,
|
||||
@@ -75,6 +76,7 @@ impl SlashCommand {
|
||||
SlashCommand::Init => "create an AGENTS.md file with instructions for Codex",
|
||||
SlashCommand::Compact => "summarize conversation to prevent hitting the context limit",
|
||||
SlashCommand::Review => "review my current changes and find issues",
|
||||
SlashCommand::Loop => "create or list thread jobs",
|
||||
SlashCommand::Rename => "rename the current thread",
|
||||
SlashCommand::Resume => "resume a saved chat",
|
||||
SlashCommand::Clear => "clear the terminal and start a new chat",
|
||||
@@ -130,6 +132,7 @@ impl SlashCommand {
|
||||
self,
|
||||
SlashCommand::Review
|
||||
| SlashCommand::Rename
|
||||
| SlashCommand::Loop
|
||||
| SlashCommand::Plan
|
||||
| SlashCommand::Fast
|
||||
| SlashCommand::SandboxReadRoot
|
||||
@@ -162,6 +165,7 @@ impl SlashCommand {
|
||||
SlashCommand::Diff
|
||||
| SlashCommand::Copy
|
||||
| SlashCommand::Rename
|
||||
| SlashCommand::Loop
|
||||
| SlashCommand::Mention
|
||||
| SlashCommand::Skills
|
||||
| SlashCommand::Status
|
||||
|
||||
Reference in New Issue
Block a user