agent: Create TerminalToolCard and display shell output while it's running (#29546)

Also, don't require a worktree to run the terminal tool.

Release Notes:

- N/A
This commit is contained in:
João Marcos 2025-04-29 13:06:43 -03:00 committed by GitHub
parent 5afb89ca93
commit 83b8530e1f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 560 additions and 343 deletions

View file

@ -313,7 +313,7 @@ impl Display for TerminalError {
// https://github.com/alacritty/alacritty/blob/cb3a79dbf6472740daca8440d5166c1d4af5029e/extra/man/alacritty.5.scd?plain=1#L207-L213
const DEFAULT_SCROLL_HISTORY_LINES: usize = 10_000;
const MAX_SCROLL_HISTORY_LINES: usize = 100_000;
pub const MAX_SCROLL_HISTORY_LINES: usize = 100_000;
const URL_REGEX: &str = r#"(ipfs:|ipns:|magnet:|mailto:|gemini://|gopher://|https://|http://|news:|file://|git://|ssh:|ftp://)[^\u{0000}-\u{001F}\u{007F}-\u{009F}<>"\s{-}\^⟨⟩`]+"#;
// Optional suffix matches MSBuild diagnostic suffixes for path parsing in PathLikeWithPosition
// https://learn.microsoft.com/en-us/visualstudio/msbuild/msbuild-diagnostic-format-for-tasks
@ -1216,15 +1216,11 @@ impl Terminal {
}
///Write the Input payload to the tty.
fn write_to_pty(&self, input: String) {
self.pty_tx.notify(input.into_bytes());
fn write_to_pty(&self, input: impl Into<Vec<u8>>) {
self.pty_tx.notify(input.into());
}
fn write_bytes_to_pty(&self, input: Vec<u8>) {
self.pty_tx.notify(input);
}
pub fn input(&mut self, input: String) {
pub fn input(&mut self, input: impl Into<Vec<u8>>) {
self.events
.push_back(InternalEvent::Scroll(AlacScroll::Bottom));
self.events.push_back(InternalEvent::SetSelection(None));
@ -1232,14 +1228,6 @@ impl Terminal {
self.write_to_pty(input);
}
pub fn input_bytes(&mut self, input: Vec<u8>) {
self.events
.push_back(InternalEvent::Scroll(AlacScroll::Bottom));
self.events.push_back(InternalEvent::SetSelection(None));
self.write_bytes_to_pty(input);
}
pub fn toggle_vi_mode(&mut self) {
self.events.push_back(InternalEvent::ToggleViMode);
}
@ -1420,6 +1408,13 @@ impl Terminal {
}
}
pub fn get_content(&self) -> String {
let term = self.term.lock_unfair();
let start = AlacPoint::new(term.topmost_line(), Column(0));
let end = AlacPoint::new(term.bottommost_line(), term.last_column());
term.bounds_to_string(start, end)
}
pub fn last_n_non_empty_lines(&self, n: usize) -> Vec<String> {
let term = self.term.clone();
let terminal = term.lock_unfair();
@ -1858,6 +1853,8 @@ impl Terminal {
let completion_receiver = task.completion_rx.clone();
return cx
.spawn(async move |_| completion_receiver.recv().await.log_err().flatten());
} else if let Ok(status) = task.completion_rx.try_recv() {
return Task::ready(status);
}
}
Task::ready(None)