Module: Ariadna::Tools::ConfigManager

Defined in:
lib/ariadna/tools/config_manager.rb

Constant Summary collapse

DEFAULTS =
{
  "model_profile" => "balanced",
  "commit_docs" => true,
  "search_gitignored" => false,
  "branching_strategy" => "none",
  "phase_branch_template" => "ariadna/phase-{phase}-{slug}",
  "milestone_branch_template" => "ariadna/{milestone}-{slug}",
  "research" => false,
  "plan_checker" => true,
  "verifier" => true,
  "parallelization" => true,
  "execution_mode" => "vertical",
  "team_execution" => false
}.freeze

Class Method Summary collapse

Class Method Details

.ensure_section(argv, raw: false) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/ariadna/tools/config_manager.rb', line 78

def self.ensure_section(argv, raw: false)
  cwd = Dir.pwd
  config_path = File.join(cwd, ".ariadna_planning", "config.json")
  planning_dir = File.join(cwd, ".ariadna_planning")

  FileUtils.mkdir_p(planning_dir) unless File.directory?(planning_dir)

  if File.exist?(config_path)
    Output.json({ created: false, reason: "already_exists" }, raw: raw, raw_value: "exists")
    return
  end

  defaults = {
    model_profile: "balanced",
    commit_docs: true,
    search_gitignored: false,
    branching_strategy: "none",
    phase_branch_template: "ariadna/phase-{phase}-{slug}",
    milestone_branch_template: "ariadna/{milestone}-{slug}",
    workflow: {
      research: false,
      plan_check: true,
      verifier: true
    },
    parallelization: true,
    execution_mode: "vertical",
    team_execution: false
  }

  File.write(config_path, JSON.pretty_generate(defaults))
  Output.json({ created: true, path: ".ariadna_planning/config.json" }, raw: raw, raw_value: "created")
end

.load_config(cwd = Dir.pwd) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/ariadna/tools/config_manager.rb', line 23

def self.load_config(cwd = Dir.pwd)
  config_path = File.join(cwd, ".ariadna_planning", "config.json")
  return DEFAULTS.dup unless File.exist?(config_path)

  raw = File.read(config_path)
  parsed = JSON.parse(raw)

  get = lambda do |key, nested = nil|
    return parsed[key] if parsed.key?(key)

    if nested && parsed[nested[:section]].is_a?(Hash)
      val = parsed[nested[:section]][nested[:field]]
      return val unless val.nil?
    end
    nil
  end

  parallelization = begin
    val = get.call("parallelization")
    if val.is_a?(Hash) && val.key?("enabled")
      val["enabled"]
    elsif [true, false].include?(val)
      val
    else
      DEFAULTS["parallelization"]
    end
  end

  # nil_or helper: use default only when value is nil (preserves false)
  nil_or = ->(val, default) { val.nil? ? default : val }

  {
    "model_profile" => get.call("model_profile") || DEFAULTS["model_profile"],
    "commit_docs" => nil_or.call(get.call("commit_docs", { section: "planning", field: "commit_docs" }), DEFAULTS["commit_docs"]),
    "search_gitignored" => nil_or.call(get.call("search_gitignored", { section: "planning", field: "search_gitignored" }), DEFAULTS["search_gitignored"]),
    "branching_strategy" => get.call("branching_strategy", { section: "git", field: "branching_strategy" }) || DEFAULTS["branching_strategy"],
    "phase_branch_template" => get.call("phase_branch_template", { section: "git", field: "phase_branch_template" }) || DEFAULTS["phase_branch_template"],
    "milestone_branch_template" => get.call("milestone_branch_template", { section: "git", field: "milestone_branch_template" }) || DEFAULTS["milestone_branch_template"],
    "research" => nil_or.call(get.call("research", { section: "workflow", field: "research" }), DEFAULTS["research"]),
    "plan_checker" => nil_or.call(get.call("plan_checker", { section: "workflow", field: "plan_check" }), DEFAULTS["plan_checker"]),
    "verifier" => nil_or.call(get.call("verifier", { section: "workflow", field: "verifier" }), DEFAULTS["verifier"]),
    "parallelization" => parallelization,
    "execution_mode" => get.call("execution_mode", { section: "execution", field: "mode" }) || DEFAULTS["execution_mode"],
    "team_execution" => begin
      val = get.call("team_execution", { section: "execution", field: "team" })
      case val
      when "auto", true, false then val
      else DEFAULTS["team_execution"]
      end
    end
  }
rescue JSON::ParserError
  DEFAULTS.dup
end

.set(argv, raw: false) ⇒ Object



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/ariadna/tools/config_manager.rb', line 111

def self.set(argv, raw: false)
  key_path = argv[0]
  value = argv[1]
  Output.error("Usage: config-set <key.path> <value>") unless key_path

  cwd = Dir.pwd
  config_path = File.join(cwd, ".ariadna_planning", "config.json")

  config = {}
  if File.exist?(config_path)
    config = JSON.parse(File.read(config_path))
  end

  parsed_value = case value
                 when "true" then true
                 when "false" then false
                 when /\A\d+\z/ then value.to_i
                 else value
                 end

  keys = key_path.split(".")
  current = config
  keys[0..-2].each do |key|
    current[key] = {} unless current[key].is_a?(Hash)
    current = current[key]
  end
  current[keys.last] = parsed_value

  File.write(config_path, JSON.pretty_generate(config))
  Output.json({ updated: true, key: key_path, value: parsed_value }, raw: raw, raw_value: "#{key_path}=#{parsed_value}")
rescue JSON::ParserError => e
  Output.error("Failed to read config.json: #{e.message}")
end