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

Function GenerateWorkflowHeader

pkg/workflow/header.go:24–85  ·  view source on GitHub ↗

GenerateWorkflowHeader generates the standard header comment for generated workflow files. It includes the ASCII art logo and instructions on how to regenerate the file. Parameters: - sourceFile: The source file path (e.g., ".md" file) that generated this workflow, or empty if not applicable - gene

(sourceFile string, generatedBy string, customInstructions string)

Source from the content-addressed store, hash-verified

22// - generatedBy: Description of what generated this file (e.g., "gh-aw", "pkg/workflow/maintenance_workflow.go")
23// - customInstructions: Optional additional instructions to display after the standard regeneration instructions
24func GenerateWorkflowHeader(sourceFile string, generatedBy string, customInstructions string) string {
25 headerLog.Printf("Generating workflow header: sourceFile=%s, generatedBy=%s, hasCustomInstructions=%v",
26 sourceFile, generatedBy, customInstructions != "")
27
28 var header strings.Builder
29
30 // Add auto-generated disclaimer as the very first line.
31 // This ensures agents see the notice immediately and can load the debugging skill.
32 // Include version for released builds only (not "dev")
33 const skillPointer = " To debug this workflow, load the skill at https://github.com/github/gh-aw/blob/main/debug.md"
34 if generatedBy != "" {
35 if IsReleasedVersion(GetVersion()) {
36 fmt.Fprintf(&header, "# This file was automatically generated by %s (%s). DO NOT EDIT.%s\n", generatedBy, GetVersion(), skillPointer)
37 } else {
38 fmt.Fprintf(&header, "# This file was automatically generated by %s. DO NOT EDIT.%s\n", generatedBy, skillPointer)
39 }
40 } else {
41 fmt.Fprintf(&header, "# This file was automatically generated. DO NOT EDIT.%s\n", skillPointer)
42 }
43 header.WriteString("#\n")
44
45 // Add ASCII logo
46 // TrimRight removes only trailing newlines, preserving per-line leading spaces
47 logoLines := strings.Split(strings.TrimRight(headerAsciiLogo, "\n"), "\n")
48 headerLog.Printf("Adding ASCII logo with %d lines", len(logoLines))
49 for _, line := range logoLines {
50 fmt.Fprintf(&header, "# %s\n", line)
51 }
52 header.WriteString("#\n")
53 header.WriteString("#\n")
54
55 // Add regeneration instructions
56 if sourceFile != "" {
57 fmt.Fprintf(&header, "# To update this file, edit %s and run:\n", sourceFile)
58 } else {
59 header.WriteString("# To regenerate this workflow, run:\n")
60 }
61 header.WriteString("# " + string(constants.CLIExtensionPrefix) + " compile\n")
62 header.WriteString("# Not all edits will cause changes to this file.\n")
63 header.WriteString("#\n")
64 header.WriteString("# For more information: https://github.github.com/gh-aw/introduction/overview/\n")
65
66 // Add custom instructions if provided
67 if customInstructions != "" {
68 header.WriteString("#\n")
69 // Split custom instructions into lines and prefix each with "# "
70 instructionLines := strings.Split(strings.TrimSpace(customInstructions), "\n")
71 headerLog.Printf("Adding %d lines of custom instructions", len(instructionLines))
72 for _, line := range instructionLines {
73 if trimmedLine := strings.TrimSpace(line); trimmedLine == "" {
74 header.WriteString("#\n")
75 } else {
76 fmt.Fprintf(&header, "# %s\n", trimmedLine)
77 }
78 }
79 }
80
81 header.WriteString("#\n")

Calls 4

IsReleasedVersionFunction · 0.85
GetVersionFunction · 0.70
PrintfMethod · 0.45
StringMethod · 0.45