# Git Workflow Implementation Summary
## Overview
Comprehensive git workflow and commit standards have been implemented for Amicus MCP, including Conventional Commits enforcement, automated validation, and git hooks.
## What Was Implemented
### 1. Git Workflow Documentation
**File:** `docs/GIT_WORKFLOW.md` (new, 800+ lines)
Complete git workflow guide including:
**Commit Standards:**
- Conventional Commits format specification
- Commit types and scopes
- Description guidelines (imperative mood, lowercase, no period, max 72 chars)
- Body and footer formatting
- Good vs bad examples
**Branch Strategy:**
- Branch naming conventions (`type/description`)
- Main branch protection
- Feature branch workflow
- Hotfix workflow
- Merge strategies (squash vs regular)
**Pull Request Guidelines:**
- PR title format
- PR description template
- PR size guidelines (< 100 lines ideal)
- Review process
- Merge procedures
**Advanced Topics:**
- Rewriting history (when and how)
- Interactive rebase
- Commit message templates
- Git aliases
- Common workflows
### 2. Commit Validation Script
**File:** `scripts/validate_commits.sh` (new, 200+ lines)
Automated commit message validation:
**Features:**
- Validates Conventional Commits format
- Checks commit types against whitelist
- Validates subject length (max 72 chars)
- Checks description style (lowercase, imperative)
- Detects trailing periods
- Identifies non-imperative mood
- Detects breaking changes
- Supports single commits or ranges
**Usage:**
```bash
# Validate HEAD
./scripts/validate_commits.sh
# Validate specific commit
./scripts/validate_commits.sh abc123f
# Validate commit range
./scripts/validate_commits.sh main..HEAD
```
**Output:**
```
=======================================================================
COMMIT MESSAGE VALIDATION
=======================================================================
Validating: HEAD
Message: feat(mcp): add assess_workload tool
✓ Format is valid
✓ Subject length OK (39/72)
✓ Description starts with lowercase
✓ Description has no trailing period
✓ Imperative mood
✓✓✓ COMMIT MESSAGE VALID ✓✓✓
```
### 3. Git Hooks Installer
**File:** `scripts/install_hooks.sh` (new, 250+ lines)
Installs three git hooks:
#### commit-msg Hook
- Validates commit message format
- Enforces Conventional Commits
- Checks subject length
- Rejects invalid messages
- Allows merge/revert commits
#### pre-commit Hook
- Checks Python syntax in staged files
- Warns about large files (> 1MB)
- Detects debug statements (console.log, debugger, pdb)
- Validates version consistency
- Provides interactive prompts
#### prepare-commit-msg Hook
- Provides commit message template
- Shows examples and guidelines
- Only for new commits (not amend/merge)
**Usage:**
```bash
./scripts/install_hooks.sh
```
**Bypass (emergency only):**
```bash
git commit --no-verify
```
### 4. Commit Message Template
**File:** `.gitmessage` (new)
Git commit template with:
- Format structure
- Type and scope examples
- Rules and guidelines
- Breaking change format
- Issue reference format
**Usage:**
```bash
# Configure globally
git config --global commit.template .gitmessage
# Or per-repository
git config commit.template .gitmessage
# Use it
git commit
# Opens editor with template
```
### 5. Governance Integration
**File:** `GOVERNANCE.md` (extended)
Added Git Workflow section:
- Commit message format
- Commit guidelines
- Validation procedures
- Branch strategy
- Pull request requirements
- Link to complete documentation
## Commit Types
### Primary Types
- **feat**: New feature
- **fix**: Bug fix
- **docs**: Documentation only
- **style**: Code style (formatting, whitespace)
- **refactor**: Code change (no bug fix, no feature)
- **perf**: Performance improvement
- **test**: Adding or updating tests
- **build**: Build system or dependencies
- **ci**: CI/CD configuration
- **chore**: Maintenance tasks
- **revert**: Revert previous commit
### Scopes
- **mcp**: MCP tools (update_state, register_node, etc.)
- **cluster**: Cluster management (anti-idle, workload)
- **config**: Configuration system
- **monitor**: HeartbeatMonitor
- **security**: Security scanner
- **cli**: Command-line interface
- **docs**: Documentation
- **validation**: Validation scripts
- **prompts**: Prompt files
## Usage Examples
### Example 1: Feature Commit
```bash
git add src/amicus/server.py
git commit -m "feat(mcp): add assess_workload tool
Implements workload assessment that analyzes pending tasks,
active nodes, and idle nodes to generate spawn/terminate
recommendations for the Bootstrap Manager.
Closes #42"
```
### Example 2: Bug Fix
```bash
git add src/amicus/monitor.py
git commit -m "fix(monitor): resolve race condition in heartbeat cleanup
The HeartbeatMonitor was checking node status without proper
locking, causing occasional crashes when nodes terminated
during health checks. Added file locking to _check_health().
Fixes #38"
```
### Example 3: Breaking Change
```bash
git commit -m "feat(mcp)!: change update_state to require task objects
BREAKING CHANGE: next_steps parameter now requires List[Dict]
instead of List[str]. All task strings must be converted to
task objects with status field.
Migration:
- Before: next_steps=[\"task 1\", \"task 2\"]
- After: next_steps=[{\"task\": \"task 1\", \"status\": \"pending\"}]
Closes #45"
```
### Example 4: Documentation
```bash
git commit -m "docs: add semantic versioning procedures to governance"
```
### Example 5: Chore
```bash
git commit -m "chore: bump version to 0.4.1"
```
## Validation Workflow
### Before Committing
```bash
# 1. Stage changes
git add file.py
# 2. Check what's staged
git diff --staged
# 3. Commit (hooks validate automatically)
git commit -m "feat(scope): description"
# 4. If rejected, fix and retry
git commit --amend
```
### After Committing
```bash
# Validate recent commits
./scripts/validate_commits.sh HEAD
./scripts/validate_commits.sh HEAD~5..HEAD
# Check commit history
git log --oneline --graph
```
## Branch Workflow
### Feature Development
```bash
# 1. Create feature branch
git checkout -b feature/workload-assessment
# 2. Develop with atomic commits
git commit -m "feat(cluster): add workload assessment skeleton"
git commit -m "feat(cluster): implement workload calculation"
git commit -m "test(cluster): add workload assessment tests"
git commit -m "docs(cluster): document workload assessment"
# 3. Push to remote
git push origin feature/workload-assessment
# 4. Create PR
# (via GitHub interface)
# 5. Squash merge to main
# (via GitHub PR merge button)
```
### Bug Fix
```bash
# 1. Create fix branch
git checkout -b fix/heartbeat-race-condition
# 2. Fix and commit
git commit -m "fix(monitor): resolve race condition in heartbeat cleanup"
# 3. Push and create PR
git push origin fix/heartbeat-race-condition
```
## Git Hooks Installation
### Install Hooks
```bash
./scripts/install_hooks.sh
```
**Output:**
```
=======================================================================
INSTALLING GIT HOOKS
=======================================================================
Installing commit-msg hook...
✓ Installed commit-msg hook
Installing pre-commit hook...
✓ Installed pre-commit hook
Installing prepare-commit-msg hook...
✓ Installed prepare-commit-msg hook
=======================================================================
✓✓✓ GIT HOOKS INSTALLED ✓✓✓
=======================================================================
Installed hooks:
- commit-msg: Validates commit message format
- pre-commit: Checks syntax, file sizes, common issues
- prepare-commit-msg: Provides commit message template
```
### Test Hooks
```bash
# Will be validated automatically
git commit -m "invalid message format"
# Rejected by commit-msg hook
git commit -m "feat(mcp): add new tool"
# Accepted
```
## Common Scenarios
### Scenario 1: Fix Commit Message
```bash
# Bad commit message
git commit -m "added new feature"
# ✗ Rejected: "added" is not imperative
# Fix it
git commit -m "feat(mcp): add workload assessment tool"
# ✓ Accepted
```
### Scenario 2: Amend Last Commit
```bash
# Forgot to add a file
git add forgotten_file.py
git commit --amend --no-edit
```
### Scenario 3: Multiple Commits
```bash
# Atomic commits for related changes
git add server.py
git commit -m "feat(mcp): add tool signature"
git add server.py
git commit -m "feat(mcp): implement tool logic"
git add tests/
git commit -m "test(mcp): add tool tests"
git add docs/
git commit -m "docs: document new tool"
```
### Scenario 4: Interactive Rebase
```bash
# Squash last 3 commits
git rebase -i HEAD~3
# In editor:
pick abc123 feat: add signature
squash def456 feat: add logic
squash ghi789 test: add tests
# Result: Single commit with combined message
```
## Integration Points
### Pre-Commit Hook Integration
Hooks run automatically on commit:
```bash
git commit -m "feat: add new tool"
# Automatic checks:
✓ Commit message format
✓ Python syntax
✓ File sizes
✓ Debug statements
✓ Version consistency
```
### CI/CD Integration (Future)
GitHub Actions should validate commits:
```yaml
- name: Validate commit messages
run: ./scripts/validate_commits.sh ${{ github.event.pull_request.base.sha }}..${{ github.sha }}
```
### IDE Integration
Configure IDE to use commit template:
```bash
# In IDE settings, set commit template to:
.gitmessage
```
## Statistics
**Lines of Code Added:**
- docs/GIT_WORKFLOW.md: ~800 lines
- scripts/validate_commits.sh: ~200 lines
- scripts/install_hooks.sh: ~250 lines
- .gitmessage: ~30 lines
- GOVERNANCE.md git section: ~50 lines
**Total: ~1,330 lines of git workflow infrastructure**
## Benefits
1. **Consistent Commit History** - All commits follow same format
2. **Automated Validation** - Hooks prevent bad commits
3. **Better Changelog Generation** - Conventional commits enable automation
4. **Clearer History** - Commit types make intent obvious
5. **Easier Debugging** - Atomic commits simplify bisecting
6. **Professional Standards** - Industry-standard practices
7. **Team Alignment** - Everyone follows same conventions
## Validation Results
Current commit validation status:
```bash
./scripts/validate_commits.sh HEAD
=======================================================================
COMMIT MESSAGE VALIDATION
=======================================================================
Validating: HEAD
Message: chore: minor updates and fixes within v0.4.0 development
✓ Format is valid
✓ Subject length OK (56/72)
✓ Description has no trailing period
✓ Imperative mood
✓✓✓ COMMIT MESSAGE VALID ✓✓✓
```
## Next Steps
1. **Install hooks** for all contributors
```bash
./scripts/install_hooks.sh
```
2. **Configure commit template** globally
```bash
git config --global commit.template .gitmessage
```
3. **Train team** on Conventional Commits format
4. **Set up CI/CD** to validate commits in PRs
5. **Enable commit validation** in GitHub Actions
6. **Create changelog automation** using conventional commits
## Resources
- [Conventional Commits](https://www.conventionalcommits.org/)
- [docs/GIT_WORKFLOW.md](docs/GIT_WORKFLOW.md) - Complete guide
- [GOVERNANCE.md](GOVERNANCE.md) - Git workflow section
- [Keep a Changelog](https://keepachangelog.com/)
---
**Status:** ✅ IMPLEMENTED AND TESTED
Git workflow and commit standards are now fully implemented. Install hooks with `./scripts/install_hooks.sh`.