Technical guide and conventions for AI agents and developers working on this extension.
commit-message is a lightweight VS Code / VSCodium extension that automatically generates Conventional Commits messages using the OpenRouter API based on your current Git diff.
- Simplicity and Speed: Fast startup, zero heavy runtime dependencies, bundled into a single file with
esbuild. - Cost Efficiency: Prioritizes and highlights free models (
:free) available on OpenRouter (defaulting toauto:freewith automatic fallback when a model is disabled or changes to paid). - Standard Commits: Enforces the Conventional Commits specification in English without noise or markdown codeblock wrappers.
- Native SCM Integration: Places buttons directly into the Source Control title bar.
.
├── .vscode/
│ ├── launch.json # Debug configuration for Extension Development Host (F5)
│ ├── settings.json # Workspace editor settings
│ └── tasks.json # Background build tasks (esbuild watch)
├── src/
│ ├── extension.ts # Extension entry point (activate/deactivate, commands registration)
│ ├── git.ts # VS Code Git extension integration (repo detection, diff extraction)
│ ├── openrouter.ts # OpenRouter API client, model listing and free model filters
│ ├── prompt.ts # Conventional Commits prompt builder and message sanitization
│ ├── secrets.ts # Secure credential storage via vscode.SecretStorage
│ ├── telemetry.ts # Anonymous usage analytics via self-hosted Umami instance
│ └── types.ts # TypeScript interfaces for OpenRouter and Git API
├── .vscodeignore # Packaging exclusion list
├── package.json # Extension manifest (commands, configuration, menus, dependencies)
├── tsconfig.json # TypeScript compiler options
└── README.md # User-facing documentation
- Trigger: User clicks the sparkle
$(sparkle)icon on the SCM input box or runscommit-message.generate. - Git API: Extension queries
vscode.gitto identify the active repository and checks:- Staged changes (
repo.diff(true)) - If empty, falls back to unstaged working tree changes (
repo.diff(false)) if enabled in settings.
- Staged changes (
- API Key & Model:
- Retrieves OpenRouter API Key from
context.secrets.get('openrouter.apiKey'). - Reads model preference from
generateCommitMessage.model.
- Retrieves OpenRouter API Key from
- Prompt Construction:
buildCommitPromptinjects Conventional Commits rules, diff text (safely truncated if large), and any optional custom instructions. - OpenRouter Completion: Sends request using native
fetchtohttps://openrouter.ai/api/v1/chat/completions. - Insertion: Cleans up response (stripping markdown code fences or quotes) and sets
repo.inputBox.value. - Telemetry: Dispatches non-blocking anonymous event to self-hosted Umami (model, duration, fallback/success/error status) if enabled in settings.
OpenRouter provides free models identified by the :free suffix or pricing set to 0.
Because free models rotate and providers can decommission or convert free slugs to paid at any time, the extension implements an Auto-Fallback & Persistent Cache Mechanism:
- Default Mode (
auto:free): Uses the last working free model saved incontext.globalStatefor instant generation without pre-querying the/modelsendpoint. On initial run or after a failure, queries live models and prioritizes known fast, reliable free models (POPULAR_FREE_MODELS). - Auto-Recovery & Persistence: If the cached or requested model responds with
unavailable for free,no endpoints found, or provider errors, the extension catches the error, fetches the live list of currently active free models, and retries with prioritized active free alternatives. Upon success, the working model is saved tocontext.globalState(openrouter.lastWorkingAutoModel) to be used directly on subsequent runs. - Live Selector: The model picker lists real-time active free models fetched live from OpenRouter and displays the currently active cached model for
Auto (Free). SelectingAuto (Free)manually resets the cache to force a fresh model discovery.
- Package Manager:
pnpm(Corepack managed). - Compile:
pnpm run compile(bundlessrc/extension.tsintodist/extension.jsviaesbuild). - Watch:
pnpm run watch. - Type Check:
pnpm run typecheck(tsc --noEmit). - Package:
pnpm run package(packages the extension into a.vsixfile using@vscode/vsce). - Release & Publish: Automated via GitHub Actions (
.github/workflows/release.yml) using Open VSX Trusted Publishing on tag push (git tag v* && git push origin v*) or manual workflow dispatch. - Debugging: Press
F5in VS Code / VSCodium to start an Extension Development Host window.
- Everything is must be written in english.