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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 36409c80888ac303814accb279c6908e55693271fc92b22c2eb151a0539285a4
4
- data.tar.gz: b17d56e53f81da126bdd231d12964b799555231eab76dc2cf7002c3a4d01e368
3
+ metadata.gz: a43b04eaad5bed61c5dbe62df46fb915e83d0481e274c2f440b3be2bd7966660
4
+ data.tar.gz: c74c24c20d94f28a58938ec1f8d0a0d323c15a0522fd6d3596b7f8e51323182d
5
5
  SHA512:
6
- metadata.gz: e760bbd37b63c7ba1cfcb486e084742718033924990b590f03e51fd9c3ec31ece730c287c0f364680fff34962a68a9d4046f66611d2f9b350c8ac520a76f165d
7
- data.tar.gz: e2d581350863a6b9dd6ff67a537b57aa126233f9cbfc921dcd63cd5f64b79cd404befff9e4157940f3ee921a4c47c4f749f37e12ed3d750fdb41f0e5303624c9
6
+ metadata.gz: 03cbbe8cf09690cc3db34f98bf42e39479672ce464d65de18a6a25d901ea9c8d35c318a0efa4eac06abc3d1f07d1848be24506ca4c6146facff7e9dcb18a1e80
7
+ data.tar.gz: 47a3c30cbb3ed60d128db9d68af240b5404096ffc95643766cb873296f8e3f2ccacc5cbc284be4fdc6d984dd1c310ea2ff01873c5442abb86745e1d34be59c19
data/bin/ai_git CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require_relative "../lib/ai_git"
4
5
 
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 $?.exitstatus != 0
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
- require 'net/http'
2
- require 'uri'
3
- require 'json'
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
- .gsub('"', '\"')
12
- .gsub("\n", '\\n')
13
- .gsub("\r", '\\r')
14
- .gsub("\t", '\\t')
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 'No staged changes to generate commit message for' if diff.to_s.strip.empty?
20
+ raise "No staged changes to generate commit message for" if diff.to_s.strip.empty?
19
21
 
20
22
  prompt = <<~PROMPT
21
- You are an expert Git commit message writer. Output ONLY the commit message — no explanations, no markdown, no backticks, no preamble.
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
- Here are the changes:
24
- #{diff}
25
+ Here are the changes:
26
+ #{diff}
25
27
 
26
- STRICT OUTPUT FORMAT (follow exactly):
28
+ STRICT OUTPUT FORMAT (follow exactly):
27
29
 
28
- <short imperative title, max 72 chars>
30
+ <short imperative title, max 72 chars>
29
31
 
30
- <blank line>
32
+ <blank line>
31
33
 
32
- ## Summary
33
- <2–4 bullet points covering the most important changes. Each bullet starts with a verb.>
34
+ ## Summary
35
+ <2–4 bullet points covering the most important changes. Each bullet starts with a verb.>
34
36
 
35
- ## Why
36
- <1–3 sentences explaining the motivation or context behind the change. Omit if the reason is obvious.>
37
+ ## Why
38
+ <1–3 sentences explaining the motivation or context behind the change. Omit if the reason is obvious.>
37
39
 
38
- RULES:
39
- - Title line: short, specific, imperative mood (e.g. "Add JWT login with refresh token support"). Avoid vague titles like "Update stuff" or "Fix bug".
40
- - Summary bullets: describe WHAT changed, not HOW the code looks. Focus on behaviour and impact.
41
- - Why section: explain the problem being solved or the goal being achieved. Skip if it adds no value.
42
- - No filler phrases ("this commit", "this PR", "as per discussion").
43
- - No line should exceed 72 characters.
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
- EXAMPLES OF GOOD OUTPUT:
47
+ EXAMPLES OF GOOD OUTPUT:
46
48
 
47
- Add JWT-based login with refresh token support
49
+ Add JWT-based login with refresh token support
48
50
 
49
- ## Summary
50
- - Implement login endpoint with access and refresh token issuance
51
- - Add token refresh route with rotation and expiry validation
52
- - Protect private routes via middleware that verifies access tokens
53
- - Store refresh tokens using encrypted HTTP-only cookies
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
- ## Why
56
- Users were being logged out on every page reload. Refresh tokens allow
57
- sessions to persist securely without requiring re-authentication.
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
- Prevent nil crash when user preferences are missing
63
+ Prevent nil crash when user preferences are missing
62
64
 
63
- ## Summary
64
- - Add nil guard in ReportGenerator#process before accessing preferences
65
- - Fall back to system defaults when preferences object is absent
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
- ## Why
68
- Reports were raising NoMethodError in production for users created
69
- before the preferences feature shipped.
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
- Now generate the commit message:
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 # Limit output length
86
+ num_predict: 400 # Limit output length
85
87
  }.to_json
86
88
 
87
- uri = URI('http://localhost:11434/api/generate')
89
+ uri = URI("http://localhost:11434/api/generate")
88
90
  request = Net::HTTP::Post.new(uri)
89
- request['Content-Type'] = 'application/json'
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 'Failed to connect to Ollama. Is it running?' unless response.is_a?(Net::HTTPSuccess)
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['response'].to_s.strip
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
- .gsub(/^>\s*/, '')
104
- .gsub(/\\n/, "\n")
105
- .strip
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" # fallback
117
+ message = "chore: update code" # fallback
116
118
  end
117
119
 
118
120
  message
119
- end
121
+ end
120
122
  end
121
123
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module AIGit
2
- VERSION = "0.0.3"
4
+ VERSION = "0.0.4"
3
5
  end
data/lib/ai_git.rb CHANGED
@@ -1,7 +1,9 @@
1
- require 'benchmark'
2
- require_relative 'ai_git/version'
3
- require_relative 'ai_git/git'
4
- require_relative 'ai_git/ollama'
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 'Error: No staged files. Use `git add` first.' if staged.to_s.strip.empty?
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('git', "commit -m \"#{escaped_msg}\"")
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('git', 'push')
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.3
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: Generates intelligent commit messages using Ollama LLMs
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-powered git commit and push tool using Ollama
43
+ summary: AIpowered Git commit + push tool using SLMs
44
44
  test_files: []