ai_git 0.0.3 → 0.0.4
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/bin/ai_git +1 -0
- data/lib/ai_git/git.rb +4 -1
- data/lib/ai_git/ollama.rb +58 -56
- data/lib/ai_git/version.rb +3 -1
- data/lib/ai_git.rb +9 -7
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a43b04eaad5bed61c5dbe62df46fb915e83d0481e274c2f440b3be2bd7966660
|
|
4
|
+
data.tar.gz: c74c24c20d94f28a58938ec1f8d0a0d323c15a0522fd6d3596b7f8e51323182d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 03cbbe8cf09690cc3db34f98bf42e39479672ce464d65de18a6a25d901ea9c8d35c318a0efa4eac06abc3d1f07d1848be24506ca4c6146facff7e9dcb18a1e80
|
|
7
|
+
data.tar.gz: 47a3c30cbb3ed60d128db9d68af240b5404096ffc95643766cb873296f8e3f2ccacc5cbc284be4fdc6d984dd1c310ea2ff01873c5442abb86745e1d34be59c19
|
data/bin/ai_git
CHANGED
data/lib/ai_git/git.rb
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "English"
|
|
1
4
|
module AIGit
|
|
2
5
|
module Git
|
|
3
6
|
module_function
|
|
@@ -17,7 +20,7 @@ module AIGit
|
|
|
17
20
|
|
|
18
21
|
def run_command(cmd, args)
|
|
19
22
|
system("#{cmd} #{args} > /dev/null 2>&1")
|
|
20
|
-
raise "Command failed: #{cmd} #{args}" if
|
|
23
|
+
raise "Command failed: #{cmd} #{args}" if $CHILD_STATUS.exitstatus != 0
|
|
21
24
|
end
|
|
22
25
|
end
|
|
23
26
|
end
|
data/lib/ai_git/ollama.rb
CHANGED
|
@@ -1,76 +1,78 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
require
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "net/http"
|
|
4
|
+
require "uri"
|
|
5
|
+
require "json"
|
|
4
6
|
|
|
5
7
|
module AIGit
|
|
6
8
|
module Ollama
|
|
7
9
|
module_function
|
|
8
10
|
|
|
9
11
|
def escape_json(string)
|
|
10
|
-
string.gsub(
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
string.gsub("\\", "\\\\")
|
|
13
|
+
.gsub('"', '\"')
|
|
14
|
+
.gsub("\n", '\\n')
|
|
15
|
+
.gsub("\r", '\\r')
|
|
16
|
+
.gsub("\t", '\\t')
|
|
15
17
|
end
|
|
16
18
|
|
|
17
19
|
def generate_commit_message(diff, model_name)
|
|
18
|
-
raise
|
|
20
|
+
raise "No staged changes to generate commit message for" if diff.to_s.strip.empty?
|
|
19
21
|
|
|
20
22
|
prompt = <<~PROMPT
|
|
21
|
-
|
|
23
|
+
You are an expert Git commit message writer. Output ONLY the commit message — no explanations, no markdown, no backticks, no preamble.
|
|
22
24
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
+
Here are the changes:
|
|
26
|
+
#{diff}
|
|
25
27
|
|
|
26
|
-
|
|
28
|
+
STRICT OUTPUT FORMAT (follow exactly):
|
|
27
29
|
|
|
28
|
-
|
|
30
|
+
<short imperative title, max 72 chars>
|
|
29
31
|
|
|
30
|
-
|
|
32
|
+
<blank line>
|
|
31
33
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
+
## Summary
|
|
35
|
+
<2–4 bullet points covering the most important changes. Each bullet starts with a verb.>
|
|
34
36
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
+
## Why
|
|
38
|
+
<1–3 sentences explaining the motivation or context behind the change. Omit if the reason is obvious.>
|
|
37
39
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
40
|
+
RULES:
|
|
41
|
+
- Title line: short, specific, imperative mood (e.g. "Add JWT login with refresh token support"). Avoid vague titles like "Update stuff" or "Fix bug".
|
|
42
|
+
- Summary bullets: describe WHAT changed, not HOW the code looks. Focus on behaviour and impact.
|
|
43
|
+
- Why section: explain the problem being solved or the goal being achieved. Skip if it adds no value.
|
|
44
|
+
- No filler phrases ("this commit", "this PR", "as per discussion").
|
|
45
|
+
- No line should exceed 72 characters.
|
|
44
46
|
|
|
45
|
-
|
|
47
|
+
EXAMPLES OF GOOD OUTPUT:
|
|
46
48
|
|
|
47
|
-
|
|
49
|
+
Add JWT-based login with refresh token support
|
|
48
50
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
51
|
+
## Summary
|
|
52
|
+
- Implement login endpoint with access and refresh token issuance
|
|
53
|
+
- Add token refresh route with rotation and expiry validation
|
|
54
|
+
- Protect private routes via middleware that verifies access tokens
|
|
55
|
+
- Store refresh tokens using encrypted HTTP-only cookies
|
|
54
56
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
57
|
+
## Why
|
|
58
|
+
Users were being logged out on every page reload. Refresh tokens allow
|
|
59
|
+
sessions to persist securely without requiring re-authentication.
|
|
58
60
|
|
|
59
|
-
|
|
61
|
+
---
|
|
60
62
|
|
|
61
|
-
|
|
63
|
+
Prevent nil crash when user preferences are missing
|
|
62
64
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
65
|
+
## Summary
|
|
66
|
+
- Add nil guard in ReportGenerator#process before accessing preferences
|
|
67
|
+
- Fall back to system defaults when preferences object is absent
|
|
66
68
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
69
|
+
## Why
|
|
70
|
+
Reports were raising NoMethodError in production for users created
|
|
71
|
+
before the preferences feature shipped.
|
|
70
72
|
|
|
71
|
-
|
|
73
|
+
---
|
|
72
74
|
|
|
73
|
-
|
|
75
|
+
Now generate the commit message:
|
|
74
76
|
PROMPT
|
|
75
77
|
|
|
76
78
|
json_body = {
|
|
@@ -81,28 +83,28 @@ module AIGit
|
|
|
81
83
|
temperature: 0.3,
|
|
82
84
|
top_p: 0.9,
|
|
83
85
|
stop: ["\n\n\n", "```", "Here is", "The commit message"],
|
|
84
|
-
num_predict: 400
|
|
86
|
+
num_predict: 400 # Limit output length
|
|
85
87
|
}.to_json
|
|
86
88
|
|
|
87
|
-
uri = URI(
|
|
89
|
+
uri = URI("http://localhost:11434/api/generate")
|
|
88
90
|
request = Net::HTTP::Post.new(uri)
|
|
89
|
-
request[
|
|
91
|
+
request["Content-Type"] = "application/json"
|
|
90
92
|
request.body = json_body
|
|
91
93
|
|
|
92
94
|
response = Net::HTTP.start(uri.host, uri.port, read_timeout: 120) do |http|
|
|
93
95
|
http.request(request)
|
|
94
96
|
end
|
|
95
97
|
|
|
96
|
-
raise
|
|
98
|
+
raise "Failed to connect to Ollama. Is it running?" unless response.is_a?(Net::HTTPSuccess)
|
|
97
99
|
|
|
98
100
|
data = JSON.parse(response.body)
|
|
99
|
-
message = data[
|
|
101
|
+
message = data["response"].to_s.strip
|
|
100
102
|
|
|
101
103
|
# Aggressive cleaning
|
|
102
|
-
message = message.gsub(/^(Here is|The commit message is|```|json|markdown)/i,
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
104
|
+
message = message.gsub(/^(Here is|The commit message is|```|json|markdown)/i, "")
|
|
105
|
+
.gsub(/^>\s*/, "")
|
|
106
|
+
.gsub(/\\n/, "\n")
|
|
107
|
+
.strip
|
|
106
108
|
|
|
107
109
|
# Remove common unwanted prefixes/suffixes
|
|
108
110
|
lines = message.lines.map(&:strip)
|
|
@@ -112,10 +114,10 @@ module AIGit
|
|
|
112
114
|
|
|
113
115
|
# Ensure it has at least a title
|
|
114
116
|
if message.lines.count < 1 || message.strip.empty?
|
|
115
|
-
message = "chore: update code"
|
|
117
|
+
message = "chore: update code" # fallback
|
|
116
118
|
end
|
|
117
119
|
|
|
118
120
|
message
|
|
119
|
-
end
|
|
121
|
+
end
|
|
120
122
|
end
|
|
121
123
|
end
|
data/lib/ai_git/version.rb
CHANGED
data/lib/ai_git.rb
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
require_relative
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "benchmark"
|
|
4
|
+
require_relative "ai_git/version"
|
|
5
|
+
require_relative "ai_git/git"
|
|
6
|
+
require_relative "ai_git/ollama"
|
|
5
7
|
|
|
6
8
|
module AIGit
|
|
7
9
|
module_function
|
|
@@ -10,7 +12,7 @@ module AIGit
|
|
|
10
12
|
model_name = ENV["AI_GIT_MODEL_NAME"] || "phi4:14b"
|
|
11
13
|
|
|
12
14
|
staged = AIGit::Git.staged_files
|
|
13
|
-
abort
|
|
15
|
+
abort "Error: No staged files. Use `git add` first." if staged.to_s.strip.empty?
|
|
14
16
|
|
|
15
17
|
diff = AIGit::Git.diff
|
|
16
18
|
branch = AIGit::Git.current_branch
|
|
@@ -27,10 +29,10 @@ module AIGit
|
|
|
27
29
|
puts "\e[1mCommit Message:\e[0m\n\n#{message}\n"
|
|
28
30
|
|
|
29
31
|
escaped_msg = message.gsub(/[\\"`$]/) { |c| "\\#{c}" }
|
|
30
|
-
AIGit::Git.run_command(
|
|
32
|
+
AIGit::Git.run_command("git", "commit -m \"#{escaped_msg}\"")
|
|
31
33
|
puts "\e[1mGit Commited\e[0m"
|
|
32
34
|
|
|
33
|
-
AIGit::Git.run_command(
|
|
35
|
+
AIGit::Git.run_command("git", "push")
|
|
34
36
|
puts "\e[1mGit Pushed\e[0m"
|
|
35
37
|
end
|
|
36
38
|
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ai_git
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Kaíque Kandy Koga
|
|
@@ -9,7 +9,7 @@ bindir: bin
|
|
|
9
9
|
cert_chain: []
|
|
10
10
|
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
11
|
dependencies: []
|
|
12
|
-
description:
|
|
12
|
+
description: AI‑powered Git commit + push tool using SLMs
|
|
13
13
|
executables:
|
|
14
14
|
- ai_git
|
|
15
15
|
extensions: []
|
|
@@ -40,5 +40,5 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
40
40
|
requirements: []
|
|
41
41
|
rubygems_version: 4.0.9
|
|
42
42
|
specification_version: 4
|
|
43
|
-
summary: AI
|
|
43
|
+
summary: AI‑powered Git commit + push tool using SLMs
|
|
44
44
|
test_files: []
|