@@ -10,6 +10,7 @@ include $(ROOT_MAKEFILE)/.env
1010
1111export
1212export PATH := $(PATH ) :$(shell pwd) /$(UV_INSTALL_DIR )
13+ OLLAMA_MODEL? =gpt-oss:20b
1314
1415$(eval UVEL := $(shell which uv && echo "true" || echo ""))
1516UVE = $(if ${UVEL},'uv',$(UV_INSTALL_DIR ) /uv)
@@ -79,7 +80,57 @@ export_runUpdate:
7980 $(UVE ) lock -U
8081
8182com commit :
82- $(UVE ) run cz commit
83+ echo " " > .commit_msg
84+ @if curl -sf http://ollama:11434; then \
85+ $(MAKE ) message; \
86+ else \
87+ $(UVE ) run cz commit; \
88+ fi
89+ echo " " > .commit_msg
8390
8491recom recommit :
85- $(UVE ) run cz commit --retry
92+ @if curl -sf http://ollama:11434; then \
93+ [ ! -s .commit_msg ] || (echo " Missing commit message!" && exit 1); \
94+ git commit -F .commit_msg; \
95+ else \
96+ $(UVE ) run cz commit; \
97+ fi
98+ echo " " > .commit_msg
99+
100+ PROMPT =Generate a commit message in the Conventional Commits 1.0.0 format based on the following git diff. The commit message must: \n\
101+ - Follow this structure: \n\
102+ 1. Commit type (e.g., feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert) \n\
103+ 2. Optional scope in parentheses (e.g., feat(auth):) \n\
104+ 3. A brief, lowercase description in present tense on the first line \n\
105+ 4. Optional body with detailed explanation (can use uppercase) \n\
106+ 5. Optional footer(s) with breaking changes, issue references (e.g., Closes \# 123), or co-authors (e.g., Co-authored-by: Name) \n\
107+ - Formatting rules: \n\
108+ 1. The first line must be entirely lowercase \n\
109+ 2. Body and footer may use uppercase letters \n\
110+ 3. Follow Conventional Commits 1.0.0 strictly \n\
111+ 4. Return only the commit message as plain text (no extra formatting, no markdown) \n\
112+ 5. Do NOT mention - no breaking changes \n\
113+ 6. Body lines must not be longer than 100 characters \n\
114+ - Example: \n\
115+ feat(auth): add user login API\n\
116+ \n\
117+ Added support for user login via OAuth2. This allows users to authenticate\n\
118+ using their Google account.\n\
119+ \n\
120+ Closes \#42\n\
121+
122+
123+ message :
124+ git diff --staged -- . ' :(exclude)*requirements*.txt' | \
125+ jq -Rs --arg prompt " $( PROMPT) " ' {"stream": false, "model": "$(OLLAMA_MODEL)", "prompt": (" <GIT_DIFF> " + . + " </GIT_DIFF> " + $$prompt)}' | \
126+ curl -s -X POST http://ollama:11434/api/generate \
127+ -H " Content-Type: application/json" \
128+ -d @- | \
129+ jq -r ' select(.done == true) | .response' > .commit_msg
130+ vim .commit_msg
131+ @if ! $(UVE ) run cz check --commit-msg-file .commit_msg; then \
132+ echo " Commit message failed cz check. Aborting." ; \
133+ echo " " > .commit_msg; \
134+ exit 1; \
135+ fi
136+ git commit -F .commit_msg
0 commit comments