Skip to content

feat(workspace): deferred workspace creation — reference prior step outputs in workspace config #699

@nextlevelshit

Description

@nextlevelshit

Problem

Workspace configuration is resolved at pipeline parse time, before any steps execute. This means workspace fields like branch: can only use static values or pipeline-level template variables ({{ pipeline_id }}), not outputs from prior steps.

This forces patterns like:

  1. Create a throwaway worktree on {{ pipeline_id }}
  2. Inside the step prompt, git fetch && git checkout the real branch
  3. The worktree creation was wasted work

This matters most for cross-pipeline workflows like ops-pr-rework, where the target branch name comes from a prior step's output (the PR's headRefName).

Proposed Solution

Support step output references in workspace config:

steps:
  - id: fetch-review
    # ... produces artifact with head_branch field
    
  - id: apply-fixes
    dependencies: [fetch-review]
    workspace:
      type: worktree
      branch: "{{ steps.fetch-review.artifacts.review-findings.head_branch }}"

The workspace for apply-fixes is created after fetch-review completes, using the resolved value from its output artifact.

Implementation

Deferred resolution in executor

In internal/pipeline/executor.go, the workspace creation path currently runs before step execution. Change to:

  1. At step start, check if workspace config contains {{ steps.* }} references
  2. If yes, resolve the references from prior step artifacts (already available in .wave/artifacts/)
  3. Then create the workspace with the resolved config

This is a narrow change — only the workspace creation path needs to defer, not the full config resolution.

Template syntax

Reuse the existing template variable system. Add a steps namespace:

  • {{ steps.<step-id>.artifacts.<artifact-name>.<json-path> }} — read a field from a prior step's JSON artifact
  • {{ steps.<step-id>.output.<field> }} — read from step outcome metadata

Fallback

If the referenced step hasn't completed or the artifact doesn't exist, fail with a clear error rather than creating a broken workspace.

Acceptance Criteria

  • Workspace branch: field can reference prior step artifact values
  • Workspace creation is deferred until references are resolved
  • Clear error if referenced step/artifact doesn't exist
  • Existing static workspace configs unaffected
  • ops-pr-rework pipeline updated to use deferred branch resolution

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions