Skip to content

Commit d61b3d6

Browse files
committed
fix: wizard now loads and uses custom template from config
- Pass config template path to RunWizard and template editor - Load custom template in wizard step 4 instead of always using default - Only override config template if user actually edits it in wizard - Remove template from isComplete check since it can come from config
1 parent 689dad4 commit d61b3d6

File tree

3 files changed

+32
-10
lines changed

3 files changed

+32
-10
lines changed

cmd/iteratr/build.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ func runBuild(cmd *cobra.Command, args []string) error {
185185
}
186186
defer cleanup()
187187

188-
result, err := wizard.RunWizard(wizardStore)
188+
result, err := wizard.RunWizard(wizardStore, buildFlags.template)
189189
if err != nil {
190190
return fmt.Errorf("wizard failed: %w", err)
191191
}

internal/tui/wizard/template_editor.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,12 @@ type TemplateEditorStep struct {
3636
width int // Available width
3737
height int // Available height
3838
tmpFile string // Path to temp file for editing
39+
edited bool // True if user edited the template via external editor
3940
}
4041

4142
// NewTemplateEditorStep creates a new template editor step.
42-
func NewTemplateEditorStep() *TemplateEditorStep {
43+
// templatePath is the custom template path from config (empty string means use default).
44+
func NewTemplateEditorStep(templatePath string) *TemplateEditorStep {
4345
// Create viewport
4446
vp := viewport.New(
4547
viewport.WithWidth(60),
@@ -50,8 +52,12 @@ func NewTemplateEditorStep() *TemplateEditorStep {
5052
vp.MouseWheelEnabled = true
5153
vp.MouseWheelDelta = 3
5254

53-
// Get default template content
54-
content := template.DefaultTemplate
55+
// Load template content - use custom path if provided, otherwise use default
56+
content, err := template.GetTemplate(templatePath)
57+
if err != nil {
58+
// Fall back to default if custom template can't be loaded
59+
content = template.DefaultTemplate
60+
}
5561

5662
// Set highlighted content
5763
vp.SetContent(highlightTemplate(content))
@@ -124,6 +130,7 @@ func (t *TemplateEditorStep) Update(msg tea.Msg) tea.Cmd {
124130
case TemplateEditedMsg:
125131
// Editor returned with new content
126132
t.content = msg.Content
133+
t.edited = true // Mark as edited so wizard knows to use this content
127134
t.viewport.SetContent(highlightTemplate(t.content))
128135
t.viewport.GotoTop()
129136
// Clean up temp file
@@ -217,6 +224,12 @@ func (t *TemplateEditorStep) Content() string {
217224
return t.content
218225
}
219226

227+
// WasEdited returns true if the user edited the template via external editor.
228+
// Used to determine whether to override config template settings.
229+
func (t *TemplateEditorStep) WasEdited() bool {
230+
return t.edited
231+
}
232+
220233
// TemplateEditedMsg is sent when the external editor returns with new content.
221234
type TemplateEditedMsg struct {
222235
Content string

internal/tui/wizard/wizard.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ type WizardModel struct {
3737

3838
// Session store for session operations
3939
sessionStore *session.Store
40+
// Template path from config (empty = use default)
41+
templatePath string
4042

4143
// Step components
4244
sessionSelectorStep *SessionSelectorStep
@@ -52,13 +54,15 @@ type WizardModel struct {
5254

5355
// RunWizard is the entry point for the build wizard.
5456
// It creates a standalone BubbleTea program, runs it, and returns the result.
57+
// templatePath is the custom template path from config (empty string means use default).
5558
// Returns nil result and error if user cancels or an error occurs.
56-
func RunWizard(sessionStore *session.Store) (*WizardResult, error) {
59+
func RunWizard(sessionStore *session.Store, templatePath string) (*WizardResult, error) {
5760
// Create initial model
5861
m := &WizardModel{
5962
step: 0,
6063
cancelled: false,
6164
sessionStore: sessionStore,
65+
templatePath: templatePath,
6266
}
6367

6468
// Create BubbleTea program
@@ -219,7 +223,10 @@ func (m *WizardModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
219223

220224
case ConfigCompleteMsg:
221225
// Config complete in step 4
222-
m.result.Template = m.templateEditorStep.Content()
226+
// Only set template if user edited it; otherwise let config template be used
227+
if m.templateEditorStep.WasEdited() {
228+
m.result.Template = m.templateEditorStep.Content()
229+
}
223230
m.result.SessionName = m.configStep.SessionName()
224231
m.result.Iterations = m.configStep.Iterations()
225232
return m, tea.Quit
@@ -365,7 +372,10 @@ func (m *WizardModel) goNext() (tea.Model, tea.Cmd) {
365372
case 4:
366373
// Config step - finish wizard
367374
if m.configStep != nil && m.configStep.IsValid() {
368-
m.result.Template = m.templateEditorStep.Content()
375+
// Only set template if user edited it; otherwise let config template be used
376+
if m.templateEditorStep.WasEdited() {
377+
m.result.Template = m.templateEditorStep.Content()
378+
}
369379
m.result.SessionName = m.configStep.SessionName()
370380
m.result.Iterations = m.configStep.Iterations()
371381
return m, tea.Quit
@@ -443,7 +453,7 @@ func (m *WizardModel) initCurrentStep() {
443453
}
444454
case 3:
445455
if m.templateEditorStep == nil {
446-
m.templateEditorStep = NewTemplateEditorStep()
456+
m.templateEditorStep = NewTemplateEditorStep(m.templatePath)
447457
}
448458
case 4:
449459
if m.configStep == nil {
@@ -781,9 +791,8 @@ func (m *WizardModel) isStepValid() bool {
781791

782792
// isComplete checks if all required steps have valid data.
783793
func (m *WizardModel) isComplete() bool {
784-
// TODO: Validate each step
794+
// Template is optional here - can come from config if not edited in wizard
785795
return m.result.SpecPath != "" &&
786796
m.result.Model != "" &&
787-
m.result.Template != "" &&
788797
m.result.SessionName != ""
789798
}

0 commit comments

Comments
 (0)