mirror of
https://github.com/github/spec-kit.git
synced 2026-07-06 22:32:13 +08:00
feat(workflows): allow resume to accept updated workflow inputs (#2815)
`workflow resume` now accepts `--input key=value` (the same flag and parsing as `workflow run`, via a shared `_parse_input_values` helper). Supplied values are merged over the run's persisted inputs and re-resolved through the existing typed-validation path (`_resolve_inputs`), so a resumed/re-run step sees the updated inputs and ill-typed values fail fast. Keys not supplied keep their persisted values; resuming without `--input` is unchanged. Reference docs updated. Distinct from #2405 (file-reference inputs at run time): this is about supplying inputs at resume time, reusing the existing input model. Closes #2812. Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -2717,6 +2717,22 @@ workflow_catalog_app = typer.Typer(
|
||||
workflow_app.add_typer(workflow_catalog_app, name="catalog")
|
||||
|
||||
|
||||
def _parse_input_values(input_values: list[str] | None) -> dict[str, Any]:
|
||||
"""Parse repeated ``key=value`` CLI inputs into a dict.
|
||||
|
||||
Shared by ``workflow run`` and ``workflow resume``. Exits with an error
|
||||
on any entry missing ``=``.
|
||||
"""
|
||||
inputs: dict[str, Any] = {}
|
||||
for kv in input_values or []:
|
||||
if "=" not in kv:
|
||||
console.print(f"[red]Error:[/red] Invalid input format: {kv!r} (expected key=value)")
|
||||
raise typer.Exit(1)
|
||||
key, _, value = kv.partition("=")
|
||||
inputs[key.strip()] = value.strip()
|
||||
return inputs
|
||||
|
||||
|
||||
@workflow_app.command("run")
|
||||
def workflow_run(
|
||||
source: str = typer.Argument(..., help="Workflow ID or YAML file path"),
|
||||
@@ -2749,14 +2765,7 @@ def workflow_run(
|
||||
raise typer.Exit(1)
|
||||
|
||||
# Parse inputs
|
||||
inputs: dict[str, Any] = {}
|
||||
if input_values:
|
||||
for kv in input_values:
|
||||
if "=" not in kv:
|
||||
console.print(f"[red]Error:[/red] Invalid input format: {kv!r} (expected key=value)")
|
||||
raise typer.Exit(1)
|
||||
key, _, value = kv.partition("=")
|
||||
inputs[key.strip()] = value.strip()
|
||||
inputs = _parse_input_values(input_values)
|
||||
|
||||
console.print(f"\n[bold cyan]Running workflow:[/bold cyan] {definition.name} ({definition.id})")
|
||||
console.print(f"[dim]Version: {definition.version}[/dim]\n")
|
||||
@@ -2787,6 +2796,9 @@ def workflow_run(
|
||||
@workflow_app.command("resume")
|
||||
def workflow_resume(
|
||||
run_id: str = typer.Argument(..., help="Run ID to resume"),
|
||||
input_values: list[str] | None = typer.Option(
|
||||
None, "--input", "-i", help="Updated input values as key=value pairs"
|
||||
),
|
||||
):
|
||||
"""Resume a paused or failed workflow run."""
|
||||
from .workflows.engine import WorkflowEngine
|
||||
@@ -2795,8 +2807,10 @@ def workflow_resume(
|
||||
engine = WorkflowEngine(project_root)
|
||||
engine.on_step_start = lambda sid, label: console.print(f" \u25b8 [{sid}] {label} \u2026")
|
||||
|
||||
inputs = _parse_input_values(input_values)
|
||||
|
||||
try:
|
||||
state = engine.resume(run_id)
|
||||
state = engine.resume(run_id, inputs or None)
|
||||
except FileNotFoundError:
|
||||
console.print(f"[red]Error:[/red] Run not found: {run_id}")
|
||||
raise typer.Exit(1)
|
||||
|
||||
@@ -507,8 +507,19 @@ class WorkflowEngine:
|
||||
state.save()
|
||||
return state
|
||||
|
||||
def resume(self, run_id: str) -> RunState:
|
||||
"""Resume a paused or failed workflow run."""
|
||||
def resume(
|
||||
self,
|
||||
run_id: str,
|
||||
inputs: dict[str, Any] | None = None,
|
||||
) -> RunState:
|
||||
"""Resume a paused or failed workflow run.
|
||||
|
||||
When ``inputs`` is provided, the values are merged over the run's
|
||||
persisted inputs and re-resolved through the same typed validation
|
||||
path used by :meth:`execute`, so the resumed step sees updated
|
||||
workflow inputs. Keys not supplied keep their persisted values; an
|
||||
empty/``None`` ``inputs`` leaves the run's inputs unchanged.
|
||||
"""
|
||||
state = RunState.load(run_id, self.project_root)
|
||||
if state.status not in (RunStatus.PAUSED, RunStatus.FAILED):
|
||||
msg = f"Cannot resume run {run_id!r} with status {state.status.value!r}."
|
||||
@@ -524,6 +535,12 @@ class WorkflowEngine:
|
||||
else:
|
||||
definition = self.load_workflow(state.workflow_id)
|
||||
|
||||
# Merge any newly-supplied inputs over the persisted ones and
|
||||
# re-validate through the same typing path as the initial run.
|
||||
if inputs:
|
||||
merged = {**state.inputs, **inputs}
|
||||
state.inputs = self._resolve_inputs(definition, merged)
|
||||
|
||||
# Restore context
|
||||
context = StepContext(
|
||||
inputs=state.inputs,
|
||||
|
||||
Reference in New Issue
Block a user