feat: add hooks functionality with automated workflows

- Introduced hooks to enable automated workflows triggered by specific events during GitHub Copilot sessions.
- Added documentation for hooks in AGENTS.md and README.md.
- Created a new directory structure for hooks, including README.md and hooks.json files.
- Implemented two example hooks: Session Auto-Commit and Session Logger.
- Developed scripts for logging session events and auto-committing changes.
- Enhanced validation and parsing for hook metadata.
- Updated build and validation scripts to accommodate new hooks functionality.
This commit is contained in:
Aaron Powell
2026-02-09 16:44:53 +11:00
parent d99ba71986
commit acb5ad4ce8
17 changed files with 783 additions and 66 deletions

View File

@@ -0,0 +1,90 @@
---
name: 'Session Auto-Commit'
description: 'Automatically commits and pushes changes when a Copilot coding agent session ends'
tags: ['automation', 'git', 'productivity']
---
# Session Auto-Commit Hook
Automatically commits and pushes changes when a GitHub Copilot coding agent session ends, ensuring your work is always saved and backed up.
## Overview
This hook runs at the end of each Copilot coding agent session and automatically:
- Detects if there are uncommitted changes
- Stages all changes
- Creates a timestamped commit
- Pushes to the remote repository
## Features
- **Automatic Backup**: Never lose work from a Copilot session
- **Timestamped Commits**: Each auto-commit includes the session end time
- **Safe Execution**: Only commits when there are actual changes
- **Error Handling**: Gracefully handles push failures
## Installation
1. Copy this hook folder to your repository's `.github/hooks/` directory:
```bash
cp -r hooks/session-auto-commit .github/hooks/
```
2. Ensure the script is executable:
```bash
chmod +x .github/hooks/session-auto-commit/auto-commit.sh
```
3. Commit the hook configuration to your repository's default branch
## Configuration
The hook is configured in `hooks.json` to run on the `sessionEnd` event:
```json
{
"version": 1,
"hooks": {
"sessionEnd": [
{
"type": "command",
"bash": ".github/hooks/session-auto-commit/auto-commit.sh",
"timeoutSec": 30
}
]
}
}
```
## How It Works
1. When a Copilot coding agent session ends, the hook executes
2. Checks if inside a Git repository
3. Detects uncommitted changes using `git status`
4. Stages all changes with `git add -A`
5. Creates a commit with format: `auto-commit: YYYY-MM-DD HH:MM:SS`
6. Attempts to push to remote
7. Reports success or failure
## Customization
You can customize the hook by modifying `auto-commit.sh`:
- **Commit Message Format**: Change the timestamp format or message prefix
- **Selective Staging**: Use specific git add patterns instead of `-A`
- **Branch Selection**: Push to specific branches only
- **Notifications**: Add desktop notifications or Slack messages
## Disabling
To temporarily disable auto-commits:
1. Remove or comment out the `sessionEnd` hook in `hooks.json`
2. Or set an environment variable: `export SKIP_AUTO_COMMIT=true`
## Notes
- The hook uses `--no-verify` to avoid triggering pre-commit hooks
- Failed pushes won't block session termination
- Requires appropriate git credentials configured
- Works with both Copilot coding agent and GitHub Copilot CLI

View File

@@ -0,0 +1,45 @@
#!/bin/bash
# Session Auto-Commit Hook
# Automatically commits and pushes changes when a Copilot session ends
set -euo pipefail
# Check if SKIP_AUTO_COMMIT is set
if [[ "${SKIP_AUTO_COMMIT:-}" == "true" ]]; then
echo "⏭️ Auto-commit skipped (SKIP_AUTO_COMMIT=true)"
exit 0
fi
# Check if we're in a git repository
if ! git rev-parse --is-inside-work-tree &>/dev/null; then
echo "⚠️ Not in a git repository"
exit 0
fi
# Check for uncommitted changes
if [[ -z "$(git status --porcelain)" ]]; then
echo "✨ No changes to commit"
exit 0
fi
echo "📦 Auto-committing changes from Copilot session..."
# Stage all changes
git add -A
# Create timestamped commit
TIMESTAMP=$(date '+%Y-%m-%d %H:%M:%S')
git commit -m "auto-commit: $TIMESTAMP" --no-verify 2>/dev/null || {
echo "⚠️ Commit failed"
exit 0
}
# Attempt to push
if git push 2>/dev/null; then
echo "✅ Changes committed and pushed successfully"
else
echo "⚠️ Push failed - changes committed locally"
fi
exit 0

View File

@@ -0,0 +1,12 @@
{
"version": 1,
"hooks": {
"sessionEnd": [
{
"type": "command",
"bash": ".github/hooks/session-auto-commit/auto-commit.sh",
"timeoutSec": 30
}
]
}
}