DevelopOther
@holtkeeper/commit-conventions
Works out how a repository names commits and branches, so agents and people write messages that fit. Rules come from four sources, strongest first:
commits.conventionssetting — what the team configured for a repository, group or everything.- Push rules of the forge (
GitForge.getPushRules, GitLab Premium): regular expressions for commit messages and new branch names. The forge rejects pushes that break them. - commitlint config on the default branch:
.commitlintrc*,commitlint.config.*or thecommitlintsection ofpackage.json. - History: the last commits of the default branch (
listCommits) and the work branches (listBranches).
import { checkCommitMessage, commitConventions, renderCommitConventions,} from '@holtkeeper/commit-conventions'
const conventions = await commitConventions({ forge, repo: 'group/app', setting, commits: 100 })renderCommitConventions(conventions) // Markdown for agentscheckCommitMessage(conventions.commit, 'feat(web): [ABC-1] add the board') // [] when it fitsPublic API
Section titled “Public API”commitConventions({ forge, repo, label?, setting?, commits? })→CommitConventions.forgeneeds onlygetRepositoryandreadFile. WithoutlistFiles,getPushRules,listCommitsorlistBranches, or when one of them fails, that source is skipped.commitsdefaults to 100.CommitConventionshascommitandbranch(Ruleset),notes?,history?(HistoryStats: share of Conventional Commits titles and ticket keys, type and scope counts, how many commits and branches were analyzed) andconsulted(the sources that were found).Ruleset<Rules>hasrules(CommitRulesorBranchRules),sources(theRuleSourceof every field),patterns(PatternRule: regexes the whole message or name must match, or must not match whennegative) andexamples.checkCommitMessage(ruleset, message)andcheckBranchName(ruleset, name)→Problem[]. A problem from ahistoryrule is awarning. Every other problem is anerror.rulenames the field it breaks (types,ticket,maxLength,prefixes, …) orpatternfor a forge push rule pattern.checkConventions(conventions, { message?, branch? })→ConventionsCheck[]: one{ target: 'message' | 'branch', problems, unchecked }per text given, message first;uncheckedis true when no rule or pattern at all is known for that kind of text, so an emptyproblemsthere means nothing was checked. A commit title git or the forge writes for a merge (isMergeTitle:Merge branch …,Merge remote-tracking branch …,Merge pull request …,Merge tag …,Merge … into …) meets only the explicit patterns, none of the derived rules. The MCP toolcheck_commit_messageandPOST /api/commit-conventions/checkboth use it, so they agree.renderCommitConventions(conventions)andrenderProblems([{ what, problems, unchecked? }])render Markdown for the MCP tools; anuncheckedtext reads “not checked” with a pointer to the team rules instead of “follows every known rule”.conventionalShape(ticket?, scoped = true): the Conventional Commits title shape (typewithout(scope)whenscopedis false; the rendered rule and the check passscopedonly when scopes are allowed or required) with the ticket key where a required ticket rule puts it ([KEY-1] type(scope): subjectforlead,type(scope): [KEY-1] subjectforbracket,type(KEY-1): subjectforscope, …;type(scope): subjectwithout one). The rendered Conventional Commits rule and theconventionalproblem use it, so they never contradict the ticket rule; with a ticket rule the branchcaserule and its problem add that ticket keys keep their case.bumpFor({ title, body? })→CommitBump(major,minor,patch): the semantic version bump one commit calls for. Breaking changes (type!:or aBREAKING CHANGE:footer) aremajor,featisminor, everything else ispatch; leading ticket keys ([ABC-1] feat:,ABC-1: feat:) are skipped. The release engine (@holtkeeper/release) derives the next version from it.ticketKeys(text)→ tracker keys such asABC-435in order (UTF-8-like keys are not tickets).commitConventionsSetting,commitConventionsKey(commits.conventions),commitConventionsSchema: the setting for the registry.
Combining sources
Section titled “Combining sources”- Fields. Each field of
CommitRulesandBranchRulescomes from the strongest source that sets it. Push rules set no fields: they only addpatterns. - Patterns. Patterns from the setting (
commit.pattern,commit.forbidden,branch.pattern) and from push rules all apply together. - Commit template. Unless the setting gives one, the template is rebuilt from the merged rules, for example
<type>(<scope>): [<TICKET>] <subject>. - Examples. The setting’s examples come first. Then come real titles and branch names, newest first, that pass every rule: up to 8 commit titles and 5 branch names.
- Turning history off. With
history: falsein the setting, commits and branches are not read at all.
Patterns are written in the forge’s dialect. A leading (?i) becomes the JavaScript i flag. A pattern JavaScript cannot compile is still shown to agents but is not checked.
What history establishes
Section titled “What history establishes”Merges, reverts, fixup!/squash!/amend! commits and WIP commits are left out. A history rule needs at least 10 analyzed commits, or 5 work branches (not the default branch and not protected ones). A style becomes a rule when at least 80% of them follow it:
- Commit titles.
conventional: titles have the formtype(scope)!: subject.scopeRequired: at least 80% of conventional titles have a scope.ticket: tracker keys such asABC-435. A key pattern is set once 30% of titles carry one, and it becomesrequiredat 80%. Keys of projects seen once are dropped when others repeat. The placement needs 60% agreement, otherwise it isanywhere. The placements arelead([ABC-1] feat: subject, where the title still counts as conventional),bracket(feat: [ABC-1] subject),prefix(feat: ABC-1 subject),scope(feat(ABC-1): subject) andsuffix(feat: subject (ABC-1)).maxLength: 72, or 100 if 72 does not fit, when 95% of titles fit.subjectCase: the first letter of the subject, ignoring leading acronyms likeAPI.noTrailingPeriod: at most 5% of titles end with a period.body:nonewhen at most 20% of commits have a body,requiredat 80%. Git trailers such asCo-Authored-By:do not count as a body.
- Types and scopes of commits are reported as counts only. A short history does not show every type that is allowed.
- Branches.
prefixes: names start with a prefix such asfeat/. Prefixes seen at least twice are kept.ticket: names carry a tracker key.case: the rest of the name iskebaborsnake.template: for example<prefix>/<TICKET>-<description>.
commitlint
Section titled “commitlint”The config is read as text, never run. This module recognizes:
extendsof@commitlint/config-conventional: conventional titles, its eleven types,maxLength100 and no trailing period;type-enum,scope-enum,scope-empty,header-max-length,subject-full-stopandbody-emptywritten as literals ([2, 'always', [...]], also YAML flow lists).
Level 0 disables a rule. Rules that are built in code are not seen.