Skip to content

Add EngineBuilder fluent API for reusable engine initialization#197

Merged
intel352 merged 6 commits intomainfrom
copilot/add-workflow-engine-support
Feb 27, 2026
Merged

Add EngineBuilder fluent API for reusable engine initialization#197
intel352 merged 6 commits intomainfrom
copilot/add-workflow-engine-support

Conversation

Copy link
Contributor

Copilot AI commented Feb 27, 2026

  • Explore repository structure and understand current engine initialization patterns
  • Identify the problem: CLI, MCP, tests all duplicate engine setup boilerplate
  • Create EngineBuilder fluent API in engine_builder.go with:
    • NewEngineBuilder() constructor
    • WithApplication(app) / WithLogger(logger) - custom dependencies
    • WithDefaultHandlers() - register all 8 built-in workflow handlers
    • WithDefaultTriggers() - register all 5 built-in triggers
    • WithDynamicComponents() - set up dynamic interpreter/registry/loader
    • WithAllDefaults() - convenience for all of the above
    • WithHandler(h) / WithTrigger(t) - custom components
    • WithPlugin(p) / WithPlugins(p...) - load plugins
    • WithPluginLoader(l) - custom plugin loader
    • WithConfigPath(path) - for BuildAndConfigure
    • Build() / BuildFromConfig(cfg) / BuildAndConfigure() - create engine
    • RunUntilSignal(cfg) - CLI convenience for start/signal/stop
  • Create setup package for default handler/trigger registration (avoids import cycles)
  • Write 19 comprehensive tests (17 builder + 2 setup)
  • Refactor CLI cmd/wfctl/run.go to use the builder (with _ setup import)
  • Refactor CLI cmd/wfctl/pipeline.go to use the builder
  • Update scaffold templates (api-service, event-processor, full-stack) to use builder with correct _ setup import
  • Add MCP engine integration:
    • EngineProvider interface in mcp package
    • WithEngine(engine) server option
    • run_workflow tool for AI-driven workflow execution
    • 6 new tests for engine integration
  • All tests pass: root (17 builder), mcp (32), wfctl, setup (2)
  • No import cycles (go vet ./... clean)
  • Linting passes (golangci-lint run ./... - 0 issues)
  • Code review feedback addressed:
    • Fixed setup/setup.go package doc (removed non-existent function references, added correct blank-import usage example)
    • Added _ "github.com/GoCodeAlone/workflow/setup" to all 3 scaffold templates
    • Updated EngineBuilder type doc with setup import example
    • Added setup import requirement note to WithDefaultHandlers(), WithDefaultTriggers(), WithAllDefaults()

🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Copilot AI and others added 3 commits February 27, 2026 12:35
…integration

Co-authored-by: intel352 <77607+intel352@users.noreply.github.com>
…ate tests and CLI

Co-authored-by: intel352 <77607+intel352@users.noreply.github.com>
Co-authored-by: intel352 <77607+intel352@users.noreply.github.com>
Copilot AI changed the title [WIP] Add functionality for workflow engine in CLI and MCP Add EngineBuilder fluent API for reusable engine initialization Feb 27, 2026
@intel352 intel352 marked this pull request as ready for review February 27, 2026 13:05
Copilot AI review requested due to automatic review settings February 27, 2026 13:05
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces a fluent EngineBuilder API to eliminate ~20 lines of boilerplate code needed to initialize the workflow engine across multiple consumers (CLI tools, MCP server, tests, scaffold templates). The implementation successfully centralizes engine initialization logic while maintaining backward compatibility.

Changes:

  • Introduces EngineBuilder with fluent API methods (WithAllDefaults(), WithDefaultHandlers(), WithDefaultTriggers(), etc.) for simplified engine configuration
  • Creates setup/ package to break import cycles between the root workflow package and handlers package using factory function pattern
  • Integrates optional engine support into MCP server via EngineProvider interface and WithEngine() option
  • Refactors all CLI commands and scaffold templates to use the new builder API, reducing code from 107→89 lines in cmd/wfctl/run.go

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
engine_builder.go New fluent builder API with 13 configuration methods and 4 terminal methods for engine construction
engine_builder_test.go Comprehensive test coverage with 17 test cases covering builder patterns, chaining, defaults, and lifecycle
setup/setup.go Factory provider package that breaks import cycles by registering default handlers/triggers via init()
setup/setup_test.go Tests verifying 8 handlers and 5 triggers are registered by default factories
mcp/server.go Adds optional EngineProvider interface and WithEngine() option, conditionally registers run_workflow tool
mcp/server_test.go 6 new tests for engine integration including success, error, missing params, and no-engine scenarios
cmd/wfctl/run.go Refactored from manual 20-line setup to 5-line builder call with WithAllDefaults()
cmd/wfctl/pipeline.go Simplified to use builder with selective components (pipeline handler + plugin only)
cmd/wfctl/templates/*/*.tmpl All 3 scaffold templates updated to use builder API, removing 10+ lines of boilerplate each

@intel352
Copy link
Contributor

@copilot apply changes based on the comments in this thread

make sure tests exist to validate our logic. replace the cli and mcp services with this functionality if you didn't already, then ensure they still compile and can execute correctly.

Co-authored-by: intel352 <77607+intel352@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 27, 2026

@copilot apply changes based on the comments in this thread

make sure tests exist to validate our ...

All review comments addressed in fb1e5a0:

  • Added _ "github.com/GoCodeAlone/workflow/setup" blank import to all 3 scaffold templates
  • Fixed setup/setup.go package doc (removed non-existent function references)
  • Updated EngineBuilder type doc and WithDefaultHandlers/Triggers/AllDefaults to document the setup import requirement

CLI (cmd/wfctl/run.go and pipeline.go) and MCP server were already refactored in the previous commits. All packages compile and tests pass (17 builder tests, 32 MCP tests, 2 setup tests, full wfctl suite).

@intel352 intel352 merged commit ec46634 into main Feb 27, 2026
14 checks passed
@intel352 intel352 deleted the copilot/add-workflow-engine-support branch February 27, 2026 13:35
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.

3 participants