Skip to content

Commit 83d0153

Browse files
etraut-openaicopyberry
authored andcommitted
Add a command to queue messages for existing sessions (#39092)
## What changed - Add `codex queue --thread <THREAD> --message <TEXT>` to submit a text message through the `thread/queue/add` app-server API. - Resolve active sessions by UUID or exact name across interactive, exec, and custom sources, and reject ambiguous names. - Support local and explicit remote app servers while reporting incompatible servers and configuration overrides instead of silently changing the target. - Reject empty messages and image attachments. ## Testing - Add CLI coverage for remote submission, validation, unsupported servers, and local-daemon routing. - Add session lookup and queue tests for stale, non-interactive, custom, and duplicate session names. GitOrigin-RevId: 44c233f752b63a85c85b92fa6da303336e4ddeca
1 parent 31f23b6 commit 83d0153

9 files changed

Lines changed: 772 additions & 32 deletions

‎codex-rs/cli/src/main.rs‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ mod marketplace_cmd;
5555
mod mcp_cmd;
5656
mod migrate_rollouts;
5757
mod plugin_cmd;
58+
mod queue_cmd;
5859
mod remote_control_cmd;
5960
#[cfg(target_os = "windows")]
6061
mod sandbox_setup;
@@ -65,6 +66,7 @@ mod wsl_paths;
6566
use crate::mcp_cmd::McpCli;
6667
use crate::plugin_cmd::PluginCli;
6768
use crate::plugin_cmd::PluginSubcommand;
69+
use crate::queue_cmd::QueueCommand;
6870
use crate::remote_control_cmd::RemoteControlCommand;
6971
use doctor::DoctorCommand;
7072
use state_db_recovery as local_state_db;
@@ -187,6 +189,9 @@ enum Subcommand {
187189
/// Resume a previous interactive session (picker by default; use --last to continue the most recent).
188190
Resume(ResumeCommand),
189191

192+
/// Queue a message for an existing session.
193+
Queue(QueueCommand),
194+
190195
/// Archive a saved session by id or session name.
191196
Archive(SessionArchiveCommand),
192197

@@ -1324,6 +1329,18 @@ async fn cli_main(
13241329
.await?;
13251330
println!("{output}");
13261331
}
1332+
Some(Subcommand::Queue(cmd)) => {
1333+
let output = queue_cmd::run_queue_command(
1334+
cmd,
1335+
interactive,
1336+
root_config_overrides.clone(),
1337+
root_remote.clone(),
1338+
root_remote_auth_token_env.clone(),
1339+
arg0_paths.clone(),
1340+
)
1341+
.await?;
1342+
println!("{output}");
1343+
}
13271344
Some(Subcommand::Delete(DeleteCommand { session, force })) => {
13281345
let action = delete_action(&session.target, force)?;
13291346
let output = run_session_archive_cli_command(
@@ -1707,6 +1724,7 @@ fn profile_v2_for_subcommand<'a>(
17071724
Subcommand::Exec(_)
17081725
| Subcommand::Review(_)
17091726
| Subcommand::Resume(_)
1727+
| Subcommand::Queue(_)
17101728
| Subcommand::Archive(_)
17111729
| Subcommand::Delete(_)
17121730
| Subcommand::Unarchive(_)
@@ -1717,7 +1735,7 @@ fn profile_v2_for_subcommand<'a>(
17171735
subcommand: DebugSubcommand::PromptInput(_),
17181736
}) => Ok(Some(profile_v2)),
17191737
_ => anyhow::bail!(
1720-
"--profile only applies to runtime commands and `codex mcp`: `codex`, `codex exec`, `codex review`, `codex resume`, `codex archive`, `codex delete`, `codex unarchive`, `codex fork`, `codex mcp`, `codex sandbox`, and `codex debug prompt-input`."
1738+
"--profile only applies to runtime commands and `codex mcp`: `codex`, `codex exec`, `codex review`, `codex resume`, `codex queue`, `codex archive`, `codex delete`, `codex unarchive`, `codex fork`, `codex mcp`, `codex sandbox`, and `codex debug prompt-input`."
17211739
),
17221740
}
17231741
}
@@ -2275,6 +2293,7 @@ fn unsupported_subcommand_name_for_strict_config(
22752293
| Some(Subcommand::McpServer(_))
22762294
| Some(Subcommand::ExecServer(_))
22772295
| Some(Subcommand::Resume(_))
2296+
| Some(Subcommand::Queue(_))
22782297
| Some(Subcommand::Archive(_))
22792298
| Some(Subcommand::Delete(_))
22802299
| Some(Subcommand::Unarchive(_))

‎codex-rs/cli/src/queue_cmd.rs‎

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
use clap::Parser;
2+
use clap::builder::NonEmptyStringValueParser;
3+
use codex_arg0::Arg0DispatchPaths;
4+
use codex_tui::Cli as TuiCli;
5+
use codex_utils_cli::CliConfigOverrides;
6+
7+
use crate::InteractiveRemoteOptions;
8+
use crate::SessionArchiveConfigOverrides;
9+
use crate::finalize_session_archive_interactive;
10+
use crate::resolve_remote_endpoint;
11+
12+
#[derive(Debug, Parser)]
13+
pub(crate) struct QueueCommand {
14+
/// Session UUID or exact session name.
15+
#[arg(long, value_name = "THREAD")]
16+
thread: String,
17+
18+
/// Message text to queue.
19+
#[arg(long, value_name = "TEXT", value_parser = NonEmptyStringValueParser::new())]
20+
message: String,
21+
22+
#[clap(flatten)]
23+
remote: InteractiveRemoteOptions,
24+
25+
#[clap(flatten)]
26+
config_overrides: SessionArchiveConfigOverrides,
27+
}
28+
29+
pub(crate) async fn run_queue_command(
30+
command: QueueCommand,
31+
interactive: TuiCli,
32+
root_config_overrides: CliConfigOverrides,
33+
root_remote: Option<String>,
34+
root_remote_auth_token_env: Option<String>,
35+
arg0_paths: Arg0DispatchPaths,
36+
) -> anyhow::Result<String> {
37+
let QueueCommand {
38+
thread,
39+
message,
40+
remote,
41+
config_overrides,
42+
} = command;
43+
let cli =
44+
finalize_session_archive_interactive(interactive, root_config_overrides, config_overrides);
45+
if !cli.images.is_empty() {
46+
anyhow::bail!("`codex queue` does not support image attachments");
47+
}
48+
let explicit_remote_endpoint = resolve_remote_endpoint(
49+
remote.remote.or(root_remote),
50+
remote.remote_auth_token_env.or(root_remote_auth_token_env),
51+
)?;
52+
codex_tui::run_session_queue_command(
53+
thread,
54+
message,
55+
codex_tui::SessionArchiveCommandOptions {
56+
cli,
57+
arg0_paths,
58+
explicit_remote_endpoint,
59+
},
60+
)
61+
.await
62+
.map_err(|error| anyhow::anyhow!("{error:#}"))
63+
}

0 commit comments

Comments
 (0)