mirror of
https://github.com/openai/codex.git
synced 2026-11-20 07:06:24 +00:00
Add managed worktree creation to TUI session commands (#43120)
## What changed - Add `/worktree` to start a fresh conversation or fork the current conversation into a new managed checkout. - Offer current-checkout and new-worktree choices for `/new` and `/fork`, preserving optional conversation names. Enable these choices for local Git repositories when the `worktrees` feature is enabled. - Load destination configuration, bind the checkout to the replacement thread, and inherit conversation history only when forking. - Reject creation from explicitly untrusted sources and require an idle primary session without queued input. Refuse forks when developer instructions differ, with guidance for removing the unused checkout. ## Testing Add picker snapshots and tests for command availability, named selections, fresh versus forked history, destination configuration, worktree ownership, and feature and trust checks. GitOrigin-RevId: d6c83e00217660aacf2a6d92acad50b506607e0b
This commit is contained in:
1 parent
f5a71ff40a
commit
f6976ab036
28 files changed
+980
-30
No files matched your search
@@ -50,6 +50,10 @@ impl App {
|
|||||||
| AppEvent::SelectAgentThread(_)
|
| AppEvent::SelectAgentThread(_)
|
||||||
| AppEvent::StartSide { .. }
|
| AppEvent::StartSide { .. }
|
||||||
| AppEvent::ForkCurrentSession { .. }
|
| AppEvent::ForkCurrentSession { .. }
|
||||||
|
| AppEvent::StartManagedWorktree {
|
||||||
|
mode: crate::app_event::ManagedWorktreeMode::Fork,
|
||||||
|
..
|
||||||
|
}
|
||||||
| AppEvent::ForkSessionForPromptEdit { .. }
|
| AppEvent::ForkSessionForPromptEdit { .. }
|
||||||
| AppEvent::SetThreadGoalDraft { .. }
|
| AppEvent::SetThreadGoalDraft { .. }
|
||||||
| AppEvent::SetThreadGoalStatus {
|
| AppEvent::SetThreadGoalStatus {
|
||||||
@@ -86,6 +90,9 @@ impl App {
|
|||||||
self.chat_widget.show_misalignment_policy_precaution();
|
self.chat_widget.show_misalignment_policy_precaution();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
AppEvent::StartManagedWorktree { mode, name } => {
|
||||||
|
self.start_managed_worktree(tui, app_server, mode, name).await;
|
||||||
|
}
|
||||||
AppEvent::ChangeWorkingDirectory {
|
AppEvent::ChangeWorkingDirectory {
|
||||||
thread_id,
|
thread_id,
|
||||||
requested_cwd,
|
requested_cwd,
|
||||||
|
|||||||
@@ -244,6 +244,12 @@ impl App {
|
|||||||
self.rate_limit_refresh_state.invalidate_recovery();
|
self.rate_limit_refresh_state.invalidate_recovery();
|
||||||
session.inherit_task_tool_capabilities(app_server);
|
session.inherit_task_tool_capabilities(app_server);
|
||||||
*app_server = session;
|
*app_server = session;
|
||||||
|
self.chat_widget.set_local_worktree_operations(
|
||||||
|
!crate::uses_remote_workspace_or_environment(
|
||||||
|
&self.app_server_target,
|
||||||
|
self.environment_manager.as_ref(),
|
||||||
|
),
|
||||||
|
);
|
||||||
self.chat_widget.cyber_policy_notice = Default::default();
|
self.chat_widget.cyber_policy_notice = Default::default();
|
||||||
self.chat_widget.requires_openai_auth = bootstrap.requires_openai_auth;
|
self.chat_widget.requires_openai_auth = bootstrap.requires_openai_auth;
|
||||||
self.chat_widget.remote_connection =
|
self.chat_widget.remote_connection =
|
||||||
|
|||||||
@@ -486,6 +486,7 @@ impl App {
|
|||||||
chat_widget.last_terminal_title = previous_terminal_title;
|
chat_widget.last_terminal_title = previous_terminal_title;
|
||||||
}
|
}
|
||||||
chat_widget.remote_connection = self.chat_widget.remote_connection.clone();
|
chat_widget.remote_connection = self.chat_widget.remote_connection.clone();
|
||||||
|
chat_widget.set_local_worktree_operations(self.chat_widget.local_worktree_operations);
|
||||||
chat_widget.set_agents_navigation_enabled(matches!(
|
chat_widget.set_agents_navigation_enabled(matches!(
|
||||||
self.app_server_target,
|
self.app_server_target,
|
||||||
AppServerTarget::LocalDaemon { .. }
|
AppServerTarget::LocalDaemon { .. }
|
||||||
|
|||||||
@@ -505,6 +505,10 @@ impl App {
|
|||||||
};
|
};
|
||||||
chat_widget.note_rendered_width(tui.terminal.last_known_screen_size.width);
|
chat_widget.note_rendered_width(tui.terminal.last_known_screen_size.width);
|
||||||
chat_widget.remote_connection = remote_connection;
|
chat_widget.remote_connection = remote_connection;
|
||||||
|
chat_widget.set_local_worktree_operations(!crate::uses_remote_workspace_or_environment(
|
||||||
|
&app_server_target,
|
||||||
|
environment_manager.as_ref(),
|
||||||
|
));
|
||||||
chat_widget.set_agents_navigation_enabled(matches!(
|
chat_widget.set_agents_navigation_enabled(matches!(
|
||||||
app_server_target,
|
app_server_target,
|
||||||
AppServerTarget::LocalDaemon { .. }
|
AppServerTarget::LocalDaemon { .. }
|
||||||
|
|||||||
@@ -2762,6 +2762,287 @@ async fn cold_paginated_subagent_transcript_excludes_inherited_parent_history()
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn managed_worktree_transitions_bind_owner_and_preserve_only_fork_history() -> Result<()> {
|
||||||
|
use crate::app_event::ManagedWorktreeMode;
|
||||||
|
use std::fs;
|
||||||
|
use std::process::Command;
|
||||||
|
|
||||||
|
let (mut app, mut events, _op_rx) = make_test_app_with_channels().await;
|
||||||
|
let root = tempdir()?;
|
||||||
|
let home = dunce::canonicalize(root.path())?.join("home");
|
||||||
|
let source = dunce::canonicalize(root.path())?.join("source");
|
||||||
|
let project_pool = dunce::canonicalize(root.path())?.join("project-pool");
|
||||||
|
fs::create_dir_all(&home)?;
|
||||||
|
fs::create_dir_all(source.join(".codex"))?;
|
||||||
|
fs::write(home.join("config.toml"), "[features]\nworktrees = true\n")?;
|
||||||
|
crate::legacy_core::config::set_project_trust_level(
|
||||||
|
&home,
|
||||||
|
&source,
|
||||||
|
codex_protocol::config_types::TrustLevel::Trusted,
|
||||||
|
)
|
||||||
|
.map_err(|error| color_eyre::eyre::eyre!(error.to_string()))?;
|
||||||
|
let destination = format!(
|
||||||
|
r#"developer_instructions = "committed policy"
|
||||||
|
model = "gpt-5.2"
|
||||||
|
model_reasoning_effort = "high"
|
||||||
|
[desktop]
|
||||||
|
git-worktree-root = {}
|
||||||
|
"#,
|
||||||
|
toml::Value::String(project_pool.display().to_string()),
|
||||||
|
);
|
||||||
|
fs::write(source.join(".codex/config.toml"), destination)?;
|
||||||
|
fs::write(source.join("AGENTS.md"), "committed worktree instructions")?;
|
||||||
|
for args in [
|
||||||
|
vec!["init", "--quiet"],
|
||||||
|
vec!["add", "."],
|
||||||
|
vec!["commit", "--quiet", "--no-gpg-sign", "-m", "initial"],
|
||||||
|
] {
|
||||||
|
let result = Command::new("git")
|
||||||
|
.current_dir(&source)
|
||||||
|
.args([
|
||||||
|
"-c",
|
||||||
|
"user.name=Worktree Test",
|
||||||
|
"-c",
|
||||||
|
"user.email=test@example.invalid",
|
||||||
|
])
|
||||||
|
.args(args)
|
||||||
|
.output()?;
|
||||||
|
assert!(
|
||||||
|
result.status.success(),
|
||||||
|
"{}",
|
||||||
|
String::from_utf8_lossy(&result.stderr)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
fs::write(
|
||||||
|
source.join(".codex/config.toml"),
|
||||||
|
r#"developer_instructions = "dirty policy"
|
||||||
|
model = "gpt-5.4"
|
||||||
|
model_reasoning_effort = "low"
|
||||||
|
"#,
|
||||||
|
)?;
|
||||||
|
fs::write(source.join("AGENTS.md"), "dirty source instructions")?;
|
||||||
|
app.config.codex_home = home.clone().abs();
|
||||||
|
app.config.sqlite = SqliteConfig::new_for_testing(home.clone().abs());
|
||||||
|
app.config.cwd = source.clone().abs();
|
||||||
|
app.harness_overrides.permission_profile = Some(PermissionProfile::workspace_write());
|
||||||
|
app.config = app.rebuild_config_for_cwd(source.clone()).await?;
|
||||||
|
app.chat_widget
|
||||||
|
.handle_thread_session_quiet(test_thread_session(ThreadId::new(), source.clone()));
|
||||||
|
let (mut server, requests, proxy) = start_recording_app_server(
|
||||||
|
&app.config,
|
||||||
|
/*blocked_thread_list*/ None,
|
||||||
|
/*failed_thread_name*/ None,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
let mut tui = crate::tui::test_support::make_test_tui()?;
|
||||||
|
app.start_fresh_session_with_summary_hint(
|
||||||
|
&mut tui,
|
||||||
|
&mut server,
|
||||||
|
/*session_start_source*/ None,
|
||||||
|
/*initial_user_message*/ None,
|
||||||
|
/*new_thread_name*/ None,
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
assert_eq!(
|
||||||
|
(
|
||||||
|
app.chat_widget.current_model(),
|
||||||
|
app.config.model_provider_id.as_str(),
|
||||||
|
app.chat_widget.current_reasoning_effort()
|
||||||
|
),
|
||||||
|
("gpt-5.4", "openai", Some(ReasoningEffortConfig::Low))
|
||||||
|
);
|
||||||
|
// Provider selection belongs to host config, not project config.
|
||||||
|
let host_config = home.join("config.toml");
|
||||||
|
let contents = fs::read_to_string(&host_config)?;
|
||||||
|
fs::write(
|
||||||
|
host_config,
|
||||||
|
format!("model_provider = \"ollama\"\n{contents}"),
|
||||||
|
)?;
|
||||||
|
let original = app.chat_widget.thread_id().expect("original thread");
|
||||||
|
server.thread_inject_items(original, vec![serde_json::from_value(serde_json::json!({
|
||||||
|
"type": "message", "role": "assistant", "content": [{"type": "output_text", "text": "managed fork history"}]
|
||||||
|
}))?]).await?;
|
||||||
|
let manager = codex_worktree::WorktreeManager::new(
|
||||||
|
codex_worktree::WorktreeSettings::for_cli(&home, /*desktop*/ None)
|
||||||
|
.map_err(|error| color_eyre::eyre::eyre!(error.to_string()))?,
|
||||||
|
);
|
||||||
|
requests.lock().expect("request recorder lock").clear();
|
||||||
|
app.handle_event(
|
||||||
|
&mut tui,
|
||||||
|
&mut server,
|
||||||
|
AppEvent::StartManagedWorktree {
|
||||||
|
mode: ManagedWorktreeMode::Fork,
|
||||||
|
name: None,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
assert_eq!(app.chat_widget.thread_id(), Some(original));
|
||||||
|
assert!(recorded_params(&requests, "thread/fork").is_empty());
|
||||||
|
let unused = manager
|
||||||
|
.list(&source)
|
||||||
|
.map_err(|error| color_eyre::eyre::eyre!(error.to_string()))?
|
||||||
|
.pop()
|
||||||
|
.expect("unused checkout");
|
||||||
|
assert_eq!(
|
||||||
|
manager
|
||||||
|
.owner(&unused.root)
|
||||||
|
.map_err(|error| color_eyre::eyre::eyre!(error.to_string()))?,
|
||||||
|
None
|
||||||
|
);
|
||||||
|
let error = std::iter::from_fn(|| events.try_recv().ok())
|
||||||
|
.filter_map(|event| match event {
|
||||||
|
AppEvent::InsertHistoryCell(cell) => {
|
||||||
|
Some(lines_to_single_string(&cell.display_lines(/*width*/ 500)))
|
||||||
|
}
|
||||||
|
_ => None,
|
||||||
|
})
|
||||||
|
.find(|message| message.contains("Cannot fork into this worktree"))
|
||||||
|
.expect("fork refusal");
|
||||||
|
let (_, with_path) = error
|
||||||
|
.split_once("An unused checkout was created at ")
|
||||||
|
.expect("checkout marker");
|
||||||
|
let (path, _) = with_path
|
||||||
|
.split_once("; remove it with")
|
||||||
|
.expect("cleanup marker");
|
||||||
|
insta::assert_snapshot!(error.replace(path, "<CHECKOUT>"), @"■ Cannot fork into this worktree because developer instructions differ. Start a new conversation instead. An unused checkout was created at <CHECKOUT>; remove it with `git worktree remove <checkout-path>` from the source repository.");
|
||||||
|
fs::write(
|
||||||
|
source.join(".codex/config.toml"),
|
||||||
|
r#"developer_instructions = "committed policy"
|
||||||
|
[features]
|
||||||
|
terminal_visualization_instructions = true
|
||||||
|
"#,
|
||||||
|
)?;
|
||||||
|
app.config = app.rebuild_config_for_cwd(source.clone()).await?;
|
||||||
|
requests.lock().expect("request recorder lock").clear();
|
||||||
|
app.handle_event(
|
||||||
|
&mut tui,
|
||||||
|
&mut server,
|
||||||
|
AppEvent::StartManagedWorktree {
|
||||||
|
mode: ManagedWorktreeMode::Fork,
|
||||||
|
name: None,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
assert_eq!(app.chat_widget.thread_id(), Some(original));
|
||||||
|
assert!(recorded_params(&requests, "thread/fork").is_empty());
|
||||||
|
for mode in [ManagedWorktreeMode::New, ManagedWorktreeMode::Fork] {
|
||||||
|
requests.lock().expect("request recorder lock").clear();
|
||||||
|
let previous = app.chat_widget.thread_id();
|
||||||
|
let previous_rollout = app.chat_widget.rollout_path().expect("previous rollout");
|
||||||
|
app.handle_event(
|
||||||
|
&mut tui,
|
||||||
|
&mut server,
|
||||||
|
AppEvent::StartManagedWorktree {
|
||||||
|
mode,
|
||||||
|
name: Some(format!("{mode:?} worktree")),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
let replacement = app.chat_widget.thread_id().expect("replacement thread");
|
||||||
|
assert_ne!(Some(replacement), previous);
|
||||||
|
assert_eq!(
|
||||||
|
app.chat_widget.thread_name(),
|
||||||
|
Some(format!("{mode:?} worktree"))
|
||||||
|
);
|
||||||
|
let cwd = app.config.cwd.as_path().canonicalize()?;
|
||||||
|
let checkouts = manager
|
||||||
|
.list(&source)
|
||||||
|
.map_err(|error| color_eyre::eyre::eyre!(error.to_string()))?;
|
||||||
|
let checkout = checkouts
|
||||||
|
.iter()
|
||||||
|
.find(|checkout| checkout.cwd.canonicalize().ok().as_ref() == Some(&cwd))
|
||||||
|
.expect("managed checkout");
|
||||||
|
assert!(checkout.root.starts_with(home.join("worktrees")));
|
||||||
|
assert!(!project_pool.exists());
|
||||||
|
assert_eq!(
|
||||||
|
manager
|
||||||
|
.owner(&checkout.root)
|
||||||
|
.map_err(|error| color_eyre::eyre::eyre!(error.to_string()))?,
|
||||||
|
Some(replacement.to_string())
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
app.config.developer_instructions.as_deref(),
|
||||||
|
Some("committed policy")
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
fs::read_to_string(checkout.cwd.join("AGENTS.md"))?,
|
||||||
|
"committed worktree instructions"
|
||||||
|
);
|
||||||
|
let fork = matches!(mode, ManagedWorktreeMode::Fork);
|
||||||
|
let method = if fork { "thread/fork" } else { "thread/start" };
|
||||||
|
let params = recorded_params(&requests, method);
|
||||||
|
assert_eq!(params.len(), 1);
|
||||||
|
assert_eq!(
|
||||||
|
[
|
||||||
|
params[0]["model"].as_str(),
|
||||||
|
params[0]["modelProvider"].as_str(),
|
||||||
|
params[0]["config"]["model_reasoning_effort"].as_str(),
|
||||||
|
],
|
||||||
|
[Some("gpt-5.2"), Some("ollama"), Some("high")]
|
||||||
|
);
|
||||||
|
// Injection flushes and materializes a new thread's otherwise lazy rollout.
|
||||||
|
server.thread_inject_items(replacement, vec![serde_json::from_value(serde_json::json!({
|
||||||
|
"type": "message", "role": "assistant", "content": [{"type": "output_text", "text": format!("replacement persistence probe {mode:?}")}]
|
||||||
|
}))?]).await?;
|
||||||
|
let rollout = app.chat_widget.rollout_path().expect("replacement rollout");
|
||||||
|
let mut history = fs::read(&rollout)?;
|
||||||
|
let metadata = codex_rollout::read_session_meta_line(&rollout).await?;
|
||||||
|
assert_eq!(metadata.meta.history_base.is_some(), fork);
|
||||||
|
if let Some(base) = metadata.meta.history_base {
|
||||||
|
assert!(fork, "New must not inherit history");
|
||||||
|
assert_eq!(Some(base.thread_id), previous);
|
||||||
|
let parent = fs::read(&previous_rollout)?;
|
||||||
|
history.extend_from_slice(
|
||||||
|
parent
|
||||||
|
.get(..usize::try_from(base.end_byte_offset)?)
|
||||||
|
.expect("valid inherited prefix"),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
let history = String::from_utf8(history)?;
|
||||||
|
assert!(!history.contains("managed fork history"));
|
||||||
|
if fork {
|
||||||
|
assert!(history.contains("replacement persistence probe New"));
|
||||||
|
}
|
||||||
|
let attached = server
|
||||||
|
.thread_read(replacement, /*include_turns*/ false)
|
||||||
|
.await?;
|
||||||
|
assert_eq!(attached.cwd.as_path().canonicalize()?, cwd);
|
||||||
|
}
|
||||||
|
app.start_fresh_session_with_summary_hint(
|
||||||
|
&mut tui,
|
||||||
|
&mut server,
|
||||||
|
/*session_start_source*/ None,
|
||||||
|
/*initial_user_message*/ None,
|
||||||
|
/*new_thread_name*/ None,
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
let unsaved = app.chat_widget.thread_id().expect("unsaved thread");
|
||||||
|
let path = app.chat_widget.rollout_path();
|
||||||
|
assert!(path.is_none_or(|path| !rollout_path_is_resumable(&path)));
|
||||||
|
let completed = test_turn("completed-unsaved-turn", TurnStatus::Completed, Vec::new());
|
||||||
|
app.thread_event_channels[&unsaved]
|
||||||
|
.store
|
||||||
|
.lock()
|
||||||
|
.await
|
||||||
|
.set_turns(vec![completed]);
|
||||||
|
for mode in [ManagedWorktreeMode::Fork, ManagedWorktreeMode::New] {
|
||||||
|
requests.lock().expect("request recorder lock").clear();
|
||||||
|
app.handle_event(
|
||||||
|
&mut tui,
|
||||||
|
&mut server,
|
||||||
|
AppEvent::StartManagedWorktree { mode, name: None },
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
let is_new = mode == ManagedWorktreeMode::New;
|
||||||
|
assert_eq!(app.chat_widget.thread_id() != Some(unsaved), is_new);
|
||||||
|
assert_eq!(recorded_params(&requests, "thread/fork").len(), 0);
|
||||||
|
}
|
||||||
|
server.shutdown().await?;
|
||||||
|
proxy.await??;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn changing_directory_preserves_project_trust_permissions_history_and_hooks() -> Result<()> {
|
async fn changing_directory_preserves_project_trust_permissions_history_and_hooks() -> Result<()> {
|
||||||
use codex_protocol::config_types::TrustLevel as T;
|
use codex_protocol::config_types::TrustLevel as T;
|
||||||
|
|||||||
@@ -11,6 +11,84 @@ use codex_protocol::permissions::FileSystemSpecialPath;
|
|||||||
use codex_protocol::permissions::NetworkSandboxPolicy;
|
use codex_protocol::permissions::NetworkSandboxPolicy;
|
||||||
use pretty_assertions::assert_eq;
|
use pretty_assertions::assert_eq;
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn worktree_creation_event_requires_feature() -> Result<()> {
|
||||||
|
let (mut app, mut events, _op_rx) = make_test_app_with_channels().await;
|
||||||
|
let mut tui = crate::tui::test_support::make_test_tui()?;
|
||||||
|
let mut app_server = Box::pin(crate::start_embedded_app_server_for_picker(&app.config)).await?;
|
||||||
|
while events.try_recv().is_ok() {}
|
||||||
|
app.handle_event(
|
||||||
|
&mut tui,
|
||||||
|
&mut app_server,
|
||||||
|
AppEvent::StartManagedWorktree {
|
||||||
|
mode: crate::app_event::ManagedWorktreeMode::New,
|
||||||
|
name: None,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
let message = std::iter::from_fn(|| events.try_recv().ok())
|
||||||
|
.find_map(|event| match event {
|
||||||
|
AppEvent::InsertHistoryCell(cell) => {
|
||||||
|
Some(lines_to_single_string(&cell.display_lines(/*width*/ 100)))
|
||||||
|
}
|
||||||
|
_ => None,
|
||||||
|
})
|
||||||
|
.expect("disabled feature message");
|
||||||
|
insta::assert_snapshot!(message, @"■ Enable worktrees in /experimental to create a worktree.");
|
||||||
|
assert!(!app.config.codex_home.join("worktrees").exists());
|
||||||
|
app_server.shutdown().await?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn worktree_creation_rejects_untrusted_source_before_allocation() -> Result<()> {
|
||||||
|
use crate::app_event::ManagedWorktreeMode;
|
||||||
|
|
||||||
|
let (mut app, mut events, _op_rx) = make_test_app_with_channels().await;
|
||||||
|
app.config.features.enable(Feature::Worktrees)?;
|
||||||
|
app.config.active_project.trust_level =
|
||||||
|
Some(codex_protocol::config_types::TrustLevel::Untrusted);
|
||||||
|
let thread_id = ThreadId::new();
|
||||||
|
app.primary_thread_id = Some(thread_id);
|
||||||
|
app.chat_widget
|
||||||
|
.handle_thread_session_quiet(test_thread_session(thread_id, app.config.cwd.to_path_buf()));
|
||||||
|
let mut tui = crate::tui::test_support::make_test_tui()?;
|
||||||
|
let mut app_server = Box::pin(crate::start_embedded_app_server_for_picker(&app.config)).await?;
|
||||||
|
for mode in [ManagedWorktreeMode::New, ManagedWorktreeMode::Fork] {
|
||||||
|
if mode == ManagedWorktreeMode::Fork {
|
||||||
|
app.config.active_project.trust_level =
|
||||||
|
Some(codex_protocol::config_types::TrustLevel::Trusted);
|
||||||
|
crate::legacy_core::config::set_project_trust_level(
|
||||||
|
&app.config.codex_home,
|
||||||
|
app.config.cwd.as_path(),
|
||||||
|
codex_protocol::config_types::TrustLevel::Untrusted,
|
||||||
|
)
|
||||||
|
.map_err(|error| color_eyre::eyre::eyre!(error.to_string()))?;
|
||||||
|
}
|
||||||
|
while events.try_recv().is_ok() {}
|
||||||
|
app.handle_event(
|
||||||
|
&mut tui,
|
||||||
|
&mut app_server,
|
||||||
|
AppEvent::StartManagedWorktree { mode, name: None },
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
let message = std::iter::from_fn(|| events.try_recv().ok())
|
||||||
|
.find_map(|event| match event {
|
||||||
|
AppEvent::InsertHistoryCell(cell) => {
|
||||||
|
Some(lines_to_single_string(&cell.display_lines(/*width*/ 100)))
|
||||||
|
}
|
||||||
|
_ => None,
|
||||||
|
})
|
||||||
|
.expect("source trust error");
|
||||||
|
insta::allow_duplicates! {
|
||||||
|
insta::assert_snapshot!(message, @"■ Cannot create a worktree from an explicitly untrusted source.");
|
||||||
|
}
|
||||||
|
assert!(!app.config.codex_home.join("worktrees").exists());
|
||||||
|
}
|
||||||
|
app_server.shutdown().await?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn turn_start_failure_is_shown_without_exiting() -> Result<()> {
|
async fn turn_start_failure_is_shown_without_exiting() -> Result<()> {
|
||||||
let (mut app, mut app_event_rx, mut op_rx) = make_test_app_with_channels().await;
|
let (mut app, mut app_event_rx, mut op_rx) = make_test_app_with_channels().await;
|
||||||
@@ -64,6 +142,32 @@ async fn turn_start_failure_is_shown_without_exiting() -> Result<()> {
|
|||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn misalignment_policy_blocks_queued_turns_and_goal_resumption() -> Result<()> {
|
async fn misalignment_policy_blocks_queued_turns_and_goal_resumption() -> Result<()> {
|
||||||
let (mut app, _app_event_rx, mut op_rx) = make_test_app_with_channels().await;
|
let (mut app, _app_event_rx, mut op_rx) = make_test_app_with_channels().await;
|
||||||
|
let checkout = tempfile::tempdir()?;
|
||||||
|
app.config.cwd = AbsolutePathBuf::from_absolute_path(checkout.path())?;
|
||||||
|
for args in [
|
||||||
|
vec!["init", "--quiet"],
|
||||||
|
vec![
|
||||||
|
"-c",
|
||||||
|
"user.name=Test",
|
||||||
|
"-c",
|
||||||
|
"user.email=test@example.com",
|
||||||
|
"-c",
|
||||||
|
"commit.gpgsign=false",
|
||||||
|
"commit",
|
||||||
|
"--quiet",
|
||||||
|
"--allow-empty",
|
||||||
|
"-m",
|
||||||
|
"initial",
|
||||||
|
],
|
||||||
|
] {
|
||||||
|
assert!(
|
||||||
|
std::process::Command::new("git")
|
||||||
|
.args(args)
|
||||||
|
.current_dir(checkout.path())
|
||||||
|
.status()?
|
||||||
|
.success()
|
||||||
|
);
|
||||||
|
}
|
||||||
let mut tui = crate::tui::test_support::make_test_tui()?;
|
let mut tui = crate::tui::test_support::make_test_tui()?;
|
||||||
let mut app_server = crate::start_embedded_app_server_for_picker(&app.config).await?;
|
let mut app_server = crate::start_embedded_app_server_for_picker(&app.config).await?;
|
||||||
let started = app_server.start_thread(&app.config).await?;
|
let started = app_server.start_thread(&app.config).await?;
|
||||||
@@ -126,12 +230,17 @@ async fn misalignment_policy_blocks_queued_turns_and_goal_resumption() -> Result
|
|||||||
user_message: Some("Do not fork this stopped thread".into()),
|
user_message: Some("Do not fork this stopped thread".into()),
|
||||||
},
|
},
|
||||||
AppEvent::ForkCurrentSession { name: None },
|
AppEvent::ForkCurrentSession { name: None },
|
||||||
|
AppEvent::StartManagedWorktree {
|
||||||
|
mode: crate::app_event::ManagedWorktreeMode::Fork,
|
||||||
|
name: None,
|
||||||
|
},
|
||||||
AppEvent::OpenAgentPicker,
|
AppEvent::OpenAgentPicker,
|
||||||
AppEvent::SelectAgentThread(thread_id),
|
AppEvent::SelectAgentThread(thread_id),
|
||||||
] {
|
] {
|
||||||
app.handle_event(&mut tui, &mut app_server, event).await?;
|
app.handle_event(&mut tui, &mut app_server, event).await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assert!(!app.config.codex_home.join("worktrees").exists());
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
app_server.next_request_id(),
|
app_server.next_request_id(),
|
||||||
AppServerRequestId::Integer(next_request_id + 1)
|
AppServerRequestId::Integer(next_request_id + 1)
|
||||||
|
|||||||
@@ -1,22 +1,141 @@
|
|||||||
//! Local working-directory changes that preserve conversation history.
|
//! Local directory transitions and managed worktrees with fresh or preserved conversation history.
|
||||||
|
|
||||||
use super::session_lifecycle::ThreadAttachPresentation;
|
use super::session_lifecycle::ThreadAttachPresentation;
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::app_server_session::ForkGoalContinuation::DeferUntilNextTurn;
|
use crate::app_server_session::ForkGoalContinuation::DeferUntilNextTurn;
|
||||||
use crate::history_cell::McpInventoryLoadingCell as LoadingCell;
|
use crate::history_cell::McpInventoryLoadingCell as LoadingCell;
|
||||||
|
use crate::terminal_visualization_instructions::with_terminal_visualization_instructions;
|
||||||
use codex_app_server_protocol::ThreadBackgroundTerminalsListParams;
|
use codex_app_server_protocol::ThreadBackgroundTerminalsListParams;
|
||||||
use codex_app_server_protocol::ThreadBackgroundTerminalsListResponse as ListResponse;
|
use codex_app_server_protocol::ThreadBackgroundTerminalsListResponse as ListResponse;
|
||||||
|
|
||||||
impl App {
|
impl App {
|
||||||
|
pub(super) async fn start_managed_worktree(
|
||||||
|
&mut self,
|
||||||
|
tui: &mut tui::Tui,
|
||||||
|
app_server: &mut AppServerSession,
|
||||||
|
mode: crate::app_event::ManagedWorktreeMode,
|
||||||
|
name: Option<String>,
|
||||||
|
) {
|
||||||
|
if !self.config.features.enabled(Feature::Worktrees) {
|
||||||
|
self.chat_widget.add_error_message(
|
||||||
|
"Enable worktrees in /experimental to create a worktree.".to_string(),
|
||||||
|
);
|
||||||
|
} else if self.config.active_project.is_untrusted() {
|
||||||
|
self.chat_widget.add_error_message(
|
||||||
|
"Cannot create a worktree from an explicitly untrusted source.".to_string(),
|
||||||
|
);
|
||||||
|
} else if crate::uses_remote_workspace_or_environment(
|
||||||
|
&self.app_server_target,
|
||||||
|
self.environment_manager.as_ref(),
|
||||||
|
) {
|
||||||
|
self.chat_widget.add_error_message(
|
||||||
|
"Managed worktrees are only supported for local sessions.".to_string(),
|
||||||
|
);
|
||||||
|
} else if self
|
||||||
|
.primary_thread_id
|
||||||
|
.is_none_or(|thread_id| !self.chat_widget.can_change_working_directory(thread_id))
|
||||||
|
{
|
||||||
|
self.chat_widget.add_error_message(
|
||||||
|
"Creating a worktree requires an idle primary session without queued input."
|
||||||
|
.to_string(),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
let setup = async {
|
||||||
|
let source = self
|
||||||
|
.rebuild_config_for_cwd(self.config.cwd.to_path_buf())
|
||||||
|
.await
|
||||||
|
.map_err(|error| anyhow::anyhow!(error.to_string()))?;
|
||||||
|
anyhow::ensure!(
|
||||||
|
!source.active_project.is_untrusted(),
|
||||||
|
"Cannot create a worktree from an explicitly untrusted source."
|
||||||
|
);
|
||||||
|
let host = crate::legacy_core::config::load_config_toml_with_layer_stack(
|
||||||
|
&self.config.codex_home,
|
||||||
|
/*cwd*/ None,
|
||||||
|
Vec::new(),
|
||||||
|
codex_config::ConfigLoadOptions::default(),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
let settings = codex_worktree::WorktreeSettings::for_cli(
|
||||||
|
&self.config.codex_home,
|
||||||
|
host.config_toml.desktop.as_ref(),
|
||||||
|
)?;
|
||||||
|
let manager = codex_worktree::WorktreeManager::new(settings);
|
||||||
|
let checkout = manager.create(&codex_worktree::CreateWorktree {
|
||||||
|
source_cwd: self.config.cwd.to_path_buf(),
|
||||||
|
base: None,
|
||||||
|
})?;
|
||||||
|
anyhow::Ok((manager, checkout))
|
||||||
|
}
|
||||||
|
.await;
|
||||||
|
match setup {
|
||||||
|
Ok((manager, checkout)) => {
|
||||||
|
if let Err(error) = self
|
||||||
|
.switch_to_managed_worktree(tui, app_server, manager, checkout, mode, name)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
self.chat_widget.add_error_message(error.to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(error) => self.chat_widget.add_error_message(error.to_string()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn working_directory_error(&mut self, message: impl Into<String>) {
|
fn working_directory_error(&mut self, message: impl Into<String>) {
|
||||||
self.chat_widget.add_error_message(message.into());
|
self.chat_widget.add_error_message(message.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(super) async fn switch_to_managed_worktree(
|
||||||
|
&mut self,
|
||||||
|
tui: &mut tui::Tui,
|
||||||
|
app_server: &mut AppServerSession,
|
||||||
|
manager: codex_worktree::WorktreeManager,
|
||||||
|
checkout: codex_worktree::ManagedWorktree,
|
||||||
|
mode: crate::app_event::ManagedWorktreeMode,
|
||||||
|
name: Option<String>,
|
||||||
|
) -> Result<()> {
|
||||||
|
let previous_thread_id = self.chat_widget.thread_id();
|
||||||
|
let cwd = AbsolutePathBuf::from_absolute_path(checkout.cwd.clone())
|
||||||
|
.map_err(|error| color_eyre::eyre::eyre!(error.to_string()))?;
|
||||||
|
self.change_working_directory_with_managed(
|
||||||
|
tui,
|
||||||
|
app_server,
|
||||||
|
cwd,
|
||||||
|
Some((manager, checkout, mode, name)),
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
if self.chat_widget.thread_id() == previous_thread_id {
|
||||||
|
return Err(color_eyre::eyre::eyre!(
|
||||||
|
"Could not start a session in the managed worktree"
|
||||||
|
));
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
pub(super) async fn change_working_directory(
|
pub(super) async fn change_working_directory(
|
||||||
&mut self,
|
&mut self,
|
||||||
tui: &mut tui::Tui,
|
tui: &mut tui::Tui,
|
||||||
app_server: &mut AppServerSession,
|
app_server: &mut AppServerSession,
|
||||||
cwd: AbsolutePathBuf,
|
cwd: AbsolutePathBuf,
|
||||||
|
) {
|
||||||
|
self.change_working_directory_with_managed(
|
||||||
|
tui, app_server, cwd, /*managed_worktree*/ None,
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn change_working_directory_with_managed(
|
||||||
|
&mut self,
|
||||||
|
tui: &mut tui::Tui,
|
||||||
|
app_server: &mut AppServerSession,
|
||||||
|
cwd: AbsolutePathBuf,
|
||||||
|
managed_worktree: Option<(
|
||||||
|
codex_worktree::WorktreeManager,
|
||||||
|
codex_worktree::ManagedWorktree,
|
||||||
|
crate::app_event::ManagedWorktreeMode,
|
||||||
|
Option<String>,
|
||||||
|
)>,
|
||||||
) {
|
) {
|
||||||
if self.config.ephemeral || !cwd.as_path().is_dir() {
|
if self.config.ephemeral || !cwd.as_path().is_dir() {
|
||||||
return self.working_directory_error("This task cannot be safely replaced.");
|
return self.working_directory_error("This task cannot be safely replaced.");
|
||||||
@@ -55,6 +174,21 @@ impl App {
|
|||||||
if config.active_project.trust_level.is_none() {
|
if config.active_project.trust_level.is_none() {
|
||||||
return self.working_directory_error("This directory is not trusted; run Codex there.");
|
return self.working_directory_error("This directory is not trusted; run Codex there.");
|
||||||
}
|
}
|
||||||
|
if let Some((_, checkout, crate::app_event::ManagedWorktreeMode::Fork, _)) =
|
||||||
|
managed_worktree.as_ref()
|
||||||
|
&& with_terminal_visualization_instructions(
|
||||||
|
&self.config,
|
||||||
|
self.config.developer_instructions.clone(),
|
||||||
|
) != with_terminal_visualization_instructions(
|
||||||
|
&config,
|
||||||
|
config.developer_instructions.clone(),
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return self.working_directory_error(format!(
|
||||||
|
"Cannot fork into this worktree because developer instructions differ. Start a new conversation instead. An unused checkout was created at {}; remove it with `git worktree remove <checkout-path>` from the source repository.",
|
||||||
|
checkout.root.display()
|
||||||
|
));
|
||||||
|
}
|
||||||
if let Some(profile) = self.runtime_permission_profile_override.as_ref()
|
if let Some(profile) = self.runtime_permission_profile_override.as_ref()
|
||||||
&& profile.active_permission_profile.is_some()
|
&& profile.active_permission_profile.is_some()
|
||||||
&& (!profile.matches_config(&config)
|
&& (!profile.matches_config(&config)
|
||||||
@@ -98,10 +232,15 @@ impl App {
|
|||||||
Err(error) => return self.chat_widget.add_error_message(error),
|
Err(error) => return self.chat_widget.add_error_message(error),
|
||||||
};
|
};
|
||||||
config.service_tier = self.chat_widget.configured_service_tier();
|
config.service_tier = self.chat_widget.configured_service_tier();
|
||||||
|
let is_new_worktree = matches!(
|
||||||
|
managed_worktree.as_ref().map(|(_, _, mode, _)| mode),
|
||||||
|
Some(crate::app_event::ManagedWorktreeMode::New)
|
||||||
|
);
|
||||||
let rollout = self.chat_widget.rollout_path();
|
let rollout = self.chat_widget.rollout_path();
|
||||||
let has_rollout = rollout.as_deref().is_some_and(rollout_path_is_resumable);
|
let has_rollout = rollout.as_deref().is_some_and(rollout_path_is_resumable);
|
||||||
let channels = &self.thread_event_channels;
|
let channels = &self.thread_event_channels;
|
||||||
if !has_rollout
|
if !has_rollout
|
||||||
|
&& !is_new_worktree
|
||||||
&& (!self.chat_widget.token_usage().is_zero()
|
&& (!self.chat_widget.token_usage().is_zero()
|
||||||
|| channels.get(&thread_id).is_some_and(|channel| {
|
|| channels.get(&thread_id).is_some_and(|channel| {
|
||||||
channel.store.try_lock().map_or(/*default*/ true, |store| {
|
channel.store.try_lock().map_or(/*default*/ true, |store| {
|
||||||
@@ -142,7 +281,16 @@ impl App {
|
|||||||
return self.working_directory_error("Active background terminals block /cd.");
|
return self.working_directory_error("Active background terminals block /cd.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let transitioned = if has_rollout {
|
if is_new_worktree {
|
||||||
|
apply_managed_new_thread_defaults(
|
||||||
|
&mut config,
|
||||||
|
app_server.managed_new_thread_defaults(),
|
||||||
|
&self.cli_kv_overrides,
|
||||||
|
&self.harness_overrides,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
let preserve_history = has_rollout && !is_new_worktree;
|
||||||
|
let transitioned = if preserve_history {
|
||||||
app_server
|
app_server
|
||||||
.fork_thread_at(
|
.fork_thread_at(
|
||||||
&local_settings,
|
&local_settings,
|
||||||
@@ -163,7 +311,7 @@ impl App {
|
|||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
};
|
};
|
||||||
let transitioned = match transitioned {
|
let mut transitioned = match transitioned {
|
||||||
Ok(value) => value,
|
Ok(value) => value,
|
||||||
Err(e) => return self.working_directory_error(format!("Failed to change: {e}")),
|
Err(e) => return self.working_directory_error(format!("Failed to change: {e}")),
|
||||||
};
|
};
|
||||||
@@ -177,16 +325,46 @@ impl App {
|
|||||||
{
|
{
|
||||||
if session.thread_id != thread_id {
|
if session.thread_id != thread_id {
|
||||||
let _ = app_server.thread_unsubscribe(session.thread_id).await;
|
let _ = app_server.thread_unsubscribe(session.thread_id).await;
|
||||||
if has_rollout {
|
if preserve_history {
|
||||||
let _ = app_server.thread_archive(session.thread_id).await;
|
let _ = app_server.thread_archive(session.thread_id).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return self.working_directory_error("Requested directory or permissions not applied.");
|
return self.working_directory_error("Requested directory or permissions not applied.");
|
||||||
}
|
}
|
||||||
|
if let Some((manager, checkout, _, _)) = managed_worktree.as_ref()
|
||||||
|
&& let Err(error) =
|
||||||
|
manager.bind_thread(&checkout.root, &transitioned.session.thread_id.to_string())
|
||||||
|
{
|
||||||
|
let replacement_id = transitioned.session.thread_id;
|
||||||
|
let _ = app_server.thread_unsubscribe(replacement_id).await;
|
||||||
|
if preserve_history {
|
||||||
|
let _ = app_server.thread_archive(replacement_id).await;
|
||||||
|
}
|
||||||
|
return self.working_directory_error(format!(
|
||||||
|
"Cannot register managed worktree ownership: {error}"
|
||||||
|
));
|
||||||
|
}
|
||||||
|
let name_error = if let Some(name) = managed_worktree
|
||||||
|
.as_ref()
|
||||||
|
.and_then(|(_, _, _, name)| name.as_ref())
|
||||||
|
{
|
||||||
|
match app_server
|
||||||
|
.thread_set_name(transitioned.session.thread_id, name.clone())
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(()) => {
|
||||||
|
transitioned.session.thread_name = Some(name.clone());
|
||||||
|
None
|
||||||
|
}
|
||||||
|
Err(error) => Some(format!("Failed to name the worktree session: {error}")),
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
if let Err(error) = app_server.thread_unsubscribe(thread_id).await {
|
if let Err(error) = app_server.thread_unsubscribe(thread_id).await {
|
||||||
let replacement_id = transitioned.session.thread_id;
|
let replacement_id = transitioned.session.thread_id;
|
||||||
let _ = app_server.thread_unsubscribe(replacement_id).await;
|
let _ = app_server.thread_unsubscribe(replacement_id).await;
|
||||||
if has_rollout {
|
if preserve_history {
|
||||||
let _ = app_server.thread_archive(replacement_id).await;
|
let _ = app_server.thread_archive(replacement_id).await;
|
||||||
}
|
}
|
||||||
return self.working_directory_error(format!("Cannot change directories: {error}"));
|
return self.working_directory_error(format!("Cannot change directories: {error}"));
|
||||||
@@ -210,6 +388,9 @@ impl App {
|
|||||||
if let Err(error) = attach(self, tui, transitioned, lineage, message).await {
|
if let Err(error) = attach(self, tui, transitioned, lineage, message).await {
|
||||||
return self.working_directory_error(format!("Could not restore session: {error}"));
|
return self.working_directory_error(format!("Could not restore session: {error}"));
|
||||||
}
|
}
|
||||||
|
if let Some(error) = name_error {
|
||||||
|
self.chat_widget.add_error_message(error);
|
||||||
|
}
|
||||||
self.cancel_pending_key_chord();
|
self.cancel_pending_key_chord();
|
||||||
self.keymap = keymap;
|
self.keymap = keymap;
|
||||||
self.merge_startup_warnings(tui, &history_cell::StartupWarningsCell::default());
|
self.merge_startup_warnings(tui, &history_cell::StartupWarningsCell::default());
|
||||||
|
|||||||
@@ -66,6 +66,13 @@ use codex_protocol::models::ActivePermissionProfile;
|
|||||||
|
|
||||||
use crate::history_cell::HistoryCell;
|
use crate::history_cell::HistoryCell;
|
||||||
|
|
||||||
|
/// Whether a managed checkout starts fresh or preserves the current conversation.
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
|
pub(crate) enum ManagedWorktreeMode {
|
||||||
|
New,
|
||||||
|
Fork,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
pub(crate) enum ThreadGoalSetMode {
|
pub(crate) enum ThreadGoalSetMode {
|
||||||
ConfirmIfExists,
|
ConfirmIfExists,
|
||||||
@@ -388,6 +395,12 @@ pub(crate) enum AppEvent {
|
|||||||
name: Option<String>,
|
name: Option<String>,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/// Create a managed checkout and start or fork a session into it.
|
||||||
|
StartManagedWorktree {
|
||||||
|
mode: ManagedWorktreeMode,
|
||||||
|
name: Option<String>,
|
||||||
|
},
|
||||||
|
|
||||||
/// Change the working directory of the originating idle primary thread.
|
/// Change the working directory of the originating idle primary thread.
|
||||||
ChangeWorkingDirectory {
|
ChangeWorkingDirectory {
|
||||||
thread_id: ThreadId,
|
thread_id: ThreadId,
|
||||||
|
|||||||
@@ -279,7 +279,6 @@ use super::paste_burst::PasteBurst;
|
|||||||
use super::prompt_args::parse_slash_name;
|
use super::prompt_args::parse_slash_name;
|
||||||
use super::skill_popup::MentionItem;
|
use super::skill_popup::MentionItem;
|
||||||
use super::skill_popup::SkillPopup;
|
use super::skill_popup::SkillPopup;
|
||||||
use super::slash_commands::BuiltinCommandFlags;
|
|
||||||
use super::slash_commands::ServiceTierCommand;
|
use super::slash_commands::ServiceTierCommand;
|
||||||
use super::slash_commands::SlashCommandItem;
|
use super::slash_commands::SlashCommandItem;
|
||||||
use crate::bottom_pane::paste_burst::FlushResult;
|
use crate::bottom_pane::paste_burst::FlushResult;
|
||||||
@@ -555,6 +554,7 @@ pub(crate) struct ChatComposer {
|
|||||||
mentions_v2_enabled: bool,
|
mentions_v2_enabled: bool,
|
||||||
goal_command_enabled: bool,
|
goal_command_enabled: bool,
|
||||||
personality_command_enabled: bool,
|
personality_command_enabled: bool,
|
||||||
|
worktrees_enabled: bool,
|
||||||
windows_degraded_sandbox_active: bool,
|
windows_degraded_sandbox_active: bool,
|
||||||
side_conversation_active: bool,
|
side_conversation_active: bool,
|
||||||
history_search: Option<HistorySearchSession>,
|
history_search: Option<HistorySearchSession>,
|
||||||
@@ -611,20 +611,6 @@ impl ChatComposer {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn builtin_command_flags(&self) -> BuiltinCommandFlags {
|
|
||||||
BuiltinCommandFlags {
|
|
||||||
collaboration_modes_enabled: self.collaboration_modes_enabled,
|
|
||||||
connectors_enabled: self.connectors_enabled,
|
|
||||||
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,
|
|
||||||
goal_command_enabled: self.goal_command_enabled,
|
|
||||||
personality_command_enabled: self.personality_command_enabled,
|
|
||||||
allow_elevate_sandbox: self.windows_degraded_sandbox_active,
|
|
||||||
side_conversation_active: self.side_conversation_active,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn new(
|
pub fn new(
|
||||||
has_input_focus: bool,
|
has_input_focus: bool,
|
||||||
app_event_tx: AppEventSender,
|
app_event_tx: AppEventSender,
|
||||||
@@ -732,6 +718,7 @@ impl ChatComposer {
|
|||||||
mentions_v2_enabled: false,
|
mentions_v2_enabled: false,
|
||||||
goal_command_enabled: false,
|
goal_command_enabled: false,
|
||||||
personality_command_enabled: false,
|
personality_command_enabled: false,
|
||||||
|
worktrees_enabled: false,
|
||||||
windows_degraded_sandbox_active: false,
|
windows_degraded_sandbox_active: false,
|
||||||
side_conversation_active: false,
|
side_conversation_active: false,
|
||||||
history_search: None,
|
history_search: None,
|
||||||
|
|||||||
@@ -178,6 +178,7 @@ impl<'a> SlashInput<'a> {
|
|||||||
service_tier_commands_enabled: self.command_flags.service_tier_commands_enabled,
|
service_tier_commands_enabled: self.command_flags.service_tier_commands_enabled,
|
||||||
goal_command_enabled: self.command_flags.goal_command_enabled,
|
goal_command_enabled: self.command_flags.goal_command_enabled,
|
||||||
personality_command_enabled: self.command_flags.personality_command_enabled,
|
personality_command_enabled: self.command_flags.personality_command_enabled,
|
||||||
|
worktrees_enabled: self.command_flags.worktrees_enabled,
|
||||||
windows_degraded_sandbox_active: self.command_flags.allow_elevate_sandbox,
|
windows_degraded_sandbox_active: self.command_flags.allow_elevate_sandbox,
|
||||||
side_conversation_active: self.command_flags.side_conversation_active,
|
side_conversation_active: self.command_flags.side_conversation_active,
|
||||||
},
|
},
|
||||||
@@ -206,6 +207,25 @@ pub(super) fn queued_input_action(
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ChatComposer {
|
impl ChatComposer {
|
||||||
|
pub(super) fn builtin_command_flags(&self) -> BuiltinCommandFlags {
|
||||||
|
BuiltinCommandFlags {
|
||||||
|
collaboration_modes_enabled: self.collaboration_modes_enabled,
|
||||||
|
connectors_enabled: self.connectors_enabled,
|
||||||
|
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,
|
||||||
|
goal_command_enabled: self.goal_command_enabled,
|
||||||
|
personality_command_enabled: self.personality_command_enabled,
|
||||||
|
worktrees_enabled: self.worktrees_enabled,
|
||||||
|
allow_elevate_sandbox: self.windows_degraded_sandbox_active,
|
||||||
|
side_conversation_active: self.side_conversation_active,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_worktrees_enabled(&mut self, enabled: bool) {
|
||||||
|
self.worktrees_enabled = enabled;
|
||||||
|
}
|
||||||
|
|
||||||
/// Handle key event when the slash-command popup is visible.
|
/// Handle key event when the slash-command popup is visible.
|
||||||
pub(super) fn handle_key_event_with_slash_popup(
|
pub(super) fn handle_key_event_with_slash_popup(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ pub(crate) struct CommandPopupFlags {
|
|||||||
pub(crate) service_tier_commands_enabled: bool,
|
pub(crate) service_tier_commands_enabled: bool,
|
||||||
pub(crate) goal_command_enabled: bool,
|
pub(crate) goal_command_enabled: bool,
|
||||||
pub(crate) personality_command_enabled: bool,
|
pub(crate) personality_command_enabled: bool,
|
||||||
|
pub(crate) worktrees_enabled: bool,
|
||||||
pub(crate) windows_degraded_sandbox_active: bool,
|
pub(crate) windows_degraded_sandbox_active: bool,
|
||||||
pub(crate) side_conversation_active: bool,
|
pub(crate) side_conversation_active: bool,
|
||||||
}
|
}
|
||||||
@@ -62,6 +63,7 @@ impl From<CommandPopupFlags> for BuiltinCommandFlags {
|
|||||||
service_tier_commands_enabled: value.service_tier_commands_enabled,
|
service_tier_commands_enabled: value.service_tier_commands_enabled,
|
||||||
goal_command_enabled: value.goal_command_enabled,
|
goal_command_enabled: value.goal_command_enabled,
|
||||||
personality_command_enabled: value.personality_command_enabled,
|
personality_command_enabled: value.personality_command_enabled,
|
||||||
|
worktrees_enabled: value.worktrees_enabled,
|
||||||
allow_elevate_sandbox: value.windows_degraded_sandbox_active,
|
allow_elevate_sandbox: value.windows_degraded_sandbox_active,
|
||||||
side_conversation_active: value.side_conversation_active,
|
side_conversation_active: value.side_conversation_active,
|
||||||
}
|
}
|
||||||
@@ -535,6 +537,7 @@ mod tests {
|
|||||||
service_tier_commands_enabled: false,
|
service_tier_commands_enabled: false,
|
||||||
goal_command_enabled: false,
|
goal_command_enabled: false,
|
||||||
personality_command_enabled: true,
|
personality_command_enabled: true,
|
||||||
|
worktrees_enabled: true,
|
||||||
windows_degraded_sandbox_active: false,
|
windows_degraded_sandbox_active: false,
|
||||||
side_conversation_active: false,
|
side_conversation_active: false,
|
||||||
},
|
},
|
||||||
@@ -562,6 +565,7 @@ mod tests {
|
|||||||
service_tier_commands_enabled: false,
|
service_tier_commands_enabled: false,
|
||||||
goal_command_enabled: false,
|
goal_command_enabled: false,
|
||||||
personality_command_enabled: false,
|
personality_command_enabled: false,
|
||||||
|
worktrees_enabled: false,
|
||||||
windows_degraded_sandbox_active: false,
|
windows_degraded_sandbox_active: false,
|
||||||
side_conversation_active: false,
|
side_conversation_active: false,
|
||||||
},
|
},
|
||||||
@@ -594,6 +598,7 @@ mod tests {
|
|||||||
service_tier_commands_enabled: false,
|
service_tier_commands_enabled: false,
|
||||||
goal_command_enabled: false,
|
goal_command_enabled: false,
|
||||||
personality_command_enabled: true,
|
personality_command_enabled: true,
|
||||||
|
worktrees_enabled: true,
|
||||||
windows_degraded_sandbox_active: false,
|
windows_degraded_sandbox_active: false,
|
||||||
side_conversation_active: false,
|
side_conversation_active: false,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -516,6 +516,11 @@ impl BottomPane {
|
|||||||
self.request_redraw();
|
self.request_redraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn set_worktrees_enabled(&mut self, enabled: bool) {
|
||||||
|
self.composer.set_worktrees_enabled(enabled);
|
||||||
|
self.request_redraw();
|
||||||
|
}
|
||||||
|
|
||||||
pub fn set_personality_command_enabled(&mut self, enabled: bool) {
|
pub fn set_personality_command_enabled(&mut self, enabled: bool) {
|
||||||
self.composer.set_personality_command_enabled(enabled);
|
self.composer.set_personality_command_enabled(enabled);
|
||||||
self.request_redraw();
|
self.request_redraw();
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ pub(crate) struct BuiltinCommandFlags {
|
|||||||
pub(crate) service_tier_commands_enabled: bool,
|
pub(crate) service_tier_commands_enabled: bool,
|
||||||
pub(crate) goal_command_enabled: bool,
|
pub(crate) goal_command_enabled: bool,
|
||||||
pub(crate) personality_command_enabled: bool,
|
pub(crate) personality_command_enabled: bool,
|
||||||
|
pub(crate) worktrees_enabled: bool,
|
||||||
pub(crate) allow_elevate_sandbox: bool,
|
pub(crate) allow_elevate_sandbox: bool,
|
||||||
pub(crate) side_conversation_active: bool,
|
pub(crate) side_conversation_active: bool,
|
||||||
}
|
}
|
||||||
@@ -76,6 +77,7 @@ pub(crate) fn builtins_for_input(flags: BuiltinCommandFlags) -> Vec<(&'static st
|
|||||||
.filter(|(_, cmd)| flags.plugins_command_enabled || *cmd != SlashCommand::Plugins)
|
.filter(|(_, cmd)| flags.plugins_command_enabled || *cmd != SlashCommand::Plugins)
|
||||||
.filter(|(_, cmd)| flags.token_activity_command_enabled || *cmd != SlashCommand::Usage)
|
.filter(|(_, cmd)| flags.token_activity_command_enabled || *cmd != SlashCommand::Usage)
|
||||||
.filter(|(_, cmd)| flags.goal_command_enabled || *cmd != SlashCommand::Goal)
|
.filter(|(_, cmd)| flags.goal_command_enabled || *cmd != SlashCommand::Goal)
|
||||||
|
.filter(|(_, cmd)| flags.worktrees_enabled || *cmd != SlashCommand::Worktree)
|
||||||
.filter(|(_, cmd)| flags.personality_command_enabled || *cmd != SlashCommand::Personality)
|
.filter(|(_, cmd)| flags.personality_command_enabled || *cmd != SlashCommand::Personality)
|
||||||
.filter(|(_, cmd)| !flags.side_conversation_active || cmd.available_in_side_conversation())
|
.filter(|(_, cmd)| !flags.side_conversation_active || cmd.available_in_side_conversation())
|
||||||
.collect()
|
.collect()
|
||||||
@@ -171,11 +173,24 @@ mod tests {
|
|||||||
service_tier_commands_enabled: true,
|
service_tier_commands_enabled: true,
|
||||||
goal_command_enabled: true,
|
goal_command_enabled: true,
|
||||||
personality_command_enabled: true,
|
personality_command_enabled: true,
|
||||||
|
worktrees_enabled: true,
|
||||||
allow_elevate_sandbox: true,
|
allow_elevate_sandbox: true,
|
||||||
side_conversation_active: false,
|
side_conversation_active: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn worktree_command_lookup_requires_feature() {
|
||||||
|
assert_eq!(
|
||||||
|
find_builtin_command("worktree", BuiltinCommandFlags::default()),
|
||||||
|
None
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
find_builtin_command("worktree", all_enabled_flags()),
|
||||||
|
Some(SlashCommand::Worktree)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn debug_command_still_resolves_for_dispatch() {
|
fn debug_command_still_resolves_for_dispatch() {
|
||||||
let cmd = find_builtin_command("debug-config", all_enabled_flags());
|
let cmd = find_builtin_command("debug-config", all_enabled_flags());
|
||||||
|
|||||||
@@ -366,6 +366,7 @@ mod hooks;
|
|||||||
mod interaction;
|
mod interaction;
|
||||||
mod skills;
|
mod skills;
|
||||||
mod slash_dispatch;
|
mod slash_dispatch;
|
||||||
|
mod worktree_picker;
|
||||||
use self::skills::collect_tool_mentions;
|
use self::skills::collect_tool_mentions;
|
||||||
use self::skills::find_app_mentions;
|
use self::skills::find_app_mentions;
|
||||||
use self::skills::find_skill_mentions_with_tool_mentions;
|
use self::skills::find_skill_mentions_with_tool_mentions;
|
||||||
@@ -582,6 +583,7 @@ pub(crate) struct ChatWidget {
|
|||||||
status_account_display: Option<StatusAccountDisplay>,
|
status_account_display: Option<StatusAccountDisplay>,
|
||||||
runtime_model_provider_base_url: Option<String>,
|
runtime_model_provider_base_url: Option<String>,
|
||||||
pub(crate) remote_connection: Option<RemoteConnectionStatus>,
|
pub(crate) remote_connection: Option<RemoteConnectionStatus>,
|
||||||
|
pub(crate) local_worktree_operations: bool,
|
||||||
token_info: Option<TokenUsageInfo>,
|
token_info: Option<TokenUsageInfo>,
|
||||||
token_usage_pending: bool,
|
token_usage_pending: bool,
|
||||||
// Status and polling use account usage reads; response streams may identify meters differently.
|
// Status and polling use account usage reads; response streams may identify meters differently.
|
||||||
|
|||||||
@@ -135,6 +135,7 @@ impl ChatWidget {
|
|||||||
status_account_display,
|
status_account_display,
|
||||||
runtime_model_provider_base_url,
|
runtime_model_provider_base_url,
|
||||||
remote_connection: None,
|
remote_connection: None,
|
||||||
|
local_worktree_operations: true,
|
||||||
token_info: None,
|
token_info: None,
|
||||||
token_usage_pending: false,
|
token_usage_pending: false,
|
||||||
rate_limit_snapshots_by_limit_id: BTreeMap::new(),
|
rate_limit_snapshots_by_limit_id: BTreeMap::new(),
|
||||||
@@ -287,6 +288,7 @@ impl ChatWidget {
|
|||||||
.set_collaboration_modes_enabled(/*enabled*/ true);
|
.set_collaboration_modes_enabled(/*enabled*/ true);
|
||||||
widget.sync_service_tier_commands();
|
widget.sync_service_tier_commands();
|
||||||
widget.sync_personality_command_enabled();
|
widget.sync_personality_command_enabled();
|
||||||
|
widget.sync_worktrees_enabled();
|
||||||
widget.sync_plugins_command_enabled();
|
widget.sync_plugins_command_enabled();
|
||||||
widget.sync_goal_command_enabled();
|
widget.sync_goal_command_enabled();
|
||||||
widget.sync_mentions_v2_enabled();
|
widget.sync_mentions_v2_enabled();
|
||||||
|
|||||||
@@ -132,6 +132,7 @@ impl ChatWidget {
|
|||||||
}
|
}
|
||||||
self.sync_service_tier_commands();
|
self.sync_service_tier_commands();
|
||||||
self.sync_personality_command_enabled();
|
self.sync_personality_command_enabled();
|
||||||
|
self.sync_worktrees_enabled();
|
||||||
self.sync_plugins_command_enabled();
|
self.sync_plugins_command_enabled();
|
||||||
self.sync_goal_command_enabled();
|
self.sync_goal_command_enabled();
|
||||||
self.refresh_plugin_mentions();
|
self.refresh_plugin_mentions();
|
||||||
|
|||||||
@@ -80,6 +80,9 @@ impl ChatWidget {
|
|||||||
self.refresh_effective_service_tier();
|
self.refresh_effective_service_tier();
|
||||||
self.sync_service_tier_commands();
|
self.sync_service_tier_commands();
|
||||||
}
|
}
|
||||||
|
if feature == Feature::Worktrees {
|
||||||
|
self.sync_worktrees_enabled();
|
||||||
|
}
|
||||||
if feature == Feature::Personality {
|
if feature == Feature::Personality {
|
||||||
self.sync_personality_command_enabled();
|
self.sync_personality_command_enabled();
|
||||||
}
|
}
|
||||||
@@ -296,6 +299,17 @@ impl ChatWidget {
|
|||||||
.unwrap_or_else(|| self.current_collaboration_mode.model())
|
.unwrap_or_else(|| self.current_collaboration_mode.model())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn set_local_worktree_operations(&mut self, enabled: bool) {
|
||||||
|
self.local_worktree_operations = enabled;
|
||||||
|
self.sync_worktrees_enabled();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(super) fn sync_worktrees_enabled(&mut self) {
|
||||||
|
self.bottom_pane.set_worktrees_enabled(
|
||||||
|
self.config.features.enabled(Feature::Worktrees) && self.local_worktree_operations,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
pub(super) fn sync_personality_command_enabled(&mut self) {
|
pub(super) fn sync_personality_command_enabled(&mut self) {
|
||||||
self.bottom_pane
|
self.bottom_pane
|
||||||
.set_personality_command_enabled(self.config.features.enabled(Feature::Personality));
|
.set_personality_command_enabled(self.config.features.enabled(Feature::Personality));
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
//! slash-command recall follows the same submitted-input rule as ordinary text.
|
//! slash-command recall follows the same submitted-input rule as ordinary text.
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use crate::app_event::ManagedWorktreeMode;
|
||||||
use crate::app_event::ThreadGoalSetMode;
|
use crate::app_event::ThreadGoalSetMode;
|
||||||
use crate::bottom_pane::prompt_args::parse_slash_name;
|
use crate::bottom_pane::prompt_args::parse_slash_name;
|
||||||
use crate::bottom_pane::slash_commands::BuiltinCommandFlags;
|
use crate::bottom_pane::slash_commands::BuiltinCommandFlags;
|
||||||
@@ -181,7 +182,7 @@ impl ChatWidget {
|
|||||||
self.request_redraw();
|
self.request_redraw();
|
||||||
}
|
}
|
||||||
SlashCommand::New => {
|
SlashCommand::New => {
|
||||||
self.app_event_tx.send(AppEvent::NewSession { name: None });
|
self.show_session_checkout_picker(ManagedWorktreeMode::New, /*name*/ None);
|
||||||
}
|
}
|
||||||
SlashCommand::Archive => {
|
SlashCommand::Archive => {
|
||||||
self.bottom_pane.show_selection_view(SelectionViewParams {
|
self.bottom_pane.show_selection_view(SelectionViewParams {
|
||||||
@@ -247,8 +248,10 @@ impl ChatWidget {
|
|||||||
self.app_event_tx.send(AppEvent::OpenResumePicker);
|
self.app_event_tx.send(AppEvent::OpenResumePicker);
|
||||||
}
|
}
|
||||||
SlashCommand::Fork => {
|
SlashCommand::Fork => {
|
||||||
self.app_event_tx
|
self.show_session_checkout_picker(ManagedWorktreeMode::Fork, /*name*/ None);
|
||||||
.send(AppEvent::ForkCurrentSession { name: None });
|
}
|
||||||
|
SlashCommand::Worktree => {
|
||||||
|
self.show_managed_worktree_picker();
|
||||||
}
|
}
|
||||||
SlashCommand::App => {
|
SlashCommand::App => {
|
||||||
let Some(thread_id) = self.thread_id else {
|
let Some(thread_id) = self.thread_id else {
|
||||||
@@ -800,9 +803,10 @@ impl ChatWidget {
|
|||||||
self.app_event_tx.set_thread_name(name);
|
self.app_event_tx.set_thread_name(name);
|
||||||
}
|
}
|
||||||
SlashCommand::New if !trimmed.is_empty() => {
|
SlashCommand::New if !trimmed.is_empty() => {
|
||||||
self.app_event_tx.send(AppEvent::NewSession {
|
self.show_session_checkout_picker(
|
||||||
name: Some(trimmed.to_string()),
|
ManagedWorktreeMode::New,
|
||||||
});
|
Some(trimmed.to_string()),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
SlashCommand::Clear if !trimmed.is_empty() => {
|
SlashCommand::Clear if !trimmed.is_empty() => {
|
||||||
self.app_event_tx.send(AppEvent::ClearUi {
|
self.app_event_tx.send(AppEvent::ClearUi {
|
||||||
@@ -810,9 +814,10 @@ impl ChatWidget {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
SlashCommand::Fork if !trimmed.is_empty() => {
|
SlashCommand::Fork if !trimmed.is_empty() => {
|
||||||
self.app_event_tx.send(AppEvent::ForkCurrentSession {
|
self.show_session_checkout_picker(
|
||||||
name: Some(trimmed.to_string()),
|
ManagedWorktreeMode::Fork,
|
||||||
});
|
Some(trimmed.to_string()),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
SlashCommand::Plan if !trimmed.is_empty() => {
|
SlashCommand::Plan if !trimmed.is_empty() => {
|
||||||
let plan_available = self.apply_plan_slash_command();
|
let plan_available = self.apply_plan_slash_command();
|
||||||
@@ -1139,6 +1144,8 @@ impl ChatWidget {
|
|||||||
goal_command_enabled: self.config.features.enabled(Feature::Goals),
|
goal_command_enabled: self.config.features.enabled(Feature::Goals),
|
||||||
service_tier_commands_enabled: self.fast_mode_enabled(),
|
service_tier_commands_enabled: self.fast_mode_enabled(),
|
||||||
personality_command_enabled: self.config.features.enabled(Feature::Personality),
|
personality_command_enabled: self.config.features.enabled(Feature::Personality),
|
||||||
|
worktrees_enabled: self.config.features.enabled(Feature::Worktrees)
|
||||||
|
&& self.local_worktree_operations,
|
||||||
allow_elevate_sandbox,
|
allow_elevate_sandbox,
|
||||||
side_conversation_active: self.active_side_conversation,
|
side_conversation_active: self.active_side_conversation,
|
||||||
}
|
}
|
||||||
@@ -1182,6 +1189,13 @@ impl ChatWidget {
|
|||||||
Some(thread_id) if self.can_change_working_directory(thread_id) => QueueDrain::Stop,
|
Some(thread_id) if self.can_change_working_directory(thread_id) => QueueDrain::Stop,
|
||||||
_ => QueueDrain::Continue,
|
_ => QueueDrain::Continue,
|
||||||
},
|
},
|
||||||
|
SlashCommand::Worktree => {
|
||||||
|
if self.managed_worktree_available() {
|
||||||
|
QueueDrain::Stop
|
||||||
|
} else {
|
||||||
|
QueueDrain::Continue
|
||||||
|
}
|
||||||
|
}
|
||||||
SlashCommand::Feedback
|
SlashCommand::Feedback
|
||||||
| SlashCommand::Export
|
| SlashCommand::Export
|
||||||
| SlashCommand::New
|
| SlashCommand::New
|
||||||
|
|||||||
+8
@@ -0,0 +1,8 @@
|
|||||||
|
---
|
||||||
|
source: tui/src/chatwidget/tests/slash_commands.rs
|
||||||
|
assertion_line: 3091
|
||||||
|
expression: popup
|
||||||
|
---
|
||||||
|
› /work
|
||||||
|
|
||||||
|
/worktree start or continue a conversation in a new worktree
|
||||||
+8
@@ -0,0 +1,8 @@
|
|||||||
|
---
|
||||||
|
source: tui/src/chatwidget/tests/slash_commands.rs
|
||||||
|
assertion_line: 3091
|
||||||
|
expression: popup
|
||||||
|
---
|
||||||
|
› /work
|
||||||
|
|
||||||
|
gpt-5.6-sol default · /tmp/project
|
||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
---
|
||||||
|
source: tui/src/chatwidget/tests/slash_commands.rs
|
||||||
|
expression: popup
|
||||||
|
---
|
||||||
|
Create a new worktree
|
||||||
|
|
||||||
|
› 1. Continue current conversation Preserve this conversation in the new
|
||||||
|
checkout
|
||||||
|
2. Start new conversation Open a fresh conversation in the new
|
||||||
|
checkout
|
||||||
|
|
||||||
|
Press enter to confirm or esc to go back
|
||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
---
|
||||||
|
source: tui/src/chatwidget/tests/slash_commands.rs
|
||||||
|
expression: popup
|
||||||
|
---
|
||||||
|
Where should the forked conversation run?
|
||||||
|
|
||||||
|
› 1. Current checkout Keep using the current working directory
|
||||||
|
2. New worktree Create an isolated managed checkout
|
||||||
|
|
||||||
|
Press enter to confirm or esc to go back
|
||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
---
|
||||||
|
source: tui/src/chatwidget/tests/slash_commands.rs
|
||||||
|
expression: popup
|
||||||
|
---
|
||||||
|
Where should the new conversation run?
|
||||||
|
|
||||||
|
› 1. Current checkout Keep using the current working directory
|
||||||
|
2. New worktree Create an isolated managed checkout
|
||||||
|
|
||||||
|
Press enter to confirm or esc to go back
|
||||||
@@ -273,6 +273,8 @@ mod status_command_tests;
|
|||||||
mod status_surface_previews;
|
mod status_surface_previews;
|
||||||
mod terminal_title;
|
mod terminal_title;
|
||||||
mod usage;
|
mod usage;
|
||||||
|
#[path = "tests/worktree_picker_tests.rs"]
|
||||||
|
mod worktree_picker;
|
||||||
|
|
||||||
pub(crate) use helpers::make_chatwidget_manual_with_sender;
|
pub(crate) use helpers::make_chatwidget_manual_with_sender;
|
||||||
pub(crate) use helpers::set_chatgpt_auth;
|
pub(crate) use helpers::set_chatgpt_auth;
|
||||||
|
|||||||
@@ -621,7 +621,7 @@ async fn queued_inline_rename_does_not_drain_again_before_turn_started() {
|
|||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn queued_unknown_slash_reports_error_when_dequeued() {
|
async fn queued_unknown_slash_reports_error_when_dequeued() {
|
||||||
let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
let (mut chat, mut rx, mut op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
||||||
chat.thread_id = Some(ThreadId::new());
|
chat.thread_id = Some(ThreadId::new());
|
||||||
handle_turn_started(&mut chat, "turn-1");
|
handle_turn_started(&mut chat, "turn-1");
|
||||||
|
|
||||||
@@ -642,6 +642,24 @@ async fn queued_unknown_slash_reports_error_when_dequeued() {
|
|||||||
"expected delayed slash error, got {rendered:?}"
|
"expected delayed slash error, got {rendered:?}"
|
||||||
);
|
);
|
||||||
assert!(chat.input_queue.queued_user_messages.is_empty());
|
assert!(chat.input_queue.queued_user_messages.is_empty());
|
||||||
|
|
||||||
|
chat.set_feature_enabled(Feature::Worktrees, /*enabled*/ true);
|
||||||
|
chat.set_local_worktree_operations(/*enabled*/ false);
|
||||||
|
let drain = chat.submit_queued_slash_prompt(UserMessage::from("/worktree extra").into());
|
||||||
|
assert_matches!(drain, QueueDrain::Continue);
|
||||||
|
assert_matches!(op_rx.try_recv(), Err(TryRecvError::Empty));
|
||||||
|
assert!(drain_insert_history(&mut rx).iter().any(|lines| {
|
||||||
|
lines_to_single_string(lines).contains("Unrecognized command '/worktree'")
|
||||||
|
}));
|
||||||
|
|
||||||
|
chat.set_local_worktree_operations(/*enabled*/ true);
|
||||||
|
let non_git = tempfile::tempdir().unwrap();
|
||||||
|
chat.config.cwd = non_git.path().to_path_buf().abs();
|
||||||
|
let drain = chat.submit_queued_slash_prompt(UserMessage::from("/worktree").into());
|
||||||
|
assert_matches!(drain, QueueDrain::Continue);
|
||||||
|
assert!(drain_insert_history(&mut rx).iter().any(|lines| {
|
||||||
|
lines_to_single_string(lines).contains("Managed worktrees require a local Git repository.")
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
|
|||||||
@@ -0,0 +1,91 @@
|
|||||||
|
//! Worktree picker behavior and rendered choices.
|
||||||
|
|
||||||
|
use super::*;
|
||||||
|
use pretty_assertions::assert_eq;
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn slash_new_and_fork_offer_checkout_choices_inside_local_git_repository() {
|
||||||
|
let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
||||||
|
let checkout = tempdir().expect("temporary checkout");
|
||||||
|
std::fs::create_dir(checkout.path().join(".git")).expect("git directory");
|
||||||
|
std::fs::write(checkout.path().join(".git/HEAD"), "ref: refs/heads/main\n").expect("git HEAD");
|
||||||
|
chat.config.cwd =
|
||||||
|
AbsolutePathBuf::from_absolute_path(checkout.path()).expect("absolute checkout");
|
||||||
|
|
||||||
|
chat.dispatch_command(SlashCommand::Fork);
|
||||||
|
assert_matches!(
|
||||||
|
rx.try_recv(),
|
||||||
|
Ok(AppEvent::ForkCurrentSession { name: None })
|
||||||
|
);
|
||||||
|
chat.dispatch_command(SlashCommand::New);
|
||||||
|
assert_matches!(rx.try_recv(), Ok(AppEvent::NewSession { name: None }));
|
||||||
|
|
||||||
|
chat.set_feature_enabled(Feature::Worktrees, /*enabled*/ true);
|
||||||
|
chat.dispatch_command(SlashCommand::Fork);
|
||||||
|
|
||||||
|
let popup = render_bottom_popup(&chat, /*width*/ 80);
|
||||||
|
assert_chatwidget_snapshot!("worktrees_fork_choices", popup);
|
||||||
|
chat.handle_key_event(KeyEvent::new(KeyCode::Esc, KeyModifiers::NONE));
|
||||||
|
chat.dispatch_command(SlashCommand::New);
|
||||||
|
let popup = render_bottom_popup(&chat, /*width*/ 80);
|
||||||
|
assert_chatwidget_snapshot!("worktrees_new_choices", popup);
|
||||||
|
assert!(popup.contains("Current checkout"), "popup: {popup}");
|
||||||
|
assert!(popup.contains("New worktree"), "popup: {popup}");
|
||||||
|
assert_matches!(rx.try_recv(), Err(TryRecvError::Empty));
|
||||||
|
chat.handle_key_event(KeyEvent::new(KeyCode::Esc, KeyModifiers::NONE));
|
||||||
|
chat.bottom_pane
|
||||||
|
.set_composer_text("/new named".into(), Vec::new(), Vec::new());
|
||||||
|
chat.handle_key_event(KeyEvent::new(KeyCode::Enter, KeyModifiers::NONE));
|
||||||
|
chat.handle_key_event(KeyEvent::new(KeyCode::Char('1'), KeyModifiers::NONE));
|
||||||
|
assert_matches!(rx.try_recv(), Ok(AppEvent::NewSession { name: Some(name) }) if name == "named");
|
||||||
|
chat.bottom_pane
|
||||||
|
.set_composer_text("/fork named".into(), Vec::new(), Vec::new());
|
||||||
|
chat.handle_key_event(KeyEvent::new(KeyCode::Enter, KeyModifiers::NONE));
|
||||||
|
chat.handle_key_event(KeyEvent::new(KeyCode::Char('2'), KeyModifiers::NONE));
|
||||||
|
assert_matches!(rx.try_recv(), Ok(AppEvent::StartManagedWorktree {
|
||||||
|
mode: crate::app_event::ManagedWorktreeMode::Fork,
|
||||||
|
name: Some(name),
|
||||||
|
}) if name == "named");
|
||||||
|
chat.set_local_worktree_operations(/*enabled*/ false);
|
||||||
|
chat.dispatch_command(SlashCommand::New);
|
||||||
|
assert_matches!(rx.try_recv(), Ok(AppEvent::NewSession { name: None }));
|
||||||
|
chat.dispatch_command(SlashCommand::Fork);
|
||||||
|
assert_matches!(
|
||||||
|
rx.try_recv(),
|
||||||
|
Ok(AppEvent::ForkCurrentSession { name: None })
|
||||||
|
);
|
||||||
|
for (available, snapshot) in [
|
||||||
|
(false, "worktrees_command_remote"),
|
||||||
|
(true, "worktrees_command_local"),
|
||||||
|
] {
|
||||||
|
chat.set_feature_enabled(Feature::Worktrees, /*enabled*/ true);
|
||||||
|
chat.set_local_worktree_operations(available);
|
||||||
|
chat.bottom_pane
|
||||||
|
.set_composer_text("/work".into(), Vec::new(), Vec::new());
|
||||||
|
let popup = normalize_snapshot_paths(render_bottom_popup(&chat, /*width*/ 80));
|
||||||
|
assert_chatwidget_snapshot!(snapshot, popup);
|
||||||
|
assert_eq!(popup.contains("/worktree"), available);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn slash_worktree_offers_current_or_new_conversation() {
|
||||||
|
let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
||||||
|
let checkout = tempdir().expect("temporary checkout");
|
||||||
|
std::fs::create_dir(checkout.path().join(".git")).expect("git directory");
|
||||||
|
std::fs::write(checkout.path().join(".git/HEAD"), "ref: refs/heads/main\n").expect("git HEAD");
|
||||||
|
chat.config.cwd =
|
||||||
|
AbsolutePathBuf::from_absolute_path(checkout.path()).expect("absolute checkout");
|
||||||
|
|
||||||
|
chat.set_feature_enabled(Feature::Worktrees, /*enabled*/ true);
|
||||||
|
chat.dispatch_command(SlashCommand::Worktree);
|
||||||
|
|
||||||
|
let popup = render_bottom_popup(&chat, /*width*/ 80);
|
||||||
|
assert_chatwidget_snapshot!("worktrees_conversation_choices", popup);
|
||||||
|
assert!(
|
||||||
|
popup.contains("Continue current conversation"),
|
||||||
|
"popup: {popup}"
|
||||||
|
);
|
||||||
|
assert!(popup.contains("Start new conversation"), "popup: {popup}");
|
||||||
|
assert_matches!(rx.try_recv(), Err(TryRecvError::Empty));
|
||||||
|
}
|
||||||
@@ -0,0 +1,121 @@
|
|||||||
|
//! Worktree choices for local, feature-enabled session commands.
|
||||||
|
|
||||||
|
use super::*;
|
||||||
|
use crate::app_event::ManagedWorktreeMode;
|
||||||
|
|
||||||
|
impl ChatWidget {
|
||||||
|
pub(super) fn managed_worktree_available(&self) -> bool {
|
||||||
|
self.config.features.enabled(Feature::Worktrees)
|
||||||
|
&& self.local_worktree_operations
|
||||||
|
&& get_git_repo_root(self.config.cwd.as_path()).is_some()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(super) fn show_session_checkout_picker(
|
||||||
|
&mut self,
|
||||||
|
mode: ManagedWorktreeMode,
|
||||||
|
name: Option<String>,
|
||||||
|
) {
|
||||||
|
if !self.managed_worktree_available() {
|
||||||
|
match mode {
|
||||||
|
ManagedWorktreeMode::New => {
|
||||||
|
self.app_event_tx.send(AppEvent::NewSession { name });
|
||||||
|
}
|
||||||
|
ManagedWorktreeMode::Fork => {
|
||||||
|
self.app_event_tx
|
||||||
|
.send(AppEvent::ForkCurrentSession { name });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let title = match mode {
|
||||||
|
ManagedWorktreeMode::New => "Where should the new conversation run?",
|
||||||
|
ManagedWorktreeMode::Fork => "Where should the forked conversation run?",
|
||||||
|
};
|
||||||
|
let current_name = name.clone();
|
||||||
|
self.bottom_pane.show_selection_view(SelectionViewParams {
|
||||||
|
title: Some(title.to_string()),
|
||||||
|
footer_hint: Some(standard_popup_hint_line()),
|
||||||
|
items: vec![
|
||||||
|
SelectionItem {
|
||||||
|
name: "Current checkout".to_string(),
|
||||||
|
description: Some("Keep using the current working directory".to_string()),
|
||||||
|
actions: vec![Box::new(move |tx| match mode {
|
||||||
|
ManagedWorktreeMode::New => {
|
||||||
|
tx.send(AppEvent::NewSession {
|
||||||
|
name: current_name.clone(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
ManagedWorktreeMode::Fork => {
|
||||||
|
tx.send(AppEvent::ForkCurrentSession {
|
||||||
|
name: current_name.clone(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})],
|
||||||
|
dismiss_on_select: true,
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
SelectionItem {
|
||||||
|
name: "New worktree".to_string(),
|
||||||
|
description: Some("Create an isolated managed checkout".to_string()),
|
||||||
|
actions: vec![Box::new(move |tx| {
|
||||||
|
tx.send(AppEvent::StartManagedWorktree {
|
||||||
|
mode,
|
||||||
|
name: name.clone(),
|
||||||
|
});
|
||||||
|
})],
|
||||||
|
dismiss_on_select: true,
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
],
|
||||||
|
..Default::default()
|
||||||
|
});
|
||||||
|
self.request_redraw();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(super) fn show_managed_worktree_picker(&mut self) {
|
||||||
|
if !self.config.features.enabled(Feature::Worktrees) {
|
||||||
|
self.add_error_message(
|
||||||
|
"Enable worktrees in /experimental to create a worktree.".to_string(),
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if !self.managed_worktree_available() {
|
||||||
|
self.add_error_message("Managed worktrees require a local Git repository.".to_string());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
self.bottom_pane.show_selection_view(SelectionViewParams {
|
||||||
|
title: Some("Create a new worktree".to_string()),
|
||||||
|
footer_hint: Some(standard_popup_hint_line()),
|
||||||
|
items: vec![
|
||||||
|
SelectionItem {
|
||||||
|
name: "Continue current conversation".to_string(),
|
||||||
|
description: Some("Preserve this conversation in the new checkout".to_string()),
|
||||||
|
actions: vec![Box::new(|tx| {
|
||||||
|
tx.send(AppEvent::StartManagedWorktree {
|
||||||
|
mode: ManagedWorktreeMode::Fork,
|
||||||
|
name: None,
|
||||||
|
});
|
||||||
|
})],
|
||||||
|
dismiss_on_select: true,
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
SelectionItem {
|
||||||
|
name: "Start new conversation".to_string(),
|
||||||
|
description: Some("Open a fresh conversation in the new checkout".to_string()),
|
||||||
|
actions: vec![Box::new(|tx| {
|
||||||
|
tx.send(AppEvent::StartManagedWorktree {
|
||||||
|
mode: ManagedWorktreeMode::New,
|
||||||
|
name: None,
|
||||||
|
});
|
||||||
|
})],
|
||||||
|
dismiss_on_select: true,
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
],
|
||||||
|
..Default::default()
|
||||||
|
});
|
||||||
|
self.request_redraw();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -35,6 +35,7 @@ pub enum SlashCommand {
|
|||||||
Delete,
|
Delete,
|
||||||
Resume,
|
Resume,
|
||||||
Fork,
|
Fork,
|
||||||
|
Worktree,
|
||||||
App,
|
App,
|
||||||
Init,
|
Init,
|
||||||
Compact,
|
Compact,
|
||||||
@@ -99,6 +100,7 @@ impl SlashCommand {
|
|||||||
SlashCommand::Delete => "permanently delete this session and exit",
|
SlashCommand::Delete => "permanently delete this session and exit",
|
||||||
SlashCommand::Clear => "clear the terminal and start a new chat",
|
SlashCommand::Clear => "clear the terminal and start a new chat",
|
||||||
SlashCommand::Fork => "fork the current chat",
|
SlashCommand::Fork => "fork the current chat",
|
||||||
|
SlashCommand::Worktree => "start or continue a conversation in a new worktree",
|
||||||
SlashCommand::App => "continue this session in the Desktop app",
|
SlashCommand::App => "continue this session in the Desktop app",
|
||||||
SlashCommand::Quit | SlashCommand::Exit => "exit Codex",
|
SlashCommand::Quit | SlashCommand::Exit => "exit Codex",
|
||||||
SlashCommand::Copy => "copy the last response or part of it",
|
SlashCommand::Copy => "copy the last response or part of it",
|
||||||
@@ -210,6 +212,7 @@ impl SlashCommand {
|
|||||||
| SlashCommand::Archive
|
| SlashCommand::Archive
|
||||||
| SlashCommand::Delete
|
| SlashCommand::Delete
|
||||||
| SlashCommand::Fork
|
| SlashCommand::Fork
|
||||||
|
| SlashCommand::Worktree
|
||||||
| SlashCommand::Init
|
| SlashCommand::Init
|
||||||
| SlashCommand::Compact
|
| SlashCommand::Compact
|
||||||
| SlashCommand::Recap
|
| SlashCommand::Recap
|
||||||
|
|||||||
Reference in new issue
Block a user