Module: Ace::Bundle

Defined in:
lib/ace/bundle.rb,
lib/ace/bundle.rb,
lib/ace/bundle/cli.rb,
lib/ace/bundle/version.rb,
lib/ace/bundle/cli/commands/load.rb,
lib/ace/bundle/atoms/line_counter.rb,
lib/ace/bundle/models/bundle_data.rb,
lib/ace/bundle/atoms/typo_detector.rb,
lib/ace/bundle/atoms/boundary_finder.rb,
lib/ace/bundle/atoms/content_checker.rb,
lib/ace/bundle/atoms/preset_validator.rb,
lib/ace/bundle/atoms/bundle_normalizer.rb,
lib/ace/bundle/atoms/section_validator.rb,
lib/ace/bundle/molecules/bundle_merger.rb,
lib/ace/bundle/organisms/bundle_loader.rb,
lib/ace/bundle/molecules/bundle_chunker.rb,
lib/ace/bundle/molecules/preset_manager.rb,
lib/ace/bundle/organisms/pr_bundle_loader.rb,
lib/ace/bundle/atoms/preset_list_formatter.rb,
lib/ace/bundle/molecules/section_formatter.rb,
lib/ace/bundle/molecules/section_processor.rb,
lib/ace/bundle/molecules/bundle_file_writer.rb,
lib/ace/bundle/molecules/section_compressor.rb

Defined Under Namespace

Modules: Atoms, CLI, Models, Molecules, Organisms Classes: Error, PresetLoadError, SectionValidationError

Constant Summary collapse

VERSION =
"0.44.1"

Class Method Summary collapse

Class Method Details

.auto_format_threshold ⇒ Integer

Line count threshold for auto-format output mode When no explicit --output mode is specified:

- Content below this threshold: displayed inline (stdout)
- Content at or above this threshold: saved to cache file


175
176
177
178
179
180
181
182
183
# File 'lib/ace/bundle.rb', line 175

def auto_format_threshold
  threshold = config["auto_format_threshold"]
  # Ensure valid integer within reasonable bounds (10-10000 lines)
  # - Below 10: too aggressive, would cache almost everything
  # - Above 10000: defeats the purpose of auto-format
  return 500 unless threshold.is_a?(Integer) && threshold.between?(10, 10_000)

  threshold
end

.cache_dir ⇒ String

Cache directory for bundle output files



160
161
162
# File 'lib/ace/bundle.rb', line 160

def cache_dir
  config["cache_dir"] || ".ace-local/bundle"
end

.compressor_config ⇒ Hash

Compressor configuration section from global/project config



187
188
189
# File 'lib/ace/bundle.rb', line 187

def compressor_config
  config["compressor"] || {}
end

.compressor_mode ⇒ String

Default compressor mode from config



199
200
201
# File 'lib/ace/bundle.rb', line 199

def compressor_mode
  compressor_config["mode"] || "exact"
end

.compressor_source_scope ⇒ String

Default compressor source scope from config



193
194
195
# File 'lib/ace/bundle.rb', line 193

def compressor_source_scope
  compressor_config["source_scope"] || "off"
end

.config ⇒ Hash

Get configuration for ace-bundle Follows ADR-022: Configuration Default and Override Pattern Uses Ace::Support::Config.create() for configuration cascade resolution Thread-safe: uses mutex for initialization

Examples:

Get current configuration

config = Ace::Bundle.config
puts config["cache_dir"]  # => ".ace-local/bundle"


137
138
139
140
141
142
143
144
145
# File 'lib/ace/bundle.rb', line 137

def config
  # Fast path: return cached config if already initialized
  return @config if defined?(@config) && @config

  # Thread-safe initialization
  @config_mutex.synchronize do
    @config ||= load_config
  end
end

.inspect_config(inputs, options = {}) ⇒ Models::BundleData

Inspect configuration of presets/files without loading files or executing commands



58
59
60
61
# File 'lib/ace/bundle.rb', line 58

def inspect_config(inputs, options = {})
  loader = Organisms::BundleLoader.new(options)
  loader.inspect_config(inputs)
end

.list_presets ⇒ Array<Hash>

List available presets



65
66
67
68
# File 'lib/ace/bundle.rb', line 65

def list_presets
  manager = Molecules::PresetManager.new
  manager.list_presets
end

.load_auto(input, options = {}) ⇒ Models::BundleData

Load with auto-detection



83
84
85
86
# File 'lib/ace/bundle.rb', line 83

def load_auto(input, options = {})
  loader = Organisms::BundleLoader.new(options)
  loader.load_auto(input)
end

.load_file(path, options = {}) ⇒ Models::BundleData

Load bundle from file



74
75
76
77
# File 'lib/ace/bundle.rb', line 74

def load_file(path, options = {})
  loader = Organisms::BundleLoader.new(options)
  loader.load_file(path)
end

.load_multiple(inputs, options = {}) ⇒ Models::BundleData

Load multiple inputs and merge them



92
93
94
95
# File 'lib/ace/bundle.rb', line 92

def load_multiple(inputs, options = {})
  loader = Organisms::BundleLoader.new(options)
  loader.load_multiple(inputs)
end

.load_multiple_inputs(preset_names, file_paths, options = {}) ⇒ Models::BundleData

Load multiple inputs (presets and files) and merge them



102
103
104
105
# File 'lib/ace/bundle.rb', line 102

def load_multiple_inputs(preset_names, file_paths, options = {})
  loader = Organisms::BundleLoader.new(options)
  loader.load_multiple_inputs(preset_names, file_paths, options)
end

.load_multiple_presets(preset_names, options = {}) ⇒ Models::BundleData

Load multiple presets and merge them



49
50
51
52
# File 'lib/ace/bundle.rb', line 49

def load_multiple_presets(preset_names, options = {})
  loader = Organisms::BundleLoader.new(options)
  loader.load_multiple_presets(preset_names)
end

.load_preset(preset_name, options = {}) ⇒ Models::BundleData

Load bundle using preset



40
41
42
43
# File 'lib/ace/bundle.rb', line 40

def load_preset(preset_name, options = {})
  loader = Organisms::BundleLoader.new(options)
  loader.load_preset(preset_name)
end

.max_lines ⇒ Integer

Maximum lines per chunk before splitting output into multiple files



166
167
168
# File 'lib/ace/bundle.rb', line 166

def max_lines
  config["max_lines"] || 2_000
end

.reset_config! ⇒ Object

Reset configuration cache (mainly for testing) Thread-safe: uses mutex to prevent race conditions



149
150
151
152
153
# File 'lib/ace/bundle.rb', line 149

def reset_config!
  @config_mutex.synchronize do
    @config = nil
  end
end

.write_output(bundle, output_path, options = {}) ⇒ Hash

Write bundle output to file with optional chunking



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/ace/bundle.rb', line 112

def write_output(bundle, output_path, options = {})
  writer = Molecules::BundleFileWriter.new(
    cache_dir: cache_dir,
    max_lines: max_lines
  )
  result = writer.write_with_chunking(bundle, output_path, options)

  # Write compression metadata sidecar for downstream tools (e.g., ace-compressor)
  stats = bundle.respond_to?(:metadata) && bundle.&.dig(:compression_stats)
  if stats && result[:success]
    require "json"
    File.write("#{output_path}.meta.json", JSON.generate(stats))
  end

  result
end