Add extensions/workflows support for 3rd-party workflow discovery and execution
Opened by swampadmin · 11/13/2024
Summary
Add extensions/workflows/ directory support, similar to how extensions/models/ works for user-defined models. Extension workflows from 3rd-party sources should be dynamically discoverable via workflow search, executable via workflow run, and create proper .swamp/ folder structure for runs.
Motivation
Extension models already live in extensions/models/ and are dynamically loaded at CLI startup. There is no equivalent for workflows. Users installing extensions from 3rd-party sources need their workflow YAML files to also be discoverable and executable without manually copying them into .swamp/workflows/.
The extension manifest (extension_manifest.ts) already has a workflows: string[] field, but there's no runtime loading mechanism for extension workflows.
Design: Composite Repository Pattern
New Components
ExtensionWorkflowRepository— Read-only repository that discovers YAML workflow files fromextensions/workflows/(or configured directory)CompositeWorkflowRepository— Wraps the existingYamlWorkflowRepository(primary/mutable) +ExtensionWorkflowRepository(secondary/read-only), implementing theWorkflowRepositoryinterface transparently
Configuration
workflowsDirfield in.swamp.yaml(mirrorsmodelsDir)SWAMP_WORKFLOWS_DIRenvironment variable override- Default:
"extensions/workflows" - Priority: env var >
.swamp.yaml> default
Behavior
- Search:
workflow searchincludes extension workflows alongside.swamp/workflows - Execution:
workflow runworks on extension workflows, creating runs in.swamp/workflow-runs/ - Read-only: Extension workflows cannot be deleted or saved via CLI commands
- Name conflicts:
.swamp/workflows/(primary) always takes precedence over extension workflows - Backwards compatible: When directory doesn't exist, behaves identically to current behavior
Implementation Plan
Files to Create
src/infrastructure/persistence/extension_workflow_repository.ts— Read-only YAML workflow repo for extensions dirsrc/infrastructure/persistence/extension_workflow_repository_test.ts— Testssrc/infrastructure/persistence/composite_workflow_repository.ts— Composite wrapping primary + extensionsrc/infrastructure/persistence/composite_workflow_repository_test.ts— Tests
Files to Modify
src/infrastructure/persistence/repo_marker_repository.ts— AddworkflowsDir?: stringtoRepoMarkerDatasrc/cli/mod.ts— AddresolveWorkflowsDir()mirroringresolveModelsDir()src/cli/mod_test.ts— Add tests forresolveWorkflowsDir()src/infrastructure/persistence/repository_factory.ts— AddworkflowsDirto config, widenworkflowRepotype toWorkflowRepository, create composite increateRepositoryContext()src/cli/repo_context.ts— Resolve and passworkflowsDirto factorysrc/cli/completion_types.ts— UpdateWorkflowNameTypeto include extension workflowssrc/cli/commands/workflow_search.ts— Change type annotations fromYamlWorkflowRepositorytoWorkflowRepositorysrc/cli/commands/workflow_delete.ts— Guard against deleting extension-only workflowssrc/cli/commands/workflow_edit.ts— Handle editing extension workflows
Key Design Decisions
- No bundling needed: Unlike extension models (TypeScript), extension workflows are plain YAML — no compilation step
- No startup loading: Unlike models that register into a global registry at startup, workflows are loaded on-demand through the repository pattern
- Interface widening:
RepositoryContext.workflowRepochanges from concreteYamlWorkflowRepositorytoWorkflowRepositoryinterface (safe change, all call sites use interface methods) - No changes to execution service:
WorkflowExecutionServicealready depends on theWorkflowRepositoryinterface, so the composite is transparent
Verification
deno check— Type checkingdeno lint— Lintingdeno fmt— Formattingdeno run test— All tests pass- Manual: Create
extensions/workflows/with a workflow YAML, verify search finds it and run executes it
Closed
No activity in this phase yet.
Sign in to post a ripple.