Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion bin/tact/src/tui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,11 @@ pub(crate) async fn run(
1,
)
};
let workspace = config.agent().workspace().to_path_buf();
let mut terminal = TerminalSession::enter().map_err(RuntimeError::Terminal)?;
terminal
.report_working_directory(&workspace)
.map_err(RuntimeError::Terminal)?;
let ConfiguredAgent {
agent,
events,
Expand Down Expand Up @@ -541,7 +545,6 @@ pub(crate) async fn run(
worker::MemoryReviewState::fresh(memory_enabled)
};
let (commands, mut worker_updates) = worker::spawn(agent, memory_review, shutdown.clone());
let workspace = config.agent().workspace().to_path_buf();
let (agent_event_sender, mut agent_events) = mpsc::unbounded_channel();
agent_events::forward(PaneId::Main, 0, events, agent_event_sender.clone());
let (subagent_sender, mut subagent_events) = mpsc::unbounded_channel();
Expand Down Expand Up @@ -775,7 +778,14 @@ pub(crate) async fn run(
continue;
}
let record = runtime.journal_mut()?.append_agent(event)?;
// `tool.result` is the canonical completion event for every agent tool.
let tool_finished = record.kind() == "tool.result";
apply_app_update!(app.update(AppEvent::Transcript { pane, record }));
if tool_finished {
terminal
.report_working_directory(&workspace)
.map_err(RuntimeError::Terminal)?;
}
}
ForwardedAgentEvent::Closed { pane, session_id, generation } => {
let mut stream_closed = false;
Expand Down Expand Up @@ -1173,6 +1183,9 @@ pub(crate) async fn run(
}, if editor_task.is_some() && !stopping => {
editor_task = None;
terminal.resume().map_err(RuntimeError::Terminal)?;
terminal
.report_working_directory(&workspace)
.map_err(RuntimeError::Terminal)?;
app.refresh_terminal_images();
input = Some(EventStream::new());
match result.map_err(RuntimeError::ExternalEditorTask)?? {
Expand Down
23 changes: 23 additions & 0 deletions bin/tact/src/tui/terminal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use ratatui::{
use std::{
io::{self, IsTerminal, Stdout, Write, stdin, stdout},
panic,
path::Path,
sync::{
Once,
atomic::{AtomicBool, Ordering},
Expand Down Expand Up @@ -251,6 +252,10 @@ impl TerminalSession {
copy_to_clipboard(self.terminal.backend_mut(), text)
}

pub(crate) fn report_working_directory(&mut self, path: &Path) -> io::Result<()> {
write_osc7_working_directory(self.terminal.backend_mut(), path)
}

pub(crate) fn suspend(&mut self) -> io::Result<()> {
if !self.active {
return Ok(());
Expand Down Expand Up @@ -288,6 +293,14 @@ fn copy_to_clipboard(output: &mut impl Write, text: &str) -> io::Result<()> {
execute!(output, CopyToClipboard::to_clipboard_from(text))
}

fn write_osc7_working_directory(output: &mut impl Write, path: &Path) -> io::Result<()> {
let uri = url::Url::from_directory_path(path).map_err(|()| {
io::Error::new(io::ErrorKind::InvalidInput, "working directory is relative")
})?;
write!(output, "\x1b]7;{uri}\x1b\\")?;
output.flush()
}

impl Drop for TerminalSession {
fn drop(&mut self) {
if !self.active {
Expand Down Expand Up @@ -371,6 +384,7 @@ mod tests {
use super::{
MeasuredBackend, StableCursorBackend, activate_commands, begin_synchronized_update,
copy_to_clipboard, end_synchronized_update, reset_after_resume, restore_commands,
write_osc7_working_directory,
};
use crate::{
app::config::ReasoningEffort,
Expand Down Expand Up @@ -424,6 +438,15 @@ mod tests {
assert_eq!(output, b"\x1b]52;c;Y29weSBtZQ==\x1b\\");
}

#[test]
fn osc7_working_directory_uses_an_encoded_file_uri() {
let mut output = Vec::new();

write_osc7_working_directory(&mut output, Path::new("/work/with space")).unwrap();

assert_eq!(output, b"\x1b]7;file:///work/with%20space/\x1b\\");
}

#[test]
fn unchanged_frames_produce_zero_ratatui_diff_cells() {
let backend = MeasuredBackend {
Expand Down