Extending Osmedeus
This guide covers how to extend Osmedeus with custom step types, runners, CLI commands, and utility functions.Architecture Overview
Adding a New Step Type
Step types are implemented as plugins registered in theStepDispatcher.
1. Define the Step Type Constant
Ininternal/core/types.go:
2. Create the Executor
Create a new fileinternal/executor/your_executor.go:
3. Register in Dispatcher
Ininternal/executor/dispatcher.go, add to NewStepDispatcher():
4. Use in Workflows
Adding a New Runner
Runners execute commands in different environments (host, Docker, SSH).1. Define Runner Type
Ininternal/core/types.go:
2. Implement the Runner Interface
Createinternal/runner/your_runner.go:
3. Register in Runner Factory
Ininternal/runner/runner.go:
4. Use in Workflows
Adding a New CLI Command
CLI commands use Cobra.1. Create Command File
Createpkg/cli/mycommand.go:
2. Register in Root Command
Inpkg/cli/root.go:
3. Add Subcommands (Optional)
Adding Utility Functions
Utility functions are executed via the Goja JavaScript VM.1. Define Function Name Constant
Ininternal/functions/constants.go:
2. Implement the Function
Ininternal/functions/util_functions.go (or create a new file):
3. Register in Goja Runtime
Ininternal/functions/goja_runtime.go, add to registerFunctionsOnVM():
4. Use in Workflows
Function Categories
Organize functions by category:| Category | File | Examples |
|---|---|---|
| File Operations | file_functions.go | fileExists, readFile, writeFile |
| String Operations | string_functions.go | trim, split, replace |
| Database | database_functions.go | db_select, db_import_asset |
| HTTP | http_functions.go | httpRequest, http_get |
| Notification | notification_functions.go | notifyTelegram, notifyWebhook |
| Storage | cdn_functions.go | cdnUpload, cdnDownload |
Testing Your Extensions
Unit Tests
Integration Tests
Best Practices
- Error Handling: Always return meaningful errors
- Context Support: Respect context cancellation for long operations
- Logging: Use structured logging with
zap - Template Variables: Support
{{Variable}}syntax in inputs - Documentation: Update usage help and CLAUDE.md
- Tests: Write unit and integration tests
File Reference
| Component | Location |
|---|---|
| Step Types | internal/core/types.go |
| Executors | internal/executor/ |
| Runners | internal/runner/ |
| Functions | internal/functions/ |
| CLI Commands | pkg/cli/ |
| Templates | internal/template/ |