pub struct PlanApprovalGate {
pub exploring_plan_mode: Arc<AtomicBool>,
pub pending_plan: Arc<RwLock<Option<String>>>,
/* private fields */
}Expand description
Shared state for the agent-driven plan mode approval flow.
A single Arc<PlanApprovalGate> is created in [AgentRuntimeBuilder::build]
and shared between:
EnterPlanModeTool— setsexploring_plan_modeExitPlanModeTool— clears flag, emits event, awaits decision- [
AgentRuntime] — callsapprove/reject RunCore— readsexploring_plan_modeto gate writes
Fields§
§exploring_plan_mode: Arc<AtomicBool>true while the agent is in exploring (read-only plan) mode.
pending_plan: Arc<RwLock<Option<String>>>The plan text currently pending review (set by ExitPlanModeTool).
Implementations§
Source§impl PlanApprovalGate
impl PlanApprovalGate
Sourcepub async fn wait_for_approval(&self) -> PlanApprovalResult
pub async fn wait_for_approval(&self) -> PlanApprovalResult
Block until the human reviewer sets a decision.
Reads the response without holding any lock across .await, preventing
deadlocks. On return the stored response is cleared so the gate can be
reused for the next exit_plan_mode call.
Sourcepub fn approve(&self)
pub fn approve(&self)
Approve the pending plan. Called by TUI / HTTP on user confirmation.
Clears the pending plan text so stale re-injection after compaction
cannot occur — the reinjector reads pending_plan
which returns None after this call.
Sourcepub fn reject(&self, reason: impl Into<String>)
pub fn reject(&self, reason: impl Into<String>)
Reject the pending plan with a reason. Called by TUI / HTTP.
Clears the pending plan text so stale re-injection after compaction cannot occur.
Sourcepub fn pending_plan(&self) -> Option<String>
pub fn pending_plan(&self) -> Option<String>
Return the currently-pending plan text, if any (set by
begin_approval, cleared by
approve or reject).
Used by post-compact re-injection so the model retains the plan
across compaction while it is still pending approval.
Returns None gracefully on a poisoned lock (invariant #5 —
no unwrap in product code).
Sourcepub fn begin_approval(&self, plan_text: String)
pub fn begin_approval(&self, plan_text: String)
Set the pending plan text and clear any stale approval/rejection from a previous cycle.
Must be called instead of writing pending_plan directly so that
a ghost response left over from a duplicate concurrent HTTP request
(TOCTOU race) cannot bypass the human-approval gate on the next round.