Execute a workflow definition. Parameters ---------- definition: The validated workflow definition. inputs: User-provided input values. run_id: Optional run ID (uses SPECKIT_WORKFLOW_RUN_ID when set, otherwise auto-generate
(
self,
definition: WorkflowDefinition,
inputs: dict[str, Any] | None = None,
run_id: str | None = None,
)
| 621 | return validate_workflow(definition) |
| 622 | |
| 623 | def execute( |
| 624 | self, |
| 625 | definition: WorkflowDefinition, |
| 626 | inputs: dict[str, Any] | None = None, |
| 627 | run_id: str | None = None, |
| 628 | ) -> RunState: |
| 629 | """Execute a workflow definition. |
| 630 | |
| 631 | Parameters |
| 632 | ---------- |
| 633 | definition: |
| 634 | The validated workflow definition. |
| 635 | inputs: |
| 636 | User-provided input values. |
| 637 | run_id: |
| 638 | Optional run ID (uses SPECKIT_WORKFLOW_RUN_ID when set, otherwise auto-generated). |
| 639 | |
| 640 | Returns |
| 641 | ------- |
| 642 | The final ``RunState`` after execution completes (or pauses). |
| 643 | """ |
| 644 | from . import STEP_REGISTRY |
| 645 | |
| 646 | effective_run_id = run_id |
| 647 | if effective_run_id is None: |
| 648 | env_run_id = os.environ.get("SPECKIT_WORKFLOW_RUN_ID", "").strip() |
| 649 | if env_run_id: |
| 650 | effective_run_id = env_run_id |
| 651 | |
| 652 | state = RunState( |
| 653 | run_id=effective_run_id, |
| 654 | workflow_id=definition.id, |
| 655 | project_root=self.project_root, |
| 656 | ) |
| 657 | |
| 658 | # Persist a copy of the workflow definition so resume can |
| 659 | # reload it even if the original source is no longer available |
| 660 | # (e.g. a local YAML path that was moved or deleted). |
| 661 | run_dir = self.project_root / ".specify" / "workflows" / "runs" / state.run_id |
| 662 | run_dir.mkdir(parents=True, exist_ok=True) |
| 663 | workflow_copy = run_dir / "workflow.yml" |
| 664 | import yaml |
| 665 | with open(workflow_copy, "w", encoding="utf-8") as f: |
| 666 | yaml.safe_dump(definition.data, f, sort_keys=False) |
| 667 | |
| 668 | # Resolve inputs |
| 669 | resolved_inputs = self._resolve_inputs(definition, inputs or {}) |
| 670 | state.inputs = resolved_inputs |
| 671 | state.status = RunStatus.RUNNING |
| 672 | state.save() |
| 673 | |
| 674 | context = StepContext( |
| 675 | inputs=resolved_inputs, |
| 676 | default_integration=definition.default_integration, |
| 677 | default_model=definition.default_model, |
| 678 | default_options=definition.default_options, |
| 679 | project_root=str(self.project_root), |
| 680 | run_id=state.run_id, |