Skip to content

feat: add typed workflow branching - #52

Merged
haseebahmed248 merged 1 commit into
mainfrom
feat/typed-workflow-branching
Sep 7, 2026
Merged

feat: add typed workflow branching#52
haseebahmed248 merged 1 commit into
mainfrom
feat/typed-workflow-branching

Conversation

@haseebahmed248

Copy link
Copy Markdown
Owner

Summary

Add explicit workflow decisions without moving control flow into host adapters. The compiler checks every final-result path, and selected branches share the runtime's existing permissions and budgets.

This is a draft pending the public RFC review in #51. Please record the RFC outcome before merging; this PR does not publish to npm.

Related issue

Closes #20.

RFC: #51. The deadline-dispatch guard also relates to #34.

Changes

  • Add if/else, else-if, nested blocks and explicit fail statements.
  • Check boolean conditions, lexical scopes, incompatible returns and unreachable/incomplete paths.
  • Count the maximum calls per path, including continuations but excluding continuations after a terminating arm.
  • Introduce IR v2 for control flow while preserving v1 output and generated contracts for linear sources.
  • Execute selected blocks with shared counters, cost and deadlines; prevent dispatch at an exhausted deadline.
  • Generate typed model contracts for each arm and add a keyless CLI example.
  • Cover branch diagnostics through the compiler and CLI, and execute the example from the actual installed npm tarball.

Validation

Local verification: Node.js 25.2.1, npm 11.6.2. The existing CI matrix covers Node.js 22/24 and package checks on Linux, macOS and Windows.

  • npm run check
  • npm run check:generated
  • npm test — 167 tests passed
  • Additional validation is described below, or was not needed.

Additional validation:

  • Clean dependency installation with npm ci.
  • npm run test:release — 4 tests passed.
  • npm run test:package — 115 package files, 7 public exports and both CLI aliases; generated v2 contracts type-check in an isolated consumer and both aliases pass all 5 branching scenarios.
  • git diff --check.

Risk and compatibility

  • Security or permission effects: branches do not grant authority or reset accounting. Only selected effects execute. Already-started model calls may still incur charges before cost enforcement. Host adapters and compiler IR remain trusted, not sandboxed.
  • Compatibility or breaking changes: compileSource returns WorkflowIr (v1 | v2). Explicit v1 consumers must narrow the version. Old npm runtimes cannot consume v2. Nested model contracts use path-qualified names. The event schema remains v1.
  • No union/optional narrowing, match, loops, retries or implicit branch-result joins are introduced. The supported subset and pending design questions are documented in the RFC and docs/BRANCHING.md.
  • README installation work assigned in Make the npm alpha easy to find and install #30 and the illustrative-example issue Replace the README's illustrative example with current GuardStep syntax #49 are untouched.

Checklist

  • This change is focused on one issue.
  • Behavioral changes include tests.
  • User-facing behavior and unsupported constructs are documented.
  • Generated files are current.
  • No credentials, private data, or unredacted model output are included.
  • Commits include the required DCO Signed-off-by line.

Signed-off-by: haseebahmed248 <haseebahmed6157@gmail.com>
@haseebahmed248
haseebahmed248 marked this pull request as ready for review September 7, 2026 17:51
@haseebahmed248
haseebahmed248 merged commit a4a6915 into main Sep 7, 2026
6 checks passed
@haseebahmed248
haseebahmed248 deleted the feat/typed-workflow-branching branch September 7, 2026 17:52
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.

Define and implement typed workflow branching

1 participant