MCPcopy Create free account
hub / github.com/astercloud/aster / demonstratePermissions

Function demonstratePermissions

examples/recipe/main.go:278–322  ·  view source on GitHub ↗

演示权限配置

(tmpDir string)

Source from the content-addressed store, hash-verified

276
277// 演示权限配置
278func demonstratePermissions(tmpDir string) {
279 fmt.Println("\n📋 权限模式配置")
280 fmt.Println(repeatStr("-", 50))
281
282 modes := []struct {
283 mode recipe.PermissionMode
284 desc string
285 }{
286 {recipe.PermissionAutoApprove, "自动批准所有工具执行"},
287 {recipe.PermissionSmartApprove, "根据风险级别智能决策"},
288 {recipe.PermissionAlwaysAsk, "所有工具都需要用户确认"},
289 }
290
291 fmt.Println(" 支持的权限模式:")
292 for _, m := range modes {
293 fmt.Printf(" - %s: %s\n", m.mode, m.desc)
294 }
295
296 // 创建不同权限模式的 Recipe
297 r, err := recipe.NewBuilder().
298 Title("Secure Assistant").
299 Description("高安全性助手").
300 PermissionMode(recipe.PermissionAlwaysAsk).
301 Tools("Bash", "Write", "Delete").
302 Build()
303
304 if err != nil {
305 log.Fatalf("创建 Recipe 失败: %v", err)
306 }
307
308 fmt.Printf("\n 创建高安全性 Recipe:\n")
309 fmt.Printf(" 权限模式: %s\n", r.PermissionMode)
310 fmt.Printf(" 工具: %v\n", r.Tools)
311
312 // 保存 Recipe
313 yamlPath := filepath.Join(tmpDir, "secure-assistant.yaml")
314 yamlData, err := r.ToYAML()
315 if err != nil {
316 log.Fatalf("序列化 Recipe 失败: %v", err)
317 }
318 if err := os.WriteFile(yamlPath, yamlData, 0644); err != nil {
319 log.Fatalf("保存 Recipe 失败: %v", err)
320 }
321 fmt.Printf(" ✓ 保存到: %s\n", yamlPath)
322}
323
324func repeatStr(s string, n int) string {
325 result := ""

Callers 1

mainFunction · 0.85

Calls 10

NewBuilderFunction · 0.92
PrintfMethod · 0.80
PermissionModeMethod · 0.80
TitleMethod · 0.80
repeatStrFunction · 0.70
BuildMethod · 0.65
ToolsMethod · 0.65
DescriptionMethod · 0.65
JoinMethod · 0.45
ToYAMLMethod · 0.45

Tested by

no test coverage detected