Add working-directory commands to the TUI (#38894)

## What changed

- Add `/cd [path]` for changing an idle local session's working directory while preserving conversation history. Relative paths resolve from the current directory, and omitting the path selects `~`.
- Reload project configuration, instructions, permissions, keybindings, file search, and hooks for the destination before replacing the active session.
- Reject unsafe transitions, including active or queued work, background terminals, remote environments, untrusted destinations, and incompatible permission profiles.
- Add `/pwd` and its `/cwd` alias to display the current working directory, and discard asynchronous results left over from the previous directory.

## Testing

- Cover command parsing, aliases, default paths, session eligibility, transition failures, history preservation, destination policy loading, hooks, and stale events.

GitOrigin-RevId: 1a987c029f157a087ba02c0f26e022260409132b
This commit is contained in:
Benjamin Carlsson authored and copyberry committed 2026-08-16 19:48:07 +00:00
1 parent 375996d3f5
commit ed32158e90
18 files changed
+776 -24

No files matched your search

@@ -0,0 +1,47 @@
//! Working-directory slash commands for the current local session.
use super::*;
use crate::history_cell::McpInventoryLoadingCell;
impl ChatWidget {
pub(crate) fn can_change_working_directory(&self, thread_id: ThreadId) -> bool {
let active = &self.transcript.active_cell;
self.thread_id == Some(thread_id)
&& !self.active_side_conversation
&& !self.blocks_direct_input
&& !self.config.ephemeral
&& self.unified_exec_processes.is_empty()
&& !self.is_user_turn_pending_or_running()
&& !self.input_queue.has_queued_follow_up_messages()
&& self.input_queue.pending_steers.is_empty()
&& active
.as_ref()
.is_none_or(|cell| !cell.as_any().is::<McpInventoryLoadingCell>())
}
pub(super) fn request_working_directory_change(&mut self, path: &str) {
if !self.is_session_configured() {
self.add_error_message(
"The session must start before you can change its working directory.".to_string(),
);
return;
}
let Some(thread_id) = self.thread_id else {
return;
};
if !self.can_change_working_directory(thread_id) {
let message =
"Changing directories requires an idle primary session without queued input.";
self.app_event_tx.send(AppEvent::InsertHistoryCell(Box::new(
history_cell::new_error_event(message.to_string()),
)));
return;
}
self.app_event_tx.send(AppEvent::ChangeWorkingDirectory {
thread_id,
requested_cwd: PathBuf::from(path),
});
}
}