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

Method Resolve

pkg/workflow/engine_definition.go:227–273  ·  view source on GitHub ↗

Resolve returns a ResolvedEngineTarget for the given engine ID and config. Resolution order: 1. Exact match in the catalog by ID 2. Prefix match in the underlying EngineRegistry (backward compat, e.g. "codex-experimental") 3. Returns a formatted validation error when no match is found

(id string, config *EngineConfig)

Source from the content-addressed store, hash-verified

225// 2. Prefix match in the underlying EngineRegistry (backward compat, e.g. "codex-experimental")
226// 3. Returns a formatted validation error when no match is found
227func (c *EngineCatalog) Resolve(id string, config *EngineConfig) (*ResolvedEngineTarget, error) {
228 engineCatalogLog.Printf("Resolving engine: %s", id)
229
230 // Exact catalog lookup
231 if def, ok := c.definitions[id]; ok {
232 engineCatalogLog.Printf("Exact catalog match found for engine: %s (runtimeID=%s)", id, def.RuntimeID)
233 runtime, err := c.registry.GetEngine(def.RuntimeID)
234 if err != nil {
235 return nil, fmt.Errorf("engine %q definition references unknown runtime %q: %w", id, def.RuntimeID, err)
236 }
237 return &ResolvedEngineTarget{Definition: def, Config: config, Runtime: runtime}, nil
238 }
239
240 // Fall back to runtime-ID prefix lookup for backward compat (e.g. "codex-experimental")
241 runtime, err := c.registry.GetEngineByPrefix(id)
242 if err == nil {
243 engineCatalogLog.Printf("Engine %q resolved via runtime-ID prefix fallback to %q", id, runtime.GetID())
244 def := &EngineDefinition{
245 ID: id,
246 DisplayName: runtime.GetDisplayName(),
247 Description: runtime.GetDescription(),
248 RuntimeID: runtime.GetID(),
249 }
250 return &ResolvedEngineTarget{Definition: def, Config: config, Runtime: runtime}, nil
251 }
252
253 // Engine not found — produce a helpful validation error matching the existing format
254 engineCatalogLog.Printf("Engine not found: %s", id)
255 validEngines := c.registry.GetSupportedEngines()
256 suggestions := parser.FindClosestMatches(id, validEngines, 1)
257 enginesStr := strings.Join(validEngines, ", ")
258
259 errMsg := fmt.Sprintf("invalid engine: %s. Valid engines are: %s.\n\nExample:\nengine: copilot\n\nSee: %s",
260 id,
261 enginesStr,
262 constants.DocsEnginesURL)
263
264 if len(suggestions) > 0 {
265 errMsg = fmt.Sprintf("invalid engine: %s. Valid engines are: %s.\n\nDid you mean: %s?\n\nExample:\nengine: copilot\n\nSee: %s",
266 id,
267 enginesStr,
268 suggestions[0],
269 constants.DocsEnginesURL)
270 }
271
272 return nil, errors.New(errMsg)
273}

Calls 9

FindClosestMatchesFunction · 0.92
GetEngineMethod · 0.80
GetEngineByPrefixMethod · 0.80
GetSupportedEnginesMethod · 0.80
GetIDMethod · 0.65
GetDisplayNameMethod · 0.65
GetDescriptionMethod · 0.65
PrintfMethod · 0.45
ErrorfMethod · 0.45