docs: update AGENTS and README to include guidelines for Conventional Commits

- Added a section on Conventional Commits in AGENTS.md, detailing the process for generating commit messages.
- Enhanced README.md with references to the Conventional Commits rules and the necessary scripts for generating commit messages.
- Clarified the format for commit messages, specifying the language requirements for headers and bodies.
This commit is contained in:
Denozordec
2026-05-20 00:48:21 +07:00
parent c263fd5c7e
commit 4c23232c4e
5 changed files with 430 additions and 0 deletions
+181
View File
@@ -0,0 +1,181 @@
#Requires -Version 5.1
<#
.SYNOPSIS
Staged git changes grouped by EvoBGP scope for Conventional Commit generation.
.DESCRIPTION
Outputs JSON to stdout: file groups, --stat, and truncated patch per group.
Exit 1 if nothing is staged. Does not write commit messages.
.EXAMPLE
powershell -NoProfile -File scripts/commit/staged-context.ps1
powershell -NoProfile -File scripts/commit/staged-context.ps1 | ConvertFrom-Json
#>
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
$MaxLinesPerGroup = 120
$MaxLinesTotal = 500
function Test-GitRepository {
$null = git rev-parse --git-dir 2>$null
if ($LASTEXITCODE -ne 0) {
Write-Error 'staged-context: not a git repository'
exit 2
}
}
function Get-ScopeForPath {
param([string]$Path)
$p = $Path -replace '\\', '/'
# Longest / most specific prefixes first
$rules = @(
@{ Prefix = 'docs/openapi.yaml'; Scope = 'openapi' }
@{ Prefix = 'redocly.yaml'; Scope = 'openapi' }
@{ Prefix = 'internal/httpapi/'; Scope = 'httpapi' }
@{ Prefix = 'internal/store/'; Scope = 'store' }
@{ Prefix = 'internal/repository/'; Scope = 'store' }
@{ Prefix = 'internal/db/'; Scope = 'store' }
@{ Prefix = 'internal/jobs/'; Scope = 'jobs' }
@{ Prefix = 'internal/pipeline/'; Scope = 'pipeline' }
@{ Prefix = 'internal/birdfmt/'; Scope = 'birdfmt' }
@{ Prefix = 'internal/birddeploy/'; Scope = 'birddeploy' }
@{ Prefix = 'internal/bundle/'; Scope = 'bundle' }
@{ Prefix = 'internal/signing/'; Scope = 'bundle' }
@{ Prefix = 'cmd/'; Scope = 'cmd' }
@{ Prefix = 'web/'; Scope = 'web' }
@{ Prefix = 'migrations/'; Scope = 'db' }
@{ Prefix = 'docs/'; Scope = 'docs' }
@{ Prefix = '.gitea/'; Scope = 'ci' }
@{ Prefix = 'deploy/'; Scope = 'deploy' }
@{ Prefix = '.cursor/'; Scope = 'chore' }
)
foreach ($rule in $rules) {
if ($p -eq $rule.Prefix.TrimEnd('/') -or $p.StartsWith($rule.Prefix)) {
return $rule.Scope
}
}
return 'chore'
}
function Get-ScopeSortOrder {
param([string]$Scope)
$order = @{
openapi = 10
httpapi = 20
store = 21
jobs = 22
pipeline = 30
birdfmt = 31
birddeploy = 32
bundle = 33
web = 40
ci = 50
deploy = 51
db = 52
docs = 60
cmd = 70
chore = 80
}
if ($order.ContainsKey($Scope)) { return $order[$Scope] }
return 99
}
function Invoke-Git {
param([string[]]$GitArgs)
$out = & git @GitArgs 2>&1
if ($LASTEXITCODE -ne 0) {
$msg = ($out | Out-String).Trim()
throw "git $($GitArgs -join ' ') failed: $msg"
}
return ($out | Out-String).TrimEnd()
}
function New-GitArgs {
param([string[]]$Base, [string[]]$Paths)
if ($Paths.Count -eq 0) { return $Base }
return $Base + '--' + $Paths
}
function Get-TruncatedDiff {
param(
[string[]]$Files,
[int]$MaxLines,
[ref]$TotalLinesUsed
)
if ($Files.Count -eq 0) { return '' }
$remaining = $MaxLinesTotal - $TotalLinesUsed.Value
if ($remaining -le 0) {
return '[diff truncated: global line budget exceeded]'
}
$cap = [Math]::Min($MaxLines, $remaining)
$diff = Invoke-Git -GitArgs (New-GitArgs -Base @(
'diff', '--cached', '--no-color', '--unified=3'
) -Paths $Files)
if ([string]::IsNullOrWhiteSpace($diff)) { return '' }
$lines = $diff -split "`n", -1
if ($lines.Count -le $cap) {
$TotalLinesUsed.Value += $lines.Count
return $diff
}
$truncated = ($lines[0..($cap - 1)] -join "`n") + "`n... [truncated: $($lines.Count - $cap) more lines]"
$TotalLinesUsed.Value += $cap
return $truncated
}
Test-GitRepository
$stagedRaw = Invoke-Git -GitArgs @('diff', '--cached', '--name-only')
if ([string]::IsNullOrWhiteSpace($stagedRaw)) {
[Console]::Error.WriteLine('staged-context: no staged changes (git index is empty)')
exit 1
}
$stagedFiles = @(
$stagedRaw -split "`n" | ForEach-Object { $_.Trim() } | Where-Object { $_ -ne '' }
)
$stagedFiles = $stagedFiles | Sort-Object -Unique
$scopeBuckets = @{}
foreach ($f in $stagedFiles) {
$scope = Get-ScopeForPath -Path $f
if (-not $scopeBuckets.ContainsKey($scope)) {
$scopeBuckets[$scope] = [System.Collections.Generic.List[string]]::new()
}
$scopeBuckets[$scope].Add($f) | Out-Null
}
$totalLinesUsed = 0
$groups = New-Object System.Collections.Generic.List[object]
$scopeKeys = @($scopeBuckets.Keys | Sort-Object { Get-ScopeSortOrder $_ })
foreach ($scope in $scopeKeys) {
$files = @($scopeBuckets[$scope] | Sort-Object)
$stat = Invoke-Git -GitArgs (New-GitArgs -Base @('diff', '--cached', '--stat') -Paths $files)
$diffExcerpt = Get-TruncatedDiff -Files $files -MaxLines $MaxLinesPerGroup -TotalLinesUsed ([ref]$totalLinesUsed)
$groups.Add([ordered]@{
scope = $scope
files = $files
stat = $stat
diff_excerpt = $diffExcerpt
}) | Out-Null
}
$result = [ordered]@{
staged_count = $stagedFiles.Count
groups = $groups.ToArray()
}
$json = $result | ConvertTo-Json -Depth 6 -Compress:$false
# UTF-8 stdout for agents / ConvertFrom-Json
[Console]::OutputEncoding = [System.Text.UTF8Encoding]::new($false)
Write-Output $json
exit 0