parseGitHubAllowedToolsAndLimits parses tools.github.allowed entries. Supports string entries and object entries: {name: "tool_name", max-calls: 1}.
(allowedSetting any)
| 264 | // Supports string entries and object entries: |
| 265 | // {name: "tool_name", max-calls: 1}. |
| 266 | func parseGitHubAllowedToolsAndLimits(allowedSetting any) ([]string, map[string]int) { |
| 267 | allowedItems, ok := allowedSetting.([]any) |
| 268 | if !ok { |
| 269 | return parseStringSliceAny(allowedSetting, nil), nil |
| 270 | } |
| 271 | |
| 272 | allowedTools := make([]string, 0, len(allowedItems)) |
| 273 | toolCallLimits := make(map[string]int) |
| 274 | |
| 275 | for _, item := range allowedItems { |
| 276 | switch entry := item.(type) { |
| 277 | case string: |
| 278 | toolName := strings.TrimSpace(entry) |
| 279 | if toolName == "" { |
| 280 | continue |
| 281 | } |
| 282 | allowedTools = append(allowedTools, toolName) |
| 283 | case map[string]any: |
| 284 | toolName, ok := entry["name"].(string) |
| 285 | toolName = strings.TrimSpace(toolName) |
| 286 | if !ok || toolName == "" { |
| 287 | continue |
| 288 | } |
| 289 | allowedTools = append(allowedTools, toolName) |
| 290 | if maxCalls, hasMax := entry["max-calls"]; hasMax { |
| 291 | if max, ok := typeutil.ParseIntValue(maxCalls); ok && max > 0 { |
| 292 | toolCallLimits[toolName] = max |
| 293 | } |
| 294 | } |
| 295 | } |
| 296 | } |
| 297 | |
| 298 | if len(toolCallLimits) == 0 { |
| 299 | return allowedTools, nil |
| 300 | } |
| 301 | return allowedTools, toolCallLimits |
| 302 | } |
| 303 | |
| 304 | // getGitHubGuardPolicies extracts guard policies from GitHub tool configuration. |
| 305 | // It reads the flat allowed-repos/repos/min-integrity/blocked-users/trusted-users/approval-labels fields |
no test coverage detected