* Generate a conventional commit message for the auto-commit feature. * MarrowScript Feature #2: replaces the hand-rolled string truncation in * the auto-commit block of runAgentLoop. * * @param {string} task - The user's task description * @param {string[]} changedFiles - Files modifie
(task, changedFiles)
| 189 | * @returns {Promise<string>} commit message string |
| 190 | */ |
| 191 | async function generateCommitMessage(task, changedFiles) { |
| 192 | const prompts = _getPrompts(); |
| 193 | const fallback = `smallcode: ${task.slice(0, 50).replace(/[\n\r"'`$\\]/g, ' ').trim()}`; |
| 194 | if (!prompts) return fallback; |
| 195 | try { |
| 196 | const traceId = require('crypto').randomUUID(); |
| 197 | const result = await prompts.callPrompt('commit_message', { |
| 198 | task: task, |
| 199 | changed_files: changedFiles.slice(0, 10).join(', '), |
| 200 | }, { trace_id: traceId }); |
| 201 | const msg = String(result).trim() |
| 202 | .replace(/^["']|["']$/g, '') // strip surrounding quotes |
| 203 | .replace(/\.$/, '') // strip trailing period |
| 204 | .slice(0, 72); |
| 205 | // Validate conventional commit format |
| 206 | if (/^(feat|fix|docs|refactor|test|chore|style|ci|perf|build|revert)(\(.+\))?:/.test(msg)) { |
| 207 | return msg; |
| 208 | } |
| 209 | // Model didn't follow the format — use its output as the description with a generic prefix |
| 210 | return `chore: ${msg.slice(0, 65)}`; |
| 211 | } catch { |
| 212 | return fallback; |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | /** |
| 217 | * Check if a user message is too vague to act on. |
no test coverage detected