返回 DeepSeek-Reasonix
planned_mutation_policy.go
根目录 / internal / agent / planned_mutation_policy.go
1 package agent
2
3 import (
4 "strings"
5
6 "reasonix/internal/runtimepolicy"
7 )
8
9 // applyExecutionPreflight classifies the resolved call and applies the
10 // remaining runtime policy before the ordinary permission decision.
11 func (a *Agent) applyExecutionPreflight(_ *turnRuntime, plan *toolCallPlan) (toolOutcome, bool) {
12 plan.classifyEffects()
13 decision := a.pipelineDecision(plan)
14 switch decision.Action {
15 case runtimepolicy.GuardDeny:
16 return policyBlock(decision.Message, firstLine(decision.Message))
17 case runtimepolicy.GuardAsk:
18 if !a.hasInteractiveAsk() {
19 return policyBlock(decision.Message, firstLine(decision.Message))
20 }
21 // Permission/Ask still owns the interactive prompt; do not wait here.
22 }
23 return toolOutcome{}, false
24 }
25
26 func policyBlock(output, reason string) (toolOutcome, bool) {
27 output = strings.TrimSpace(output)
28 reason = strings.TrimSpace(reason)
29 if output == "" {
30 output = reason
31 }
32 if !strings.HasPrefix(output, "blocked:") {
33 output = "blocked: " + output
34 }
35 if reason == "" {
36 reason = output
37 }
38 if !strings.HasPrefix(reason, "blocked:") {
39 reason = "blocked: " + reason
40 }
41 return toolOutcome{output: output, blocked: true, errMsg: firstLine(reason)}, true
42 }
43
43 lines GO