Skip to content

Conversation

@karthikscale3
Copy link
Contributor

@karthikscale3 karthikscale3 commented Nov 28, 2025

This PR adds a new control flow graph (CFG) extractor that analyzes bundled workflow files and generates graph manifests for workflow visualization.

Note: The corresponding UI updates for graph viewer are in #456

Changes

  • @workflow/builders: Add workflows-extractor.ts that parses workflow bundles using SWC to extract nodes and edges representing step calls, loops, conditionals, and parallel execution patterns
  • @workflow/builders: Add createWorkflowsManifest() method to BaseBuilder for generating workflow graph manifests post-bundle
  • @workflow/next: Integrate manifest generation into Next.js builder (initial build and watch mode rebuilds)

Output

Generates a workflows.json manifest containing React Flow-compatible graph data for each workflow, including:

  • Step nodes with metadata (loop context, conditional branches, parallel groups)
  • Edges representing control flow between steps
  • Support for transitive step resolution through helper functions

@changeset-bot
Copy link

changeset-bot bot commented Nov 28, 2025

🦋 Changeset detected

Latest commit: 8208f3c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 19 packages
Name Type
@workflow/world-postgres Patch
@workflow/world-local Patch
@workflow/sveltekit Patch
@workflow/builders Patch
@workflow/nitro Patch
@workflow/utils Patch
@workflow/world Patch
@workflow/core Patch
@workflow/next Patch
@workflow/web Patch
@workflow/cli Patch
workflow Patch
@workflow/astro Patch
@workflow/nuxt Patch
@workflow/errors Patch
@workflow/web-shared Patch
@workflow/world-testing Patch
@workflow/world-vercel Patch
@workflow/ai Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link
Contributor

vercel bot commented Nov 28, 2025

@karthikscale3 is attempting to deploy a commit to the Vercel Labs Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Collaborator

@pranaygp pranaygp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a bunch of comments we need to address. Very excited about this!

Let's try and just get things aligned with how we want to do manifests according to the versioning spec. I'll be a nuisance to try and clean this up later

@karthikscale3
Copy link
Contributor Author

@pranaygp thanks for the review! Great and valid points! Let me do a bit of thinking to address these.

@karthikscale3
Copy link
Contributor Author

@pranaygp Please take a look at the new iteration when you get a chance. Summary of the changes:

  1. Unified the partial manifest.debug.json files that gets generated inside .well-known/workflow/v1/flow and .well-known/workflow/v1/step directories as a single manifest.json.
  2. This new manifest.json file gets generated inside the .well-known/workflow/v1 directory for each builder.
  3. This manifest.json file is the single source of truth for all workflow metadata including the graph structure needed to build the Control Flow Graphs for the workflows and steps.
  4. See below the schema extension that allows this new structure. (A graph field is added to the workflows):
...
    "workflows": {
      "example/workflows/97_bench.ts": {
        "noStepsWorkflow": {
          "workflowId": "workflow//example/workflows/97_bench.ts//noStepsWorkflow",
          "graph": {
            "nodes": [
              {
                "id": "start",
                "type": "workflowStart",
                "data": {
                  "label": "Start: noStepsWorkflow",
                  "nodeKind": "workflow_start"
                }
              },
              {
                "id": "end",
                "type": "workflowEnd",
                "data": {
                  "label": "Return",
                  "nodeKind": "workflow_end"
                }
              }
            ],
            "edges": [
              {
                "id": "e_start_end",
                "source": "start",
                "target": "end",
                "type": "default"
              }
            ]
          }
        },
...
image

I, Karthik Kalyanaraman <[email protected]>, hereby add my Signed-off-by to this commit: 8a3f152

I, Karthik Kalyanaraman <[email protected]>, hereby add my Signed-off-by to this commit: 252a0dd

I, Karthik Kalyanaraman <[email protected]>, hereby add my Signed-off-by to this commit: b002d81

I, Karthik Kalyanaraman <[email protected]>, hereby add my Signed-off-by to this commit: 8e21d56

I, Karthik Kalyanaraman <[email protected]>, hereby add my Signed-off-by to this commit: 1c45af6

I, Karthik Kalyanaraman <[email protected]>, hereby add my Signed-off-by to this commit: 68b23e0

I, Karthik Kalyanaraman <[email protected]>, hereby add my Signed-off-by to this commit: e5f4cd8

I, Karthik Kalyanaraman <[email protected]>, hereby add my Signed-off-by to this commit: d537846

I, Karthik Kalyanaraman <[email protected]>, hereby add my Signed-off-by to this commit: 0f62431

Signed-off-by: Karthik Kalyanaraman <[email protected]>
Single-statement if/while/for/for-of bodies without braces were ignored.
Added recursive analysis for non-block bodies and corresponding tests.
Single-statement if/while/for/for-of bodies without braces were ignored.
Added recursive analysis for non-block bodies and corresponding tests.
}

/**
* Tests for single-statement control flow extraction.
Copy link
Contributor Author

@karthikscale3 karthikscale3 Dec 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a bunch of tests that cover the following scenarios:

single_statement_if() - Single-statement if and if-else without braces
single_statement_while() - Single-statement while loop without braces
single_statement_for() - Single-statement for and for-of loops without braces

cc @pranaygp


const selectedHookId = sidebar === 'hook' && hookId ? hookId : undefined;

// TODO(Karthik): Uncomment after https://github.com/vercel/workflow/pull/455 is merged
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These were reviewed, commented and merged since it had a dependency on this PR. I am just uncommenting them here to enable the corresponding UI changes.

I, Karthik Kalyanaraman <[email protected]>, hereby add my Signed-off-by to this commit: 6609b39

I, Karthik Kalyanaraman <[email protected]>, hereby add my Signed-off-by to this commit: 2484c01

I, Karthik Kalyanaraman <[email protected]>, hereby add my Signed-off-by to this commit: a0363a1

Signed-off-by: Karthik Kalyanaraman <[email protected]>
Signed-off-by: Karthik Kalyanaraman <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants