Skip to main content

opendev_runtime/
plan_approval.rs

1//! Plan approval types shared between tools and TUI.
2//!
3//! `PlanDecision` and `PlanApprovalRequest` live here so that both
4//! `opendev-tools-impl` (which blocks inside `PresentPlanTool::execute()`)
5//! and `opendev-tui` (which renders the approval panel) can reference them
6//! without a circular dependency.
7
8use tokio::sync::{mpsc, oneshot};
9
10/// The user's decision on a presented plan.
11#[derive(Debug, Clone, PartialEq, Eq)]
12pub struct PlanDecision {
13    /// The action chosen: `"approve_auto"`, `"approve"`, or `"modify"`.
14    pub action: String,
15    /// Optional feedback text (empty unless the user chose to revise).
16    pub feedback: String,
17}
18
19/// A request sent from `PresentPlanTool` to the TUI for user approval.
20///
21/// The tool creates a oneshot channel, sends this struct through an mpsc
22/// channel, and then awaits the oneshot receiver. The TUI displays the
23/// plan, collects the user's decision, and sends it back via `response_tx`.
24#[derive(Debug)]
25pub struct PlanApprovalRequest {
26    /// The full plan content to display.
27    pub plan_content: String,
28    /// Oneshot sender the TUI uses to return the user's decision.
29    pub response_tx: oneshot::Sender<PlanDecision>,
30}
31
32/// Convenience type alias for the sender half that `PresentPlanTool` holds.
33pub type PlanApprovalSender = mpsc::UnboundedSender<PlanApprovalRequest>;
34
35/// Convenience type alias for the receiver half that the TUI polls.
36pub type PlanApprovalReceiver = mpsc::UnboundedReceiver<PlanApprovalRequest>;
37
38/// Create a paired (sender, receiver) for plan approval communication.
39pub fn plan_approval_channel() -> (PlanApprovalSender, PlanApprovalReceiver) {
40    mpsc::unbounded_channel()
41}
42
43#[cfg(test)]
44#[path = "plan_approval_tests.rs"]
45mod tests;