-
Notifications
You must be signed in to change notification settings - Fork 152
Expand file tree
/
Copy pathoutput.go
More file actions
64 lines (55 loc) · 1.64 KB
/
Copy pathoutput.go
File metadata and controls
64 lines (55 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package agenthook
import (
"strings"
"go.kenn.io/roborev/internal/autofix"
)
func PostToolUseAdditionalContext(reason string) string {
return resolvedInstruction(reason)
}
func StopReason(reason string) string {
return resolvedInstruction(reason)
}
func PostToolUseAdditionalContextWithFixGuidelines(reason, guidelines string) string {
return autofix.AppendGuidelines(PostToolUseAdditionalContext(reason), guidelines)
}
func StopReasonWithFixGuidelines(reason, guidelines string) string {
return autofix.AppendGuidelines(StopReason(reason), guidelines)
}
func BuildOutput(input Input, resp Response) map[string]any {
if !resp.Triggered {
return map[string]any{}
}
if input.HookEventName == "PostToolUse" {
return map[string]any{
"hookSpecificOutput": map[string]any{
"hookEventName": "PostToolUse",
"additionalContext": PostToolUseAdditionalContext(resp.Reason),
},
}
}
return map[string]any{"decision": "block", "reason": StopReason(resp.Reason)}
}
func BuildOutputWithFixGuidelines(input Input, resp Response, guidelines string) map[string]any {
if !resp.Triggered {
return BuildOutput(input, resp)
}
if input.HookEventName == "PostToolUse" {
return map[string]any{
"hookSpecificOutput": map[string]any{
"hookEventName": "PostToolUse",
"additionalContext": PostToolUseAdditionalContextWithFixGuidelines(resp.Reason, guidelines),
},
}
}
return map[string]any{
"decision": "block",
"reason": StopReasonWithFixGuidelines(resp.Reason, guidelines),
}
}
func resolvedInstruction(reason string) string {
reason = strings.TrimSpace(reason)
if reason == "" {
return DefaultInstruction
}
return reason
}