-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontext.rs
More file actions
69 lines (58 loc) · 2.02 KB
/
Copy pathcontext.rs
File metadata and controls
69 lines (58 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/// Output of a command executed on the remote host.
#[derive(Debug, Clone)]
pub struct CommandOutput {
pub stdout: String,
pub stderr: String,
pub exit_code: i32,
}
impl CommandOutput {
/// Combined stdout + stderr, useful for sending to the LLM.
pub fn combined(&self) -> String {
let mut out = self.stdout.clone();
if !self.stderr.is_empty() {
if !out.is_empty() {
out.push('\n');
}
out.push_str(&self.stderr);
}
out
}
pub fn succeeded(&self) -> bool {
self.exit_code == 0
}
}
/// The interface that tools use to interact with the remote SSH session.
///
/// The main app will implement this trait on top of `TerminalTab` (PTY) or
/// a dedicated SSH exec channel — tools don't care which.
pub trait SshContext: Send + Sync {
/// Execute a shell command and return its output.
fn execute(&self, command: &str) -> anyhow::Result<CommandOutput>;
/// Read a remote file's full contents as UTF-8.
fn read_file(&self, path: &str) -> anyhow::Result<String>;
/// Write `content` to `path` on the remote host (create or overwrite).
fn write_file(&self, path: &str, content: &str) -> anyhow::Result<()>;
/// Append `content` to `path` on the remote host.
fn append_file(&self, path: &str, content: &str) -> anyhow::Result<()>;
/// List entries in a remote directory.
fn list_dir(&self, path: &str) -> anyhow::Result<Vec<DirEntry>>;
/// Return `true` if the remote path exists.
fn path_exists(&self, path: &str) -> anyhow::Result<bool>;
/// Return the current working directory of the remote session.
fn working_dir(&self) -> anyhow::Result<String>;
}
/// A single entry returned by `SshContext::list_dir`.
#[derive(Debug, Clone)]
pub struct DirEntry {
pub name: String,
pub kind: EntryKind,
/// Size in bytes (None if unknown).
pub size: Option<u64>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum EntryKind {
File,
Directory,
Symlink,
Other,
}