rails_code_auditor 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 83cd23ea4027538587a1814cbf2a3472bd818fe0cb15bf492a3ab54b565c2e63
4
- data.tar.gz: 40438e254bed8d07966559ac52df8a3063f427167fbc236a8eac0fba6a591c1d
3
+ metadata.gz: 02d182284c325102a56357851f1bf841c265b33d601c7af29726be9c1d3d80e0
4
+ data.tar.gz: 30afb60183c7b4fbc029b0b3341afac7c7a857364906caebe29d4a1e359f6773
5
5
  SHA512:
6
- metadata.gz: e1cdd901ff82b3f2c2d5f0be65175a03b534a6d3a401c34a9c85861401ea2cf416162a1045fe34b2e8cf0ef79a3a220a1c1e9f87b81fff05d06b973735974227
7
- data.tar.gz: 721d41c939a3e00321508a4c36033221e58b6f67a6fd1f0ee9df090e1ae289fafe0b65c94e0f07b7e20c6b3c4bad375463b763f00d440c7a96c29af529e6cde2
6
+ metadata.gz: a5c24bea5bf8a7b816eac7fc88b1d0b38bbb29fe69e0d5a02d9534b96a75b714f15df4ba65fba100c24d112267fee13b25ed13b3eaa096bf59d31ef8f028da72
7
+ data.tar.gz: 97c13bb474926f97522e39c43fb2f9bf8578d163cef77a697f0c43331fe311f314d207cec80d11ee606f88c073d45a0cc211f1b2cd3f1735fae9ba139b2d40a5
@@ -9,12 +9,13 @@ module RailsCodeAuditor
9
9
  tool.dup.tap do |entry|
10
10
  if entry.is_a?(Hash) && entry[:details].is_a?(String)
11
11
  entry[:details] = entry[:details].slice(0, 500) # Trim details to avoid LLM overload
12
- entry[:details].gsub!(/\e\[[\d;]*m/, '') # Remove ANSI color codes
12
+ entry[:details].gsub!(/\e\[[\d;]*m/, "") # Remove ANSI color codes
13
13
  end
14
14
  end
15
15
  end
16
16
  end
17
- def self.score_with_llm(json_results)
17
+
18
+ def self.score_with_llm(json_results, endpoint: "http://localhost:11434/api/generate", model: "llama3")
18
19
  sanitized = sanitize_results(json_results)
19
20
  puts "[*] Scoring with LLM (LLaMA3)..."
20
21
 
@@ -34,9 +35,9 @@ module RailsCodeAuditor
34
35
  #{JSON.pretty_generate(sanitized)}
35
36
  PROMPT
36
37
 
37
- uri = URI("http://localhost:11434/api/generate")
38
+ uri = URI(endpoint)
38
39
  body = {
39
- model: "llama3",
40
+ model: model,
40
41
  prompt: prompt,
41
42
  stream: false
42
43
  }
@@ -48,24 +49,21 @@ module RailsCodeAuditor
48
49
  # Try to extract JSON from any surrounding text
49
50
  json_match = raw_output.match(/\{.*\}/m)
50
51
 
51
- if json_match
52
- parsed_scores = JSON.parse(json_match[0])
53
- scored_results = parsed_scores.transform_values do |score|
54
- remark = case score
55
- when 90..100 then "Excellent"
56
- when 75..89 then "Good"
57
- when 60..74 then "Average"
58
- else "Needs Improvement"
59
- end
60
- { score: score, remark: remark }
61
- end
62
- scored_results
63
- else
64
- raise "Response did not contain valid JSON"
52
+ raise "Response did not contain valid JSON" unless json_match
53
+
54
+ parsed_scores = JSON.parse(json_match[0])
55
+ parsed_scores.transform_values do |score|
56
+ remark = case score
57
+ when 90..100 then "Excellent"
58
+ when 75..89 then "Good"
59
+ when 60..74 then "Average"
60
+ else "Needs Improvement"
61
+ end
62
+ { score: score, remark: remark }
65
63
  end
66
- rescue => e
64
+ rescue StandardError => e
67
65
  puts "[!] LLM scoring failed: #{e.message}"
68
66
  nil
69
67
  end
70
68
  end
71
- end
69
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsCodeAuditor
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.2"
5
5
  end
@@ -15,17 +15,41 @@ module RailsCodeAuditor
15
15
  def self.run(args)
16
16
  puts "[*] Running Rails Code Auditor..."
17
17
 
18
+ # Parse CLI options
19
+ use_llm = args.include?("--use-llm")
20
+ model_arg = args[args.index("--llm-model") + 1] if args.include?("--llm-model")
21
+ endpoint_arg = args[args.index("--llm-endpoint") + 1] if args.include?("--llm-endpoint")
22
+ format_arg = args[args.index("--format") + 1] if args.include?("--format")
23
+ output_arg = args[args.index("--output") + 1] if args.include?("--output")
24
+
18
25
  raw_results = Analyzer.run_all
19
26
  results = ReportGenerator.normalize(raw_results)
20
27
  results[:simplecov] = SimpleCovRunner.run
21
- scores = if args.include?("--use-llm")
22
- LlmClient.score_with_llm(results) || Scorer.score(results)
28
+ scores = if use_llm
29
+ LlmClient.score_with_llm(results, model: model_arg || "llama3",
30
+ endpoint: endpoint_arg || "http://localhost:11434/api/generate") || Scorer.score(results)
23
31
  else
24
32
  Scorer.score(results)
25
33
  end
34
+
35
+ if format_arg == "json"
36
+ json_output = JSON.pretty_generate({ results: results, scores: scores })
37
+ if output_arg
38
+ File.write(output_arg, json_output)
39
+ puts "[✓] JSON report saved to #{output_arg}"
40
+ else
41
+ puts json_output
42
+ end
43
+ return
44
+ end
26
45
  graphs = Grapher.generate(scores)
27
46
  html_pdf_paths = USE_GROVER ? HtmlToPdfConverter.convert_all : []
28
- PdfGenerator.generate(results, scores, graphs, html_pdf_paths)
29
- puts "[✓] Audit complete. PDF report generated."
47
+ pdf_path = PdfGenerator.generate(results, scores, graphs, html_pdf_paths)
48
+ if output_arg
49
+ FileUtils.mv(pdf_path, output_arg)
50
+ puts "[✓] PDF report saved to #{output_arg}"
51
+ else
52
+ puts "[✓] Audit complete. PDF report generated at #{pdf_path}"
53
+ end
30
54
  end
31
55
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_code_auditor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - sivamanikandan
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-07-24 00:00:00.000000000 Z
10
+ date: 2025-08-08 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: brakeman
@@ -247,7 +247,7 @@ licenses:
247
247
  metadata:
248
248
  allowed_push_host: https://rubygems.org
249
249
  homepage_uri: https://github.com/railsfactory-sivamanikandan/rails_code_auditor
250
- source_code_uri: https://github.com/railsfactory-sivamanikandan/rails_code_auditor
250
+ documentation_uri: https://github.com/railsfactory-sivamanikandan/rails_code_auditor/blob/main/README.md
251
251
  changelog_uri: https://github.com/railsfactory-sivamanikandan/rails_code_auditor/CHANGELOG.md
252
252
  rdoc_options: []
253
253
  require_paths: