Class: Zwischen::Reporter::Terminal

Inherits:
Object
  • Object
show all
Defined in:
lib/zwischen/reporter/terminal.rb

Constant Summary collapse

SEVERITY_COLORS =
{
  "critical" => :red,
  "high" => :red,
  "medium" => :yellow,
  "low" => :blue,
  "info" => :cyan
}.freeze
SEVERITY_BADGES =
{
  "critical" => "🔴 CRITICAL",
  "high" => "🔴 HIGH",
  "medium" => "🟡 MEDIUM",
  "low" => "🔵 LOW",
  "info" => "ℹ️  INFO"
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(aggregated_results, ai_enabled: false, config: nil) ⇒ Terminal

Returns a new instance of Terminal.



33
34
35
36
37
# File 'lib/zwischen/reporter/terminal.rb', line 33

def initialize(aggregated_results, ai_enabled: false, config: nil)
  @results = aggregated_results
  @ai_enabled = ai_enabled
  @config = config
end

Class Method Details

.report(aggregated_results, config: nil, ai_enabled: false) ⇒ Object



25
26
27
# File 'lib/zwischen/reporter/terminal.rb', line 25

def self.report(aggregated_results, config: nil, ai_enabled: false)
  new(aggregated_results, ai_enabled: ai_enabled, config: config).report
end

.report_compact(aggregated_results, config:, ai_enabled: false) ⇒ Object



29
30
31
# File 'lib/zwischen/reporter/terminal.rb', line 29

def self.report_compact(aggregated_results, config:, ai_enabled: false)
  new(aggregated_results, ai_enabled: ai_enabled, config: config).report_compact
end

Instance Method Details

#display_path(path) ⇒ Object

Show paths relative to the working directory when they live under it. Scanners may emit symlink-resolved absolute paths (/tmp vs /private/tmp on macOS), so compare against the resolved cwd too.



42
43
44
45
46
47
48
# File 'lib/zwischen/reporter/terminal.rb', line 42

def display_path(path)
  expanded = File.expand_path(path.to_s)
  [Dir.pwd, (File.realpath(Dir.pwd) rescue Dir.pwd)].uniq.each do |root|
    return expanded.delete_prefix("#{root}/") if expanded.start_with?("#{root}/")
  end
  path.to_s
end

#reportObject



50
51
52
53
54
# File 'lib/zwischen/reporter/terminal.rb', line 50

def report
  print_summary
  print_findings
  exit_code
end

#report_compactObject



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/zwischen/reporter/terminal.rb', line 56

def report_compact
  blocking_severity = @config&.blocking_severity || "high"
  findings = @results[:findings]

  # Filter to only blocking findings
  blocking_findings = findings.select { |f| should_block?(f, blocking_severity) }

  # If no blocking findings, exit silently (exit code 0)
  return 0 if blocking_findings.empty?

  # Show compact output for blocking findings
  puts "🛡️  Zwischen: #{blocking_findings.length} issue#{blocking_findings.length == 1 ? '' : 's'} found\n\n"

  blocking_findings.each do |finding|
    severity_color = SEVERITY_COLORS[finding.severity] || :white
    severity_label = finding.severity.upcase

    puts "  #{severity_label}".colorize(severity_color) + "  #{display_path(finding.file)}:#{finding.line || '?'}"
    puts "            #{finding.message}"

    # Show fix suggestion if available
    if @ai_enabled && finding.raw_data["ai_fix_suggestion"]
      puts "#{finding.raw_data['ai_fix_suggestion']}"
    end

    puts ""
  end

  puts "Push blocked. Fix issues above or:"
  puts "  • Run 'zwischen scan' for full report"
  puts "  • Run 'git push --no-verify' to skip (not recommended)"

  1 # Exit code 1 = push blocked
end