Add config-based close hooks (bd-g4b4)

Implements on_close hooks in .beads/config.yaml for automation and
notifications. Hooks receive issue data via environment variables
(BEAD_ID, BEAD_TITLE, BEAD_TYPE, BEAD_PRIORITY, BEAD_CLOSE_REASON)
and run via sh -c.

Changes:
- internal/config: Add HookEntry type and GetCloseHooks()
- internal/hooks: Add RunConfigCloseHooks() for executing config hooks
- cmd/bd: Call RunConfigCloseHooks after successful close
- docs/CONFIG.md: Document hooks configuration with examples

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Steve Yegge
2025-12-23 13:38:09 -08:00
parent bc0973bfa2
commit c46b1a0bbb
5 changed files with 449 additions and 2 deletions

View File

@@ -306,6 +306,43 @@ func ResolveExternalProjectPath(projectName string) string {
return path
}
// HookEntry represents a single config-based hook
type HookEntry struct {
Command string `yaml:"command" mapstructure:"command"` // Shell command to run
Name string `yaml:"name" mapstructure:"name"` // Optional display name
}
// GetCloseHooks returns the on_close hooks from config
func GetCloseHooks() []HookEntry {
if v == nil {
return nil
}
var hooks []HookEntry
raw := v.Get("hooks.on_close")
if raw == nil {
return nil
}
// Handle slice of maps (from YAML parsing)
if rawSlice, ok := raw.([]interface{}); ok {
for _, item := range rawSlice {
if m, ok := item.(map[string]interface{}); ok {
entry := HookEntry{}
if cmd, ok := m["command"].(string); ok {
entry.Command = cmd
}
if name, ok := m["name"].(string); ok {
entry.Name = name
}
if entry.Command != "" {
hooks = append(hooks, entry)
}
}
}
}
return hooks
}
// GetIdentity resolves the user's identity for messaging.
// Priority chain:
// 1. flagValue (if non-empty, from --identity flag)