Class: Aidp::Skills::Wizard::Controller

Inherits:
Object
  • Object
show all
Defined in:
lib/aidp/skills/wizard/controller.rb

Overview

Controller orchestrating the skill creation wizard

Coordinates the wizard flow: template selection, prompting, building, preview, and writing the skill.

Examples:

Creating a new skill

controller = Controller.new(project_dir: "/path/to/project")
controller.run

With options

controller = Controller.new(
  project_dir: "/path/to/project",
  options: { id: "my_skill", dry_run: true }
)
controller.run

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project_dir:, options: {}) ⇒ Controller

Initialize controller

Parameters:

  • project_dir (String)

    Root directory of the project

  • options (Hash) (defaults to: {})

    Wizard options

Options Hash (options:):

  • :id (String)

    Pre-filled skill ID

  • :name (String)

    Pre-filled skill name

  • :dry_run (Boolean)

    Don’t write files

  • :minimal (Boolean)

    Skip optional sections

  • :open_editor (Boolean)

    Open in $EDITOR (future)



38
39
40
41
42
43
44
# File 'lib/aidp/skills/wizard/controller.rb', line 38

def initialize(project_dir:, options: {})
  @project_dir = project_dir
  @options = options
  @template_library = TemplateLibrary.new(project_dir: project_dir)
  @prompter = Prompter.new
  @writer = Writer.new(project_dir: project_dir)
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



27
28
29
# File 'lib/aidp/skills/wizard/controller.rb', line 27

def options
  @options
end

#project_dirObject (readonly)

Returns the value of attribute project_dir.



27
28
29
# File 'lib/aidp/skills/wizard/controller.rb', line 27

def project_dir
  @project_dir
end

#prompterObject (readonly)

Returns the value of attribute prompter.



27
28
29
# File 'lib/aidp/skills/wizard/controller.rb', line 27

def prompter
  @prompter
end

#template_libraryObject (readonly)

Returns the value of attribute template_library.



27
28
29
# File 'lib/aidp/skills/wizard/controller.rb', line 27

def template_library
  @template_library
end

#writerObject (readonly)

Returns the value of attribute writer.



27
28
29
# File 'lib/aidp/skills/wizard/controller.rb', line 27

def writer
  @writer
end

Instance Method Details

#runString?

Run the wizard

Returns:

  • (String, nil)

    Path to created skill file, or nil if cancelled/dry-run



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/aidp/skills/wizard/controller.rb', line 49

def run
  Aidp.log_info("wizard", "Starting skill creation wizard", options: options)

  # Gather user responses
  responses = prompter.gather_responses(template_library, options: options)

  # Build skill from responses
  base_skill = responses.delete(:base_skill)
  builder = Builder.new(base_skill: base_skill)
  skill = builder.build(responses)

  # Generate SKILL.md content
  skill_md_content = builder.to_skill_md(skill)

  # Preview
  show_preview(skill, skill_md_content) unless options[:minimal]

  # Confirm
  unless options[:dry_run] || options[:yes] || confirm_save(skill)
    prompter.prompt.warn("Cancelled")
    return nil
  end

  # Write to disk
  path = writer.write(
    skill,
    content: skill_md_content,
    dry_run: options[:dry_run],
    backup: true
  )

  # Show success message
  show_success(skill, path) unless options[:dry_run]

  path
rescue Interrupt
  prompter.prompt.warn("\nWizard cancelled")
  nil
rescue => e
  Aidp.log_error("wizard", "Wizard failed", error: e.message, backtrace: e.backtrace.first(5))
  prompter.prompt.error("Error: #{e.message}")
  nil
end