-
Notifications
You must be signed in to change notification settings - Fork 424
Expand file tree
/
Copy pathheader.go
More file actions
85 lines (73 loc) · 3.32 KB
/
Copy pathheader.go
File metadata and controls
85 lines (73 loc) · 3.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package workflow
import (
_ "embed"
"fmt"
"strings"
"github.com/github/gh-aw/pkg/constants"
"github.com/github/gh-aw/pkg/logger"
)
var headerLog = logger.New("workflow:header")
//go:embed assets/logo.txt
var headerAsciiLogo string
// 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
// - generatedBy: Description of what generated this file (e.g., "gh-aw", "pkg/workflow/maintenance_workflow.go")
// - customInstructions: Optional additional instructions to display after the standard regeneration instructions
func GenerateWorkflowHeader(sourceFile string, generatedBy string, customInstructions string) string {
headerLog.Printf("Generating workflow header: sourceFile=%s, generatedBy=%s, hasCustomInstructions=%v",
sourceFile, generatedBy, customInstructions != "")
var header strings.Builder
// Add auto-generated disclaimer as the very first line.
// This ensures agents see the notice immediately and can load the debugging skill.
// Include version for released builds only (not "dev")
const skillPointer = " To debug this workflow, load the skill at https://github.com/github/gh-aw/blob/main/debug.md"
if generatedBy != "" {
if IsReleasedVersion(GetVersion()) {
fmt.Fprintf(&header, "# This file was automatically generated by %s (%s). DO NOT EDIT.%s\n", generatedBy, GetVersion(), skillPointer)
} else {
fmt.Fprintf(&header, "# This file was automatically generated by %s. DO NOT EDIT.%s\n", generatedBy, skillPointer)
}
} else {
fmt.Fprintf(&header, "# This file was automatically generated. DO NOT EDIT.%s\n", skillPointer)
}
header.WriteString("#\n")
// Add ASCII logo
// TrimRight removes only trailing newlines, preserving per-line leading spaces
logoLines := strings.Split(strings.TrimRight(headerAsciiLogo, "\n"), "\n")
headerLog.Printf("Adding ASCII logo with %d lines", len(logoLines))
for _, line := range logoLines {
fmt.Fprintf(&header, "# %s\n", line)
}
header.WriteString("#\n")
header.WriteString("#\n")
// Add regeneration instructions
if sourceFile != "" {
fmt.Fprintf(&header, "# To update this file, edit %s and run:\n", sourceFile)
} else {
header.WriteString("# To regenerate this workflow, run:\n")
}
header.WriteString("# " + string(constants.CLIExtensionPrefix) + " compile\n")
header.WriteString("# Not all edits will cause changes to this file.\n")
header.WriteString("#\n")
header.WriteString("# For more information: https://github.github.com/gh-aw/introduction/overview/\n")
// Add custom instructions if provided
if customInstructions != "" {
header.WriteString("#\n")
// Split custom instructions into lines and prefix each with "# "
instructionLines := strings.Split(strings.TrimSpace(customInstructions), "\n")
headerLog.Printf("Adding %d lines of custom instructions", len(instructionLines))
for _, line := range instructionLines {
if trimmedLine := strings.TrimSpace(line); trimmedLine == "" {
header.WriteString("#\n")
} else {
fmt.Fprintf(&header, "# %s\n", trimmedLine)
}
}
}
header.WriteString("#\n")
headerLog.Printf("Generated header with %d bytes", header.Len())
return header.String()
}