-
Notifications
You must be signed in to change notification settings - Fork 78
feat: add channel-based AI tools and multi-round tool chaining for SSH sessions #152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
ead0b7f
feat(pty): add OutputBuffer for session output capture
jexShain fe064b9
feat(pty): add SessionInterceptor state machine for SSH AI interception
jexShain ea2064e
feat(pty): register session_interceptor module and exports
jexShain 7b6c576
feat(pty): integrate SessionInterceptor into select loop
jexShain d12e840
feat(shell): provide AI callback for session command interception
jexShain 2c18fb5
fix: resolve clippy warnings in session interceptor modules
jexShain c5bbb0c
feat: match SSH AI display with local aish UI
jexShain 94ba4b9
fix: robust at_line_start tracking and preserve user input line
jexShain bf13d4f
fix: support editing and cancellation during SSH AI input mode
jexShain 25f6e8f
feat: add channel-based AI tools and multi-round tool chaining for SS…
jexShain e52844b
fix: address CodeRabbit review feedback
jexShain db8ce72
fix: support multi-round bash tool calls and handle cancellation in S…
jexShain File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| //! Circular buffer that keeps the most recent N bytes of PTY output. | ||
| //! Used to provide context for AI error correction during SSH sessions. | ||
|
|
||
| pub struct OutputBuffer { | ||
| data: Vec<u8>, | ||
| capacity: usize, | ||
| write_pos: usize, | ||
| len: usize, | ||
| } | ||
|
|
||
| impl OutputBuffer { | ||
| pub fn new(capacity: usize) -> Self { | ||
| assert!(capacity > 0, "OutputBuffer capacity must be > 0"); | ||
| Self { | ||
| data: vec![0u8; capacity], | ||
| capacity, | ||
| write_pos: 0, | ||
| len: 0, | ||
| } | ||
| } | ||
|
|
||
| /// Append bytes, overwriting oldest data when full. | ||
| pub fn append(&mut self, input: &[u8]) { | ||
| for &byte in input { | ||
| self.data[self.write_pos] = byte; | ||
| self.write_pos = (self.write_pos + 1) % self.capacity; | ||
| if self.len < self.capacity { | ||
| self.len += 1; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// Return the most recent bytes up to `max_len`, in order. | ||
| pub fn recent(&self, max_len: usize) -> Vec<u8> { | ||
| let count = max_len.min(self.len); | ||
| let mut result = Vec::with_capacity(count); | ||
| let actual_start = if self.len < self.capacity { | ||
| self.len.saturating_sub(count) | ||
| } else { | ||
| (self.write_pos + self.capacity - count) % self.capacity | ||
| }; | ||
| for i in 0..count { | ||
| result.push(self.data[(actual_start + i) % self.capacity]); | ||
| } | ||
| result | ||
| } | ||
|
|
||
| /// Clear the buffer. | ||
| pub fn clear(&mut self) { | ||
| self.write_pos = 0; | ||
| self.len = 0; | ||
| } | ||
|
|
||
| /// Current number of bytes stored. | ||
| pub fn len(&self) -> usize { | ||
| self.len | ||
| } | ||
|
|
||
| /// Whether the buffer is empty. | ||
| pub fn is_empty(&self) -> bool { | ||
| self.len == 0 | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
|
|
||
| #[test] | ||
| fn test_basic_append_and_read() { | ||
| let mut buf = OutputBuffer::new(100); | ||
| buf.append(b"hello world"); | ||
| assert_eq!(buf.recent(100), b"hello world"); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_circular_overwrite() { | ||
| let mut buf = OutputBuffer::new(10); | ||
| buf.append(b"0123456789"); | ||
| assert_eq!(buf.recent(10), b"0123456789"); | ||
| buf.append(b"AB"); | ||
| assert_eq!(buf.recent(10), b"23456789AB"); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_recent_with_max_len() { | ||
| let mut buf = OutputBuffer::new(100); | ||
| buf.append(b"hello world"); | ||
| assert_eq!(buf.recent(5), b"world"); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_clear() { | ||
| let mut buf = OutputBuffer::new(100); | ||
| buf.append(b"data"); | ||
| buf.clear(); | ||
| assert!(buf.is_empty()); | ||
| assert_eq!(buf.len(), 0); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_wrap_around_multiple_times() { | ||
| let mut buf = OutputBuffer::new(5); | ||
| buf.append(b"ABCDE"); | ||
| buf.append(b"FGHIJ"); | ||
| buf.append(b"KLMNO"); | ||
| assert_eq!(buf.recent(5), b"KLMNO"); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_empty_buffer() { | ||
| let buf = OutputBuffer::new(100); | ||
| assert!(buf.is_empty()); | ||
| assert_eq!(buf.recent(100), b""); | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.