-
Notifications
You must be signed in to change notification settings - Fork 3.3k
feat(tui): save ask permission rules from approvals #3301
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8664,17 +8664,20 @@ async fn handle_view_events( | |
| timed_out, | ||
| approval_key, | ||
| approval_grouping_key, | ||
| persistent_ask_rules, | ||
| } => { | ||
| apply_approval_decision( | ||
| app, | ||
| engine_handle, | ||
| config, | ||
| ApprovalDecisionEvent { | ||
| tool_id, | ||
| tool_name, | ||
| decision, | ||
| timed_out, | ||
| approval_key, | ||
| approval_grouping_key, | ||
| persistent_ask_rules, | ||
| }, | ||
| ) | ||
| .await; | ||
|
|
@@ -9014,11 +9017,13 @@ struct ApprovalDecisionEvent { | |
| timed_out: bool, | ||
| approval_key: String, | ||
| approval_grouping_key: String, | ||
| persistent_ask_rules: Vec<codewhale_config::ToolAskRule>, | ||
| } | ||
|
|
||
| async fn apply_approval_decision( | ||
| app: &mut App, | ||
| engine_handle: &mut EngineHandle, | ||
| config: &mut Config, | ||
| event: ApprovalDecisionEvent, | ||
| ) { | ||
| if event.decision == ReviewDecision::ApprovedForSession { | ||
|
|
@@ -9031,6 +9036,15 @@ async fn apply_approval_decision( | |
| .insert(event.approval_grouping_key.clone()); | ||
| } | ||
|
|
||
| if matches!( | ||
| event.decision, | ||
| ReviewDecision::Approved | ReviewDecision::ApprovedForSession | ||
| ) && !event.persistent_ask_rules.is_empty() | ||
| && !event.timed_out | ||
| { | ||
| persist_ask_rules_from_approval(app, config, &event.persistent_ask_rules); | ||
| } | ||
|
|
||
| match event.decision { | ||
| ReviewDecision::Approved | ReviewDecision::ApprovedForSession => { | ||
| let _ = engine_handle.approve_tool_call(event.tool_id).await; | ||
|
|
@@ -9053,6 +9067,35 @@ async fn apply_approval_decision( | |
| } | ||
| } | ||
|
|
||
| fn persist_ask_rules_from_approval( | ||
| app: &mut App, | ||
| config: &mut Config, | ||
| rules: &[codewhale_config::ToolAskRule], | ||
| ) { | ||
| match codewhale_config::ConfigStore::load(app.config_path.clone()).and_then(|mut store| { | ||
| let added = store.append_ask_rules(rules)?; | ||
| let permissions_path = store.permissions_path(); | ||
| config.exec_policy_engine = store.exec_policy_engine(); | ||
| Ok((added, permissions_path)) | ||
| }) { | ||
| Ok((added, path)) if added > 0 => { | ||
| app.status_message = Some(format!( | ||
| "Saved {added} ask permission rule(s) to {}", | ||
| path.display() | ||
| )); | ||
| } | ||
| Ok((_added, path)) => { | ||
| app.status_message = Some(format!( | ||
| "Ask permission rule already saved in {}", | ||
| path.display() | ||
| )); | ||
| } | ||
| Err(err) => { | ||
| app.status_message = Some(format!("Failed to save ask permission rule: {err:#}")); | ||
| } | ||
|
Comment on lines
+9081
to
+9095
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The status messages set in |
||
| } | ||
| } | ||
|
|
||
| fn mark_active_turn_cancelled_locally(app: &mut App) { | ||
| // #2739: every local cancel surface (Esc, Ctrl+C, approval abort, paused | ||
| // command abort) must snapshot before it clears turn state. Otherwise | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The condition checks
ReviewDecision::ApprovedForSessionto decide whether to persist the ask rules. However, 'Approved for Session' is intended to be a temporary, session-only approval. Persisting rules topermissions.tomlunder this decision contradicts the user's choice of a session-only approval. We should only persist rules when the decision is permanentlyApproved.