-
Notifications
You must be signed in to change notification settings - Fork 445
Expand file tree
/
Copy pathadd_wizard_command.go
More file actions
139 lines (117 loc) · 6.9 KB
/
Copy pathadd_wizard_command.go
File metadata and controls
139 lines (117 loc) · 6.9 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package cli
import (
"errors"
"os"
"github.com/github/gh-aw/pkg/constants"
"github.com/github/gh-aw/pkg/logger"
"github.com/github/gh-aw/pkg/tty"
"github.com/spf13/cobra"
)
var addWizardLog = logger.New("cli:add_wizard_command")
// NewAddWizardCommand creates the add-wizard command, which is always interactive.
func NewAddWizardCommand(validateEngine func(string) error) *cobra.Command {
cmd := &cobra.Command{
Use: "add-wizard <workflow>...",
Short: "Interactively add one or more agentic workflows with guided setup",
Long: `Interactively add one or more agentic workflows with guided setup.
This command walks you through:
- Selecting an AI engine (Copilot, Claude, Codex, Gemini, or Crush)
- Configuring API keys and secrets
- Creating a pull request with the workflow
- Optionally running the workflow immediately
Use 'add' for non-interactive workflow addition.
Workflow specifications:
- Two parts: "owner/repo[@version]" (loads repository-root aw.yml package)
- Three+ parts without .md: "owner/repo/folder[@version]" (loads nested aw.yml package when present)
- Three parts: "owner/repo/workflow-name[@version]" (implicitly looks in workflows/ directory)
- Four+ parts: "owner/repo/workflows/workflow-name.md[@version]" (requires explicit .md extension)
- GitHub URL: "https://github.com/owner/repo/blob/branch/path/to/workflow.md"
- Arbitrary URL: "https://example.com/workflow.md" (fetches and dispatches on Content-Type)
- text/markdown → treated as a gh-aw workflow markdown file
- application/json → converted from a JSON workflow definition
- Local file: "./path/to/workflow.md"
- Version can be tag, branch, or SHA (for remote workflows)
Note: Requires an interactive terminal. Use 'add' for CI/automation environments.
Note: In GitHub Enterprise repos, shorthand source specs resolve on your enterprise host by default.
For github/*, githubnext/*, and microsoft/* sources, shorthand resolves on github.com.
Use full https://github.com/... source URLs for other public github.com workflows.
Note: To create a new workflow from scratch, use the 'new' command instead.`,
Example: ` ` + string(constants.CLIExtensionPrefix) + ` add-wizard githubnext/agentics # Guided setup for repository-root aw.yml package
` + string(constants.CLIExtensionPrefix) + ` add-wizard githubnext/agentics/packages/repo-assist # Guided setup for nested aw.yml package
` + string(constants.CLIExtensionPrefix) + ` add-wizard githubnext/agentics/daily-repo-status # Guided setup
` + string(constants.CLIExtensionPrefix) + ` add-wizard githubnext/agentics/ci-doctor@v1.0.0 # Guided setup with version
` + string(constants.CLIExtensionPrefix) + ` add-wizard ./my-workflow.md # Guided setup for local workflow
` + string(constants.CLIExtensionPrefix) + ` add-wizard https://example.com/my-workflow.md # Guided setup from any HTTPS URL
` + string(constants.CLIExtensionPrefix) + ` add-wizard https://example.com/workflow.json # Import JSON workflow definition with guided setup
` + string(constants.CLIExtensionPrefix) + ` add-wizard githubnext/agentics/ci-doctor --engine copilot # Pre-select engine
` + string(constants.CLIExtensionPrefix) + ` add-wizard githubnext/agentics/ci-doctor --no-secret # Skip secret prompt
` + string(constants.CLIExtensionPrefix) + ` add-wizard githubnext/agentics/ci-doctor --append "custom footer" # Append custom content
` + string(constants.CLIExtensionPrefix) + ` add-wizard githubnext/agentics/ci-doctor --no-security-scanner # Skip security scan
`,
Args: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
return errors.New("missing workflow specification\n\nRun 'gh aw add-wizard --help' for usage information")
}
return nil
},
RunE: func(cmd *cobra.Command, args []string) error {
workflows := args
engineOverride, _ := cmd.Flags().GetString("engine")
verbose, _ := cmd.Flags().GetBool("verbose")
noGitattributes, _ := cmd.Flags().GetBool("no-gitattributes")
workflowDir, _ := cmd.Flags().GetString("dir")
noStopAfter, _ := cmd.Flags().GetBool("no-stop-after")
stopAfter, _ := cmd.Flags().GetString("stop-after")
noSecret, _ := cmd.Flags().GetBool("no-secret")
skipSecretLegacy, _ := cmd.Flags().GetBool("skip-secret")
skipSecret := noSecret || skipSecretLegacy
appendText, _ := cmd.Flags().GetString("append")
disableSecurityScanner, _ := cmd.Flags().GetBool("no-security-scanner")
addWizardLog.Printf("Starting add-wizard: workflows=%v, engine=%s, verbose=%v", workflows, engineOverride, verbose)
if err := validateEngine(engineOverride); err != nil {
return err
}
// add-wizard requires an interactive terminal
isTerminal := tty.IsStdoutTerminal()
isCIEnv := os.Getenv("CI") != "" //nolint:osgetenvlibrary
addWizardLog.Printf("Terminal check: is_terminal=%v, is_ci=%v", isTerminal, isCIEnv)
if !isTerminal || isCIEnv {
return errors.New("add-wizard requires an interactive terminal; use 'add' for non-interactive environments")
}
return RunAddInteractive(cmd.Context(), &AddInteractiveConfig{
WorkflowSpecs: workflows,
Verbose: verbose,
EngineOverride: engineOverride,
NoGitattributes: noGitattributes,
WorkflowDir: workflowDir,
NoStopAfter: noStopAfter,
StopAfter: stopAfter,
SkipSecret: skipSecret,
AppendText: appendText,
DisableSecurityScanner: disableSecurityScanner,
})
},
}
// Add AI engine flag
addEngineFlag(cmd)
// Add no-gitattributes flag
cmd.Flags().Bool("no-gitattributes", false, "Skip updating .gitattributes file")
// Add workflow directory flag
cmd.Flags().StringP("dir", "d", "", "Workflow directory (default: $GH_AW_WORKFLOWS_DIR or .github/workflows)")
// Add no-stop-after flag
cmd.Flags().Bool("no-stop-after", false, "Remove any stop-after field from the workflow")
// Add stop-after flag
cmd.Flags().String("stop-after", "", "Override stop-after value in the workflow (e.g., '+48h', '2025-12-31 23:59:59')")
// Add no-secret flag (--skip-secret is kept as an undocumented alias)
cmd.Flags().Bool("no-secret", false, "Skip the API secret prompt (use when the secret is already set at the org or repo level)")
cmd.Flags().Bool("skip-secret", false, "Skip the API secret prompt (use when the secret is already set at the org or repo level)")
_ = cmd.Flags().MarkHidden("skip-secret")
// Add append flag (matches --append in add command)
cmd.Flags().String("append", "", "Append extra content to the end of agentic workflow on installation")
// Add no-security-scanner flag (matches --no-security-scanner in add command)
cmd.Flags().Bool("no-security-scanner", false, "Disable security scanning of workflow markdown content")
// Register completions
RegisterEngineFlagCompletion(cmd)
RegisterDirFlagCompletion(cmd, "dir")
return cmd
}