@moretocontabilidade/cmsg
v2.0.1
Published
CLI for generating commit messages from staged git changes using the OpenAI API.
Readme
@moretocontabilidade/cmsg
CLI for generating commit messages from staged Git changes using the OpenAI API.
Requirements
- Node.js 18.18 or newer
- Git
- An OpenAI API key (configured via
cmsg --init)
Installation
Install the package:
yarn add -D @moretocontabilidade/cmsgAdd the script to package.json:
{
"scripts": {
"cmsg": "cmsg"
}
}Setup
Run the setup wizard to configure your OpenAI API key:
yarn cmsg --initThe key is stored in ~/.config/cmsg/config with restricted permissions (600) and is reused automatically on every run.
To remove the key:
yarn cmsg --unsetUsage
Run the assistant:
yarn cmsgIf no files are staged, the CLI will ask whether you want to stage all changed files (git add .) before continuing.
You can optionally provide a preferred prefix:
yarn cmsg bug
yarn cmsg chore
yarn cmsg docs
yarn cmsg feature
yarn cmsg improvementShow help:
yarn cmsg --helpCheck the installed version:
yarn cmsg --versionHow it works
- If no staged changes are found, asks whether to run
git add . - Reads staged changes and filters out lock files, build artifacts, and minified files to reduce token usage
- Sends the filtered diff to the OpenAI API (model
gpt-4o-mini) with structured output - Presents one recommended commit message and three alternatives, plus a Try again option
- If Try again is selected, re-runs the request
- Runs
git commit -m "<selected message>" - Optionally runs
git pull --rebaseandgit push
Environment variables
OPENAI_API_KEY
Overrides the key stored by --init. Useful for CI or when you prefer to manage the key yourself.
CMSG_DEBUG
When set to 1, prints the raw API response and token usage instead of the progress spinner.
export CMSG_DEBUG=1Publishing
Before publishing, log in to npm:
npm login --registry https://registry.npmjs.orgCheck what will be included in the package:
yarn pack:checkPublish to npm:
yarn pack:publishNotes
- The tool analyzes only staged changes
- Lock files (
*.lock,package-lock.json, etc.), build artifacts (dist/,build/,.next/, etc.), minified files, and source maps are excluded from the diff automatically - Large per-file diffs are truncated at 300 lines; the total diff is capped at 20,000 characters
- Commit messages are always requested in English
- The CLI is interactive and expects a terminal when prompting for prefix, selection, and sync confirmation
