git-commit-msg-ai 1.0.0__py3-none-any.whl → 1.2.0__py3-none-any.whl

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.
File without changes
@@ -0,0 +1,32 @@
1
+ import textwrap
2
+ from typing import Final, cast
3
+
4
+ import anthropic
5
+
6
+ SYSTEM_PROMPT: Final[str] = textwrap.dedent("""\
7
+ You are a Git commit message generator. Output only the commit message, nothing else. Follow the Conventional Commits specification:
8
+ - First line: <type>(<optional scope>)<!>: <short subject> (50 chars max); append ! before the colon if the commit introduces a breaking change
9
+ - Blank line
10
+ - Bullet-point body explaining WHY the changes were made, not what
11
+ - If there is a breaking change, add a blank line after the body followed by "BREAKING CHANGE: <description of what breaks and why>
12
+ Types: feat, fix, docs, style, refactor, test, chore""")
13
+
14
+ MODEL: Final[str] = 'claude-haiku-4-5-20251001'
15
+ MAX_TOKENS: Final[int] = 1024
16
+
17
+
18
+ def generate_commit_message(diff: str) -> str:
19
+ anthropic_client = anthropic.Anthropic()
20
+
21
+ anthropic_api_response = anthropic_client.messages.create(
22
+ model=MODEL,
23
+ max_tokens=MAX_TOKENS,
24
+ system=SYSTEM_PROMPT,
25
+ messages=[{'role': 'user', 'content': diff}],
26
+ )
27
+
28
+ anthropic_api_response_message = anthropic_api_response.content[0]
29
+ commit_message = cast(anthropic.types.TextBlock, anthropic_api_response_message).text.strip()
30
+
31
+ return commit_message
32
+
@@ -0,0 +1,22 @@
1
+ from git_commit_msg_ai import ai_client, editor, git_ops
2
+
3
+
4
+ def main() -> None:
5
+ diff = git_ops.get_staged_diff()
6
+ commit_message = ai_client.generate_commit_message(diff)
7
+ print(commit_message)
8
+
9
+ print()
10
+ user_selection = input('[a]ccept / [e]dit / [r]eject: ').strip().lower()
11
+
12
+ if user_selection == 'a':
13
+ git_ops.commit(commit_message)
14
+ elif user_selection == 'e':
15
+ updated_commit_message = editor.open_in_editor(commit_message)
16
+ git_ops.commit(updated_commit_message)
17
+ elif user_selection == 'r':
18
+ print('User rejected the generated commit message. No commit made.')
19
+
20
+
21
+ if __name__ == '__main__':
22
+ main()
@@ -0,0 +1,19 @@
1
+ import os
2
+ import subprocess
3
+ import tempfile
4
+
5
+
6
+ def open_in_editor(initial_text: str) -> str:
7
+ with tempfile.NamedTemporaryFile(suffix='.txt', mode='w', delete=False) as temp_file:
8
+ temp_file.write(initial_text)
9
+ temp_file_path = temp_file.name
10
+
11
+ editor_command = os.environ.get('EDITOR', 'notepad')
12
+ subprocess.run([editor_command, temp_file_path])
13
+
14
+ with open(temp_file_path) as temp_file:
15
+ edited_text = temp_file.read().strip()
16
+
17
+ os.unlink(temp_file_path)
18
+
19
+ return edited_text
@@ -0,0 +1,12 @@
1
+ import subprocess
2
+
3
+
4
+ def get_staged_diff() -> str:
5
+ staged_diff = subprocess.check_output(['git', 'diff', '--cached']).decode()
6
+
7
+ return staged_diff
8
+
9
+
10
+ def commit(message: str) -> None:
11
+ subprocess.run(['git', 'commit', '-m', message])
12
+
@@ -1,11 +1,14 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: git-commit-msg-ai
3
- Version: 1.0.0
3
+ Version: 1.2.0
4
4
  Summary: AI-powered git commit message generator following Conventional Commits
5
- License: MIT
5
+ License-Expression: MIT
6
6
  Requires-Python: >=3.9
7
7
  Description-Content-Type: text/markdown
8
8
  Requires-Dist: anthropic
9
+ Provides-Extra: dev
10
+ Requires-Dist: mypy; extra == "dev"
11
+ Requires-Dist: ruff; extra == "dev"
9
12
 
10
13
  # git-commit-msg-ai
11
14
 
