mirror of
https://github.com/imjasonh/cnotes
synced 2026-07-12 10:51:20 +00:00
- 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>
44 lines
1.1 KiB
Go
44 lines
1.1 KiB
Go
package handlers
|
|
|
|
import (
|
|
"context"
|
|
"log/slog"
|
|
"time"
|
|
|
|
"github.com/imjasonh/hooks/internal/hooks"
|
|
)
|
|
|
|
func LogToolUsage(ctx context.Context, input hooks.HookInput) (hooks.HookOutput, error) {
|
|
switch input.Tool {
|
|
case "Bash":
|
|
if bashInput, err := input.GetBashInput(); err == nil {
|
|
slog.Info("bash command executed",
|
|
"command", bashInput.Command,
|
|
"session_id", input.SessionID,
|
|
"cwd", input.CWD,
|
|
"timestamp", time.Now().Unix())
|
|
}
|
|
case "Write", "Edit", "MultiEdit", "Read":
|
|
if fileInput, err := input.GetFileInput(); err == nil {
|
|
if input.Tool == "Read" {
|
|
slog.Info("file read",
|
|
"file", fileInput.FilePath,
|
|
"session_id", input.SessionID,
|
|
"timestamp", time.Now().Unix())
|
|
} else {
|
|
slog.Info("file modified",
|
|
"tool", input.Tool,
|
|
"file", fileInput.FilePath,
|
|
"session_id", input.SessionID,
|
|
"timestamp", time.Now().Unix())
|
|
}
|
|
}
|
|
default:
|
|
slog.Info("tool used",
|
|
"tool", input.Tool,
|
|
"session_id", input.SessionID,
|
|
"timestamp", time.Now().Unix())
|
|
}
|
|
|
|
return hooks.HookOutput{Decision: "approve"}, nil
|
|
}
|