Class: Ace::Compressor::Organisms::CompactCompressor
- Inherits:
-
Object
- Object
- Ace::Compressor::Organisms::CompactCompressor
- Defined in:
- lib/ace/compressor/organisms/compact_compressor.rb
Overview
Orchestrates compact mode with a tiered section ladder. In agent mode the same ladder is used, but eligible narrative sections may be rewritten by AgentCompressor while rule-bearing sections stay deterministic.
Constant Summary collapse
- DENSE_FACT_RE =
/\d|(?:must|must not|never|required|should|shall|cannot|can't|do not|only)\b/i- MIMICRY_RE =
/\b(?:exact output|required format|must match|mimic|verbatim|follow exactly)\b/i- SENSITIVE_TABLE_RE =
/\b(?:must|must not|never|required|only|shall|cannot|do not|policy|constraint)\b/i- TABLE_SEPARATOR_RE =
/\A\|?\s*:?-{3,}:?(?:\s*\|\s*:?-{3,}:?)*\|?\z/- TABLE_ROW_SEPARATOR_ESCAPED_RE =
/\s+\\\|\\\|ROW\\\|\\\|\s+/- EXAMPLE_PAYLOAD_PREFIXES =
["CMD|", "FILES|", "TREE|", "CODE|"].freeze
- PRESERVE_TABLE_MAX_ROWS =
2- SCHEMA_KEY_ROWS_MAX_ROWS =
6- SCHEMA_KEY_ROWS_LIMIT =
2- SUMMARY_ROWS_LIMIT =
1- EXACT_SECTION_PREFIXES =
["RULE|", "CONSTRAINT|", "CMD|", "U|"].freeze
Instance Attribute Summary collapse
-
#ignored_paths ⇒ Object
readonly
Returns the value of attribute ignored_paths.
-
#refused_sources ⇒ Object
readonly
Returns the value of attribute refused_sources.
Instance Method Summary collapse
- #call ⇒ Object
- #compress_sources(sources, source_paths: nil) ⇒ Object
-
#initialize(paths, verbose: false, mode_label: "compact", agent_rewriter: nil) ⇒ CompactCompressor
constructor
A new instance of CompactCompressor.
- #resolve_sources ⇒ Object
Constructor Details
#initialize(paths, verbose: false, mode_label: "compact", agent_rewriter: nil) ⇒ CompactCompressor
Returns a new instance of CompactCompressor.
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/ace/compressor/organisms/compact_compressor.rb', line 26 def initialize(paths, verbose: false, mode_label: "compact", agent_rewriter: nil) @paths = Array(paths) @mode_label = mode_label @resolver = ExactCompressor.new(paths, verbose: verbose, mode_label: mode_label) @parser = Ace::Compressor::Atoms::MarkdownParser.new @transformer = Ace::Compressor::Atoms::CanonicalBlockTransformer @classifier = Ace::Compressor::Atoms::CompactPolicyClassifier.new @agent_rewriter = agent_rewriter @refused_sources = [] @example_registry = {} end |
Instance Attribute Details
#ignored_paths ⇒ Object (readonly)
Returns the value of attribute ignored_paths.
24 25 26 |
# File 'lib/ace/compressor/organisms/compact_compressor.rb', line 24 def ignored_paths @ignored_paths end |
#refused_sources ⇒ Object (readonly)
Returns the value of attribute refused_sources.
24 25 26 |
# File 'lib/ace/compressor/organisms/compact_compressor.rb', line 24 def refused_sources @refused_sources end |
Instance Method Details
#call ⇒ Object
38 39 40 |
# File 'lib/ace/compressor/organisms/compact_compressor.rb', line 38 def call compress_sources(resolve_sources) end |
#compress_sources(sources, source_paths: nil) ⇒ Object
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 |
# File 'lib/ace/compressor/organisms/compact_compressor.rb', line 50 def compress_sources(sources, source_paths: nil) @refused_sources = [] @example_registry = {} lines = [Ace::Compressor::Models::ContextPack.header(@mode_label)] Array(sources).each do |source| source_label = source_label(display_source(source, source_paths)) lines << Ace::Compressor::Models::ContextPack.file_line(source_label) text = File.read(source) raise Ace::Compressor::Error, "Input file is empty. #{@mode_label.capitalize} mode requires content: #{source}" if text.strip.empty? blocks = @parser.call(text) raise Ace::Compressor::Error, "Input file is empty after frontmatter removal. #{@mode_label.capitalize} mode requires content: #{source}" if blocks.empty? policy = @classifier.call(source: source_label, blocks: blocks) action = policy.fetch("action") lines << Ace::Compressor::Models::ContextPack.policy_line(doc_class: policy.fetch("class"), action: action) transformed = @transformer.new(source_label).call(blocks) if @mode_label == "agent" lines.concat agent_records(transformed, policy: policy, source_label: source_label) else lines.concat deterministic_records(transformed, action: action, source_label: source_label, policy_class: policy.fetch("class")) end end lines.join("\n") end |
#resolve_sources ⇒ Object
42 43 44 |
# File 'lib/ace/compressor/organisms/compact_compressor.rb', line 42 def resolve_sources @resolver.resolve_sources end |