MCPcopy
hub / github.com/github/spec-kit / execute

Method execute

src/specify_cli/workflows/steps/prompt/__init__.py:39–95  ·  view source on GitHub ↗
(self, config: dict[str, Any], context: StepContext)

Source from the content-addressed store, hash-verified

37 type_key = "prompt"
38
39 def execute(self, config: dict[str, Any], context: StepContext) -> StepResult:
40 prompt_template = config.get("prompt", "")
41 prompt = evaluate_expression(prompt_template, context)
42 if not isinstance(prompt, str):
43 prompt = str(prompt)
44
45 # Resolve integration (step → workflow default)
46 integration = config.get("integration") or context.default_integration
47 if integration and isinstance(integration, str) and "{{" in integration:
48 integration = evaluate_expression(integration, context)
49
50 # Resolve model
51 model = config.get("model") or context.default_model
52 if model and isinstance(model, str) and "{{" in model:
53 model = evaluate_expression(model, context)
54
55 # Attempt CLI dispatch
56 dispatch_result = self._try_dispatch(
57 prompt, integration, model, context
58 )
59
60 output: dict[str, Any] = {
61 "prompt": prompt,
62 "integration": integration,
63 "model": model,
64 }
65
66 if dispatch_result is not None:
67 output["exit_code"] = dispatch_result["exit_code"]
68 output["stdout"] = dispatch_result["stdout"]
69 output["stderr"] = dispatch_result["stderr"]
70 output["dispatched"] = True
71 if dispatch_result["exit_code"] != 0:
72 return StepResult(
73 status=StepStatus.FAILED,
74 output=output,
75 error=(
76 dispatch_result["stderr"]
77 or f"Prompt exited with code {dispatch_result['exit_code']}"
78 ),
79 )
80 return StepResult(
81 status=StepStatus.COMPLETED,
82 output=output,
83 )
84 else:
85 output["exit_code"] = 1
86 output["dispatched"] = False
87 return StepResult(
88 status=StepStatus.FAILED,
89 output=output,
90 error=(
91 f"Cannot dispatch prompt: "
92 f"integration {integration!r} "
93 f"CLI not found or not installed."
94 ),
95 )
96

Calls 4

_try_dispatchMethod · 0.95
evaluate_expressionFunction · 0.90
StepResultClass · 0.90
getMethod · 0.45