rails_code_auditor 0.1.0 → 0.1.1
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 +4 -4
- data/lib/rails_code_auditor/llm_client.rb +18 -20
- data/lib/rails_code_auditor/version.rb +1 -1
- data/lib/rails_code_auditor.rb +8 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 598189dda2fba4a0b37869531aae8cb254a7effbcdff35b5be9638892c79eafb
|
4
|
+
data.tar.gz: d90fc145ba60a605012b332a8c74a2400ba7607f0278387ec74eed58a0211677
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 506c2a77006ff53ac87a5e58e86d322f79323d10f5a0714d1c0a9a75fa3b27ec32082894af8bd314146be709a464cce296558c5b01e3496100fc862fd2f5938e
|
7
|
+
data.tar.gz: 97a84b00a918e79e7a7ec9ab4e5b1c6100b6f1c719267649120b13ce9d4c3279d6b119cc5f91c3da7ced0cb4832309efbe987ed20b13f76fd8f74d9047c93b90
|
@@ -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/,
|
12
|
+
entry[:details].gsub!(/\e\[[\d;]*m/, "") # Remove ANSI color codes
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
17
|
-
|
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(
|
38
|
+
uri = URI(endpoint)
|
38
39
|
body = {
|
39
|
-
model:
|
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
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
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
|
data/lib/rails_code_auditor.rb
CHANGED
@@ -15,11 +15,17 @@ 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
|
+
|
18
23
|
raw_results = Analyzer.run_all
|
19
24
|
results = ReportGenerator.normalize(raw_results)
|
20
25
|
results[:simplecov] = SimpleCovRunner.run
|
21
|
-
scores = if
|
22
|
-
LlmClient.score_with_llm(results
|
26
|
+
scores = if use_llm
|
27
|
+
LlmClient.score_with_llm(results, model: model_arg || "llama3",
|
28
|
+
endpoint: endpoint_arg || "http://localhost:11434/api/generate") || Scorer.score(results)
|
23
29
|
else
|
24
30
|
Scorer.score(results)
|
25
31
|
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.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- sivamanikandan
|
8
8
|
bindir: exe
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-07-
|
10
|
+
date: 2025-07-25 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: brakeman
|