1
0
Fork 0
mirror of https://github.com/imjasonh/cnotes synced 2026-07-13 11:19:43 +00:00
cnotes/internal/handlers/notification.go
Jason Hall 45ef980233
Scaffold all 7 hook events and eliminate type casting
- Add missing hook handlers: Stop, SubagentStop, PreCompact
- Replace all string type casting with proper JSON unmarshaling
- Change ToolUseRequest.Parameters from map[string]interface{} to json.RawMessage
- Update helper methods to use json.Unmarshal directly to typed structs
- Replace speech notifications with simple logging notifications
- Update documentation to reflect all hook events and remove speech references
- Add comprehensive CLAUDE.md with architecture overview and development guidance

All hooks now use type-safe JSON handling without .(string) assertions.
Complete coverage of Claude Code events: PreToolUse, PostToolUse,
UserPromptSubmit, Notification, Stop, SubagentStop, PreCompact.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-21 12:01:55 -04:00

55 lines
1.6 KiB
Go

package handlers
import (
"context"
"log/slog"
"time"
"github.com/imjasonh/hooks/internal/hooks"
)
func init() {
hooks.RegisterHook(hooks.EventNotification, "*", LogNotification)
}
// LogNotification logs notification events for debugging and monitoring.
// This hook is triggered when Claude needs permission to use a tool or when
// prompt input has been idle for 60+ seconds.
//
// Common use cases:
// - Debug notification flow
// - Monitor permission requests
// - Track user idle states
// - Audit notification patterns
func LogNotification(ctx context.Context, input hooks.HookInput) (hooks.HookOutput, error) {
var message string
var notificationType string
// Check if we have the direct message format (newer)
if input.Message != "" {
message = input.Message
notificationType = "direct"
} else if input.Notification.Permission != "" {
// Permission request (older format)
message = input.Notification.Message
notificationType = "permission"
} else if input.Notification.Message != "" {
// Regular notification (older format)
message = input.Notification.Message
notificationType = "message"
} else {
// No valid notification content
slog.Debug("notification hook triggered with no message content", "session_id", input.SessionID)
return hooks.HookOutput{Decision: "approve"}, nil
}
slog.Info("notification received",
"type", notificationType,
"message", message,
"tool", input.Notification.Tool,
"permission", input.Notification.Permission != "",
"session_id", input.SessionID,
"timestamp", time.Now().Unix())
return hooks.HookOutput{Decision: "approve"}, nil
}