MCPcopy Index your code
hub / github.com/ChrisFeldmeier/OpenCodeRust / ask

Method ask

crates/opencode-permission/src/engine.rs:97–145  ·  view source on GitHub ↗
(&mut self, info: PermissionInfo)

Source from the content-addressed store, hash-verified

95 }
96
97 pub async fn ask(&mut self, info: PermissionInfo) -> Result<(), PermissionError> {
98 let session_id = info.session_id.clone();
99 let permission_id = info.id.clone();
100
101 if self.is_approved(&session_id, info.pattern.as_ref(), &info.permission_type) {
102 return Ok(());
103 }
104
105 // Plugin hook: permission.ask — plugins may decide "ask" | "deny" | "allow".
106 let mut hook_ctx = HookContext::new(HookEvent::PermissionAsk)
107 .with_session(&session_id)
108 .with_data("permission_type", serde_json::json!(&info.permission_type))
109 .with_data("permission_id", serde_json::json!(&permission_id))
110 .with_data("permission", serde_json::json!(&info))
111 .with_data("status", serde_json::json!("ask"));
112 if let Some(call_id) = &info.call_id {
113 hook_ctx = hook_ctx.with_data("call_id", serde_json::json!(call_id));
114 }
115
116 let mut status = "ask".to_string();
117 let hook_outputs = opencode_plugin::trigger_collect(hook_ctx).await;
118 for output in hook_outputs {
119 let Some(payload) = output.payload.as_ref() else {
120 continue;
121 };
122 if let Some(next_status) = extract_permission_status(payload) {
123 status = next_status;
124 }
125 }
126
127 match status.as_str() {
128 "allow" => return Ok(()),
129 "deny" => {
130 return Err(PermissionError::Rejected {
131 session_id: session_id.clone(),
132 permission_id: permission_id.clone(),
133 tool_call_id: info.call_id.clone(),
134 });
135 }
136 _ => {}
137 }
138
139 self.pending
140 .entry(session_id.clone())
141 .or_insert_with(HashMap::new)
142 .insert(permission_id, PendingPermission { info });
143
144 Ok(())
145 }
146
147 pub fn respond(
148 &mut self,

Callers 1

test_permission_engineFunction · 0.45

Calls 8

newFunction · 0.85
trigger_collectFunction · 0.85
is_approvedMethod · 0.80
with_dataMethod · 0.80
with_sessionMethod · 0.80
cloneMethod · 0.45
as_strMethod · 0.45

Tested by 1

test_permission_engineFunction · 0.36