use crate::risk::Risk;
use agent_client_protocol::schema::v1::StopReason;
use bitrouter_substrate::translate::{PermissionOutcome, SessionUpdateKind};
use bitrouter_substrate::up::PendingPermission;
use crossterm::event::KeyEvent;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct PermOption {
pub outcome: PermissionOutcome,
pub label: String,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DiffData {
pub path: String,
pub old: String,
pub new: String,
}
#[derive(Debug, Clone)]
pub enum AppEvent {
Key(KeyEvent),
Update {
record_id: String,
update: SessionUpdateKind,
},
Permission {
record_id: String,
title: String,
diff: Option<DiffData>,
options: Vec<PermOption>,
risk: Risk,
},
TurnEnded {
record_id: String,
stop_reason: StopReason,
},
Exited { record_id: String },
AgentSpawned {
record_id: String,
agent_id: String,
port: Option<u16>,
},
AgentSpawnFailed { agent_id: String, error: String },
PromptFailed { record_id: String, error: String },
PtyAttached { record_id: String, agent_id: String },
SessionSpawned {
record_id: String,
binary: String,
model: Option<String>,
},
ReviewReady {
record_id: String,
files: u64,
adds: u64,
dels: u64,
},
ChecksFailed { record_id: String, output: String },
DiffLoaded { record_id: String, text: String },
OpDone {
record_id: String,
message: String,
ok: bool,
},
Paste(String),
Scroll { up: bool },
Click { col: u16, row: u16 },
Focus(bool),
ServeStatus { ok: bool },
Tick,
ForceQuit,
#[cfg(unix)]
BridgeConnected { conn: u64 },
#[cfg(unix)]
BridgeSpawned {
record_id: String,
agent_id: String,
port: Option<u16>,
},
#[cfg(unix)]
BridgeState { record_id: String, state: String },
#[cfg(unix)]
BridgeGone { record_ids: Vec<String> },
#[cfg(unix)]
BridgeNotify { message: String },
#[cfg(unix)]
BridgeRequestAttach { record_id: String },
#[cfg(unix)]
BridgeRequestReview { record_id: String },
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Effect {
Prompt { record_id: String, text: String },
ResolvePermission {
record_id: String,
outcome: PermissionOutcome,
},
Quit,
Bell,
Notify { title: String, body: String },
SpawnAgent { agent_id: String },
SpawnSession { binary: String },
CloseAgent { record_id: String },
PtyKey { record_id: String, key: KeyEvent },
PtyPaste { record_id: String, text: String },
PtyScroll {
record_id: String,
up: bool,
page: bool,
},
CancelTurn { record_id: String },
Attach { record_id: String },
CheckReview { record_id: String },
LoadDiff { record_id: String },
Merge { record_id: String },
Apply { record_id: String },
ReviewVerdict { record_id: String, note: String },
#[cfg(unix)]
BridgeHello { conn: u64, bootstrap_approved: bool },
#[cfg(unix)]
BridgeBootstrapApproved,
}
pub enum Incoming {
Update {
record_id: String,
update: SessionUpdateKind,
},
Permission {
record_id: String,
pending: Box<PendingPermission>,
},
PermissionNext {
record_id: String,
},
TurnEnded {
record_id: String,
stop_reason: StopReason,
},
Exited {
record_id: String,
},
PromptFailed {
record_id: String,
error: String,
},
ReviewReady {
record_id: String,
files: u64,
adds: u64,
dels: u64,
},
ChecksFailed {
record_id: String,
output: String,
},
DiffLoaded {
record_id: String,
text: String,
},
PtyOutput {
record_id: String,
bytes: Vec<u8>,
},
PtyExited {
record_id: String,
},
ServeStatus {
ok: bool,
},
Spawned {
agent_id: String,
session: Box<bitrouter_substrate::engine::Session>,
lease: Option<crate::fleet::PortLease>,
tag: String,
base_ref: String,
},
SpawnFailed {
agent_id: String,
error: String,
},
OpDone {
record_id: String,
message: String,
ok: bool,
},
#[cfg(unix)]
BridgeConnected {
conn: u64,
writer: tokio::net::unix::OwnedWriteHalf,
},
#[cfg(unix)]
Bridge {
conn: u64,
msg: crate::fleet::BridgeMsg,
},
#[cfg(unix)]
BridgeGone {
conn: u64,
},
}