-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpolicy.go
More file actions
66 lines (54 loc) · 2.1 KB
/
Copy pathpolicy.go
File metadata and controls
66 lines (54 loc) · 2.1 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
65
66
package agenthooks
import "time"
// FailMode governs what a handler error, panic, or timeout means.
type FailMode int
const (
FailOpen FailMode = iota // handler error/timeout -> NoDecision
FailClosed // handler error/timeout -> Deny (where possible)
)
// DegradeMode governs unsupported decisions (e.g. Ask on Codex).
type DegradeMode int
const (
// Degrade maps to the nearest supported intent (Ask->Deny or
// Ask->NoDecision per AskFallback) and logs the downgrade.
Degrade DegradeMode = iota
// Strict treats an unsupported decision as a handler error, which then
// follows Policy.Fail.
Strict
)
// AskFallback selects the degradation target when Ask is unsupported.
type AskFallback int
const (
FallbackNoDecision AskFallback = iota
FallbackDeny
)
// DefaultContinuationCap bounds ContinueWith loops on providers without a
// native cap (Cursor Claude-compat mode ships loop_limit: null).
const DefaultContinuationCap = 5
// defaultDeadline is used when no --timeout flag was baked into the
// generated config: slightly under the common 60s provider default so the
// runner always answers rather than getting killed mid-write.
const defaultDeadline = 55 * time.Second
// Policy declares how the runner behaves when a handler fails or asks for
// something the provider can't do. FailClosed is enforced with the provider's
// real mechanism per event; on events with no blocking mechanism it
// downgrades to logging (see Can(CapDeny)).
type Policy struct {
Fail FailMode
Unsupported DegradeMode
AskFallback AskFallback
// ContinuationCap caps ContinueWith loops; 0 means DefaultContinuationCap.
ContinuationCap int
// Timeout bounds handler execution. 0 derives a deadline from the
// --timeout flag in the generated config (90% of it) or defaultDeadline.
Timeout time.Duration
}
func (p Policy) continuationCap() int {
if p.ContinuationCap > 0 {
return p.ContinuationCap
}
return DefaultContinuationCap
}
// PolicyFunc resolves policy per event, enabling consumer patterns like a
// ratchet (fail-open until first success, then fail-closed).
type PolicyFunc func(*Event) Policy