Objective
Reduce 90% boilerplate in script loading by implementing a registry-based loader pattern, reducing ~400 lines of repetitive code.
Context
Part of issue #4640 - Priority 5 (Quick Win)
pkg/workflow/scripts.go contains ~600 lines of boilerplate for 26 embedded scripts. Each script follows identical lazy-loading pattern with //go:embed, sync.Once, and bundling fallback logic.
Approach
-
Create pkg/workflow/script_registry.go:
- Define
ScriptLoader struct with: source, bundled, once, bundler function
- Implement
ScriptRegistry with registration and retrieval methods
- Provide lazy bundling with fallback on error
-
Simplify pkg/workflow/scripts.go:
- Keep 26
//go:embed directives (unavoidable)
- Replace 78 variable declarations with registry initialization
- Replace 26 getter functions with simple one-line registry lookups
- Use
init() function for registration
-
Pattern transformation:
- Before: 4 declarations per script (source var, cached var, sync.Once, getter func)
- After: 1 embed declaration + 1 registration line + 1 getter line
Files to Modify
- Create:
pkg/workflow/script_registry.go (new registry pattern)
- Update:
pkg/workflow/scripts.go (use registry for all 26 scripts)
Acceptance Criteria
AI generated by Plan Command for #4640
Objective
Reduce 90% boilerplate in script loading by implementing a registry-based loader pattern, reducing ~400 lines of repetitive code.
Context
Part of issue #4640 - Priority 5 (Quick Win)
pkg/workflow/scripts.gocontains ~600 lines of boilerplate for 26 embedded scripts. Each script follows identical lazy-loading pattern with//go:embed,sync.Once, and bundling fallback logic.Approach
Create
pkg/workflow/script_registry.go:ScriptLoaderstruct with: source, bundled, once, bundler functionScriptRegistrywith registration and retrieval methodsSimplify
pkg/workflow/scripts.go://go:embeddirectives (unavoidable)init()function for registrationPattern transformation:
Files to Modify
pkg/workflow/script_registry.go(new registry pattern)pkg/workflow/scripts.go(use registry for all 26 scripts)Acceptance Criteria
ScriptRegistryimplementation created with lazy loadingmake test)make build)Related to [refactor] 🔧 Semantic Function Clustering Analysis - November 2025 #4640