user shell command refactor

This commit is contained in:
kevin zhao
2025-11-04 14:03:35 -08:00
parent cb6584de46
commit 3b345e0cb4
11 changed files with 485 additions and 65 deletions

View File

@@ -493,6 +493,15 @@ pub enum EventMsg {
ExecCommandEnd(ExecCommandEndEvent),
/// Notification that the user initiated a shell command.
UserCommandBegin(UserCommandBeginEvent),
/// Incremental chunk of output from a running user command.
UserCommandOutputDelta(UserCommandOutputDeltaEvent),
/// Completion notification for a user shell command.
UserCommandEnd(UserCommandEndEvent),
/// Notification that the agent attached a local image via the view_image tool.
ViewImageToolCall(ViewImageToolCallEvent),
@@ -1267,6 +1276,51 @@ pub struct ExecCommandOutputDeltaEvent {
pub chunk: Vec<u8>,
}
#[derive(Debug, Clone, Deserialize, Serialize, JsonSchema, TS)]
pub struct UserCommandBeginEvent {
/// Identifier so this can be paired with the UserCommandEnd event.
pub call_id: String,
/// The command to be executed.
pub command: Vec<String>,
/// The command's working directory.
pub cwd: PathBuf,
pub parsed_cmd: Vec<ParsedCommand>,
}
#[derive(Debug, Clone, Deserialize, Serialize, JsonSchema, TS)]
pub struct UserCommandEndEvent {
/// Identifier for the UserCommandBegin that finished.
pub call_id: String,
/// Captured stdout.
pub stdout: String,
/// Captured stderr.
pub stderr: String,
/// Captured aggregated output.
#[serde(default)]
pub aggregated_output: String,
/// The command's exit code.
pub exit_code: i32,
/// The duration of the command execution.
#[ts(type = "string")]
pub duration: Duration,
/// Formatted output from the command, as seen by the model.
pub formatted_output: String,
}
#[serde_as]
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, JsonSchema, TS)]
pub struct UserCommandOutputDeltaEvent {
/// Identifier for the UserCommandBegin that produced this chunk.
pub call_id: String,
/// Which stream produced this chunk.
pub stream: ExecOutputStream,
/// Raw bytes from the stream (may not be valid UTF-8).
#[serde_as(as = "serde_with::base64::Base64")]
#[schemars(with = "String")]
#[ts(type = "string")]
pub chunk: Vec<u8>,
}
#[derive(Debug, Clone, Deserialize, Serialize, JsonSchema, TS)]
pub struct BackgroundEventEvent {
pub message: String,