(input, context)
| 169 | return input.prompt ? `${input.url}: ${input.prompt}` : input.url |
| 170 | }, |
| 171 | async checkPermissions(input, context): Promise<PermissionDecision> { |
| 172 | const appState = context.getAppState() |
| 173 | const permissionContext = appState.toolPermissionContext |
| 174 | |
| 175 | // Check if the hostname is in the preapproved list |
| 176 | try { |
| 177 | const { url } = input as { url: string } |
| 178 | const parsedUrl = new URL(url) |
| 179 | if (isPreapprovedHost(parsedUrl.hostname, parsedUrl.pathname)) { |
| 180 | return { |
| 181 | behavior: 'allow', |
| 182 | updatedInput: input, |
| 183 | decisionReason: { type: 'other', reason: 'Preapproved host' }, |
| 184 | } |
| 185 | } |
| 186 | } catch { |
| 187 | // If URL parsing fails, continue with normal permission checks |
| 188 | } |
| 189 | |
| 190 | // Check for a rule specific to the tool input (matching hostname) |
| 191 | const ruleContent = webFetchToolInputToPermissionRuleContent(input) |
| 192 | |
| 193 | const denyRule = getRuleByContentsForTool( |
| 194 | permissionContext, |
| 195 | WebFetchTool, |
| 196 | 'deny', |
| 197 | ).get(ruleContent) |
| 198 | if (denyRule) { |
| 199 | return { |
| 200 | behavior: 'deny', |
| 201 | message: `${WebFetchTool.name} denied access to ${ruleContent}.`, |
| 202 | decisionReason: { |
| 203 | type: 'rule', |
| 204 | rule: denyRule, |
| 205 | }, |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | const askRule = getRuleByContentsForTool( |
| 210 | permissionContext, |
| 211 | WebFetchTool, |
| 212 | 'ask', |
| 213 | ).get(ruleContent) |
| 214 | if (askRule) { |
| 215 | return { |
| 216 | behavior: 'ask', |
| 217 | message: `NCode requested permissions to use ${WebFetchTool.name}, but you haven't granted it yet.`, |
| 218 | decisionReason: { |
| 219 | type: 'rule', |
| 220 | rule: askRule, |
| 221 | }, |
| 222 | suggestions: buildSuggestions(ruleContent), |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | const allowRule = getRuleByContentsForTool( |
| 227 | permissionContext, |
| 228 | WebFetchTool, |
nothing calls this directly
no test coverage detected