MCPcopy Create free account
hub / github.com/github/gh-aw / generateAllowedToolsComment

Method generateAllowedToolsComment

pkg/workflow/claude_tools.go:419–453  ·  view source on GitHub ↗

generateAllowedToolsComment generates a multi-line comment showing each allowed tool

(allowedToolsStr string, indent string)

Source from the content-addressed store, hash-verified

417
418// generateAllowedToolsComment generates a multi-line comment showing each allowed tool
419func (e *ClaudeEngine) generateAllowedToolsComment(allowedToolsStr string, indent string) string {
420 if allowedToolsStr == "" {
421 return ""
422 }
423
424 tools := strings.Split(allowedToolsStr, ",")
425 if len(tools) == 0 {
426 return ""
427 }
428
429 // Pre-size the builder using the exact output size:
430 // - header line: indent + "# Allowed tools (sorted):\n"
431 // - per tool: indent + "# - " + toolName + "\n"
432 // allowedToolsStr is comma-separated, so subtracting (len(tools)-1) gives the
433 // total bytes contributed by tool names alone.
434 toolNameBytes := len(allowedToolsStr) - (len(tools) - 1)
435 var comment strings.Builder
436 comment.Grow(
437 len(indent) +
438 len("# Allowed tools (sorted):\n") +
439 len(tools)*len(indent) +
440 len(tools)*len("# - \n") +
441 toolNameBytes,
442 )
443 comment.WriteString(indent)
444 comment.WriteString("# Allowed tools (sorted):\n")
445 for _, tool := range tools {
446 comment.WriteString(indent)
447 comment.WriteString("# - ")
448 comment.WriteString(tool)
449 comment.WriteByte('\n')
450 }
451
452 return comment.String()
453}

Callers 2

GetExecutionStepsMethod · 0.95

Calls 1

StringMethod · 0.45

Tested by 1