2025-07-21 10:12:28 -04:00
|
|
|
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":
|
2025-07-21 12:01:55 -04:00
|
|
|
if bashInput, err := input.GetBashInput(); err == nil {
|
2025-07-21 10:12:28 -04:00
|
|
|
slog.Info("bash command executed",
|
2025-07-21 12:01:55 -04:00
|
|
|
"command", bashInput.Command,
|
2025-07-21 10:12:28 -04:00
|
|
|
"session_id", input.SessionID,
|
|
|
|
|
"cwd", input.CWD,
|
|
|
|
|
"timestamp", time.Now().Unix())
|
|
|
|
|
}
|
2025-07-21 12:01:55 -04:00
|
|
|
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())
|
|
|
|
|
}
|
2025-07-21 10:12:28 -04:00
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
slog.Info("tool used",
|
|
|
|
|
"tool", input.Tool,
|
|
|
|
|
"session_id", input.SessionID,
|
|
|
|
|
"timestamp", time.Now().Unix())
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-21 11:26:50 -04:00
|
|
|
return hooks.HookOutput{Decision: "approve"}, nil
|
2025-07-21 12:01:55 -04:00
|
|
|
}
|