Class: Aidp::Skills::Wizard::Writer

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

Overview

Writes skills to the filesystem

Handles creating directories, writing SKILL.md files, and creating backups.

Examples:

Writing a new skill

writer = Writer.new(project_dir: "/path/to/project")
writer.write(skill, content: "...", dry_run: false)

Dry-run mode

writer.write(skill, content: "...", dry_run: true)  # Returns path without writing

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project_dir:) ⇒ Writer

Initialize writer



24
25
26
# File 'lib/aidp/skills/wizard/writer.rb', line 24

def initialize(project_dir:)
  @project_dir = project_dir
end

Instance Attribute Details

#project_dirObject (readonly)

Returns the value of attribute project_dir.



19
20
21
# File 'lib/aidp/skills/wizard/writer.rb', line 19

def project_dir
  @project_dir
end

Instance Method Details

#exists?(skill_id) ⇒ Boolean

Check if a skill already exists



76
77
78
# File 'lib/aidp/skills/wizard/writer.rb', line 76

def exists?(skill_id)
  File.exist?(path_for_skill(skill_id))
end

#path_for_skill(skill_id) ⇒ String

Get the path where a skill would be written



68
69
70
# File 'lib/aidp/skills/wizard/writer.rb', line 68

def path_for_skill(skill_id)
  File.join(project_dir, ".aidp", "skills", skill_id, "SKILL.md")
end

#write(skill, content:, dry_run: false, backup: true) ⇒ String

Write a skill to disk



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/aidp/skills/wizard/writer.rb', line 35

def write(skill, content:, dry_run: false, backup: true)
  skill_path = path_for_skill(skill.id)
  skill_dir = File.dirname(skill_path)

  if dry_run
    Aidp.log_debug("wizard", "Dry-run mode, would write to", path: skill_path)
    return skill_path
  end

  # Create backup if file exists and backup is requested
  create_backup(skill_path) if backup && File.exist?(skill_path)

  # Create directory if it doesn't exist
  FileUtils.mkdir_p(skill_dir) unless Dir.exist?(skill_dir)

  # Write file
  File.write(skill_path, content)

  Aidp.log_info(
    "wizard",
    "Wrote skill",
    skill_id: skill.id,
    path: skill_path,
    size: content.bytesize
  )

  skill_path
end