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

Function detectRuntimeFromCommand

pkg/workflow/runtime_detection.go:139–181  ·  view source on GitHub ↗

detectRuntimeFromCommand scans a command string for runtime indicators

(cmdLine string, requirements map[string]*RuntimeRequirement)

Source from the content-addressed store, hash-verified

137
138// detectRuntimeFromCommand scans a command string for runtime indicators
139func detectRuntimeFromCommand(cmdLine string, requirements map[string]*RuntimeRequirement) {
140 // Split by common shell delimiters and operators
141 words := strings.FieldsFunc(cmdLine, func(r rune) bool {
142 return r == ' ' || r == '|' || r == '&' || r == ';' || r == '\n' || r == '\t'
143 })
144
145 // Special handling for "gh aw" command pair.
146 for i := range len(words) - 1 {
147 if strings.EqualFold(words[i], "gh") && strings.EqualFold(words[i+1], "aw") {
148 if runtime := findRuntimeByID("gh-aw"); runtime != nil {
149 updateRequiredRuntime(runtime, getDefaultGhAWRuntimeVersion(), requirements)
150 }
151 break
152 }
153 }
154
155 for _, word := range words {
156 // Check if this word matches a known command
157 if runtime, exists := commandToRuntime[word]; exists {
158 // Special handling for "uv pip" to avoid detecting pip separately
159 if word == "pip" || word == "pip3" {
160 // Check if "uv" appears before this pip command
161 uvIndex := -1
162 pipIndex := -1
163 for i, w := range words {
164 if w == "uv" {
165 uvIndex = i
166 }
167 if w == word {
168 pipIndex = i
169 break
170 }
171 }
172 if uvIndex >= 0 && uvIndex < pipIndex {
173 // This is "uv pip", skip pip detection
174 continue
175 }
176 }
177
178 updateRequiredRuntime(runtime, "", requirements)
179 }
180 }
181}
182
183// getDefaultGhAWRuntimeVersion returns the default gh-aw runtime version to inject.
184// Release builds use the released compiler version; dev builds use the current build version.

Callers 3

detectFromCustomStepsFunction · 0.85

Calls 3

findRuntimeByIDFunction · 0.85
updateRequiredRuntimeFunction · 0.85

Tested by 2