@@ -0,0 +1,10 @@
1
+ git_commit_msg_ai/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ git_commit_msg_ai/ai_client.py,sha256=uSqGxQihITI-4OcZ7jcZnsm7SoZfSJCPIAo5MPENqtM,1262
3
+ git_commit_msg_ai/cli.py,sha256=hiSvdBXYgNb9NuWSzWpTe6F3WqyiWLfauL3vTYHoh2c,662
4
+ git_commit_msg_ai/editor.py,sha256=gNhHrDlMNl650tunwKwhS4i2IWoKMEbwMLY3NyGrim0,518
5
+ git_commit_msg_ai/git_ops.py,sha256=ebTvWg1mUnXrEpup0XZaQ1jMv_JeQtFu-CpUuldjhBg,244
6
+ git_commit_msg_ai-1.2.0.dist-info/METADATA,sha256=gLF-4BqEjBahtHkDNHWHmQ1YsGMqdHLDa4X70uGjk1w,1926
7
+ git_commit_msg_ai-1.2.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
8
+ git_commit_msg_ai-1.2.0.dist-info/entry_points.txt,sha256=KTu6wUhl0p3nf27k8L4vpSH_hpeRQpwzMPSmKv7K5Cs,65
9
+ git_commit_msg_ai-1.2.0.dist-info/top_level.txt,sha256=XYQC2BXvrcREGKEG7sm9nbwO7ifqcUSVgU7SW8BTURs,18
10
+ git_commit_msg_ai-1.2.0.dist-info/RECORD,,
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ git-commit-msg-ai = git_commit_msg_ai.cli:main
@@ -0,0 +1 @@
1
+ git_commit_msg_ai
commit_msg.py DELETED
@@ -1,50 +0,0 @@
1
- import subprocess
2
- import os
3
- import tempfile
4
- from typing import cast
5
- import anthropic
6
-
7
-
8
- def main():
9
- diff = subprocess.check_output(['git', 'diff', '--cached']).decode()
10
-
11
- client = anthropic.Anthropic()
12
- response = client.messages.create(
13
- model='claude-haiku-4-5-20251001',
14
- max_tokens=1024,
15
- system=(
16
- 'You are a Git commit message generator. Output only the commit message, nothing else. '
17
- 'Follow the Conventional Commits specification:\n'
18
- '- First line: <type>(<optional scope>)<!>: <short subject> (50 chars max); '
19
- 'append ! before the colon if the commit introduces a breaking change\n'
20
- '- Blank line\n'
21
- '- Bullet-point body explaining WHY the changes were made, not what\n'
22
- '- If there is a breaking change, add a blank line after the body followed by '
23
- '"BREAKING CHANGE: <description of what breaks and why>\n'
24
- 'Types: feat, fix, docs, style, refactor, test, chore'
25
- ),
26
- messages=[{'role': 'user', 'content': diff}],
27
- )
28
-
29
- msg = cast(anthropic.types.TextBlock, response.content[0]).text.strip()
30
- print(msg)
31
-
32
- choice = input('\n[a]ccept / [e]dit / [r]eject: ').strip().lower()
33
-
34
- if choice == 'a':
35
- subprocess.run(['git', 'commit', '-m', msg])
36
- elif choice == 'e':
37
- with tempfile.NamedTemporaryFile(suffix='.txt', mode='w', delete=False) as f:
38
- f.write(msg)
39
- tmp = f.name
40
- subprocess.run([os.environ.get('EDITOR', 'notepad'), tmp])
41
- with open(tmp) as f:
42
- msg = f.read().strip()
43
- os.unlink(tmp)
44
- subprocess.run(['git', 'commit', '-m', msg])
45
- elif choice == 'r':
46
- print('User rejected the generated commit message. No commit made.')
47
-
48
-
49
- if __name__ == '__main__':
50
- main()
@@ -1,6 +0,0 @@
1
- commit_msg.py,sha256=8jfalkufA0BxVHJzEegY7nCUA9b0b7HlSp5dXCm0XGw,1832
2
- git_commit_msg_ai-1.0.0.dist-info/METADATA,sha256=ckC9Sqq6jeUrCyl5BW8Z7ksJOyIbOVyPeQdtm8DfavA,1820
3
- git_commit_msg_ai-1.0.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
4
- git_commit_msg_ai-1.0.0.dist-info/entry_points.txt,sha256=6c2u6AJ08tD5_ZHIm3kLOXg9NdcRgUcdqmf8sN9EGIE,54
5
- git_commit_msg_ai-1.0.0.dist-info/top_level.txt,sha256=ZybdMozy1k619MPQuC0axGNbHbu97uYGjoV3B-o7sb4,11
6
- git_commit_msg_ai-1.0.0.dist-info/RECORD,,
@@ -1,2 +0,0 @@
1
- [console_scripts]
2
- git-commit-msg-ai = commit_msg:main
@@ -1 +0,0 @@
1
- commit_msg