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.43.5'

Class Method Summary collapse

Class Method Details

.auto_format_thresholdInteger

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

Returns:

  • (Integer)

    Auto-format threshold in lines (default: 500, range: 10-10000)



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_dirString

Cache directory for bundle output files

Returns:

  • (String)

    Cache directory path (default: “.ace-local/bundle”)



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

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

.compressor_configHash

Compressor configuration section from global/project config

Returns:

  • (Hash)

    compressor config (default: {})



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

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

.compressor_modeString

Default compressor mode from config

Returns:

  • (String)

    compressor mode (default: “exact”)



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

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

.compressor_source_scopeString

Default compressor source scope from config

Returns:

  • (String)

    source scope (default: “off”)



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

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

.configHash

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"

Returns:

  • (Hash)

    merged configuration hash



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

Parameters:

  • inputs (Array<String>)

    Names of presets or paths to files to inspect

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

    Additional options

Returns:



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_presetsArray<Hash>

List available presets

Returns:

  • (Array<Hash>)

    List of 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

Parameters:

  • input (String)

    File path, inline YAML, or preset name

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

    Additional options

Returns:



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

Parameters:

  • path (String)

    Path to bundle file

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

    Additional options

Returns:



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

Parameters:

  • inputs (Array<String>)

    Array of inputs to load

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

    Additional options

Returns:



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

Parameters:

  • preset_names (Array<String>)

    Names of presets to load

  • file_paths (Array<String>)

    Paths to configuration files

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

    Additional options

Returns:



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

Parameters:

  • preset_names (Array<String>)

    Names of presets to load

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

    Additional options

Returns:



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

Parameters:

  • preset_name (String)

    Name of the preset to load

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

    Additional options

Returns:



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_linesInteger

Maximum lines per chunk before splitting output into multiple files

Returns:

  • (Integer)

    Max lines per chunk (default: 2000)



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

Parameters:

  • bundle (Models::BundleData)

    Bundle to write

  • output_path (String)

    Output file path

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

    Additional options

Returns:

  • (Hash)

    Write result with success status



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