返回 DeepSeek-Reasonix
blocked_outcome.go
根目录 / internal / agent / blocked_outcome.go
1 package agent
2
3 import "reasonix/internal/tool"
4
5 // blockedToolOutcome shapes a tool's own refusal into the standard blocked
6 // outcome, with the not-run shell metadata a blocked bash card renders.
7 func (a *Agent) blockedToolOutcome(plan *toolCallPlan, msg string) toolOutcome {
8 out := toolOutcome{
9 output: msg,
10 blocked: true,
11 errMsg: firstLine(msg),
12 }
13 if tool.IsShellToolName(plan.evidenceName) || tool.IsShellToolName(plan.call.Name) {
14 out.execution = shellPreflightExecution(plan, plan.verification)
15 }
16 return out
17 }
18
19 // blockedShellOutcome fills host-only terminal metadata for an early policy
20 // refusal that was produced before blockedToolOutcome could shape it.
21 func blockedShellOutcome(out toolOutcome, plan *toolCallPlan) toolOutcome {
22 if out.execution == nil && plan != nil && (tool.IsShellToolName(plan.evidenceName) || tool.IsShellToolName(plan.call.Name)) {
23 out.execution = shellPreflightExecution(plan, plan.verification)
24 }
25 return out
26 }
27
28 // shellPreflightExecution builds not_run/preflight metadata for a blocked bash call.
29 func shellPreflightExecution(plan *toolCallPlan, hasVerification bool) *tool.ShellExecution {
30 ex := &tool.ShellExecution{
31 Kind: "shell",
32 State: tool.ShellStateNotRun,
33 FailurePhase: tool.ShellPhasePreflight,
34 MutationRisk: tool.ShellMutationNotStarted,
35 Verification: tool.ShellVerificationNotVerification,
36 }
37 if hasVerification {
38 ex.Verification = tool.ShellVerificationNotRun
39 }
40 if plan != nil {
41 if de, ok := plan.execTool.(tool.DetailedExecutor); ok {
42 if desc := de.ExecutionDescriptor(plan.execArgs); desc != nil {
43 ex.Shell = desc.Shell
44 ex.ShellVersion = desc.ShellVersion
45 ex.Platform = desc.Platform
46 ex.SupportsAndAnd = desc.SupportsAndAnd
47 }
48 }
49 }
50 return ex
51 }
52
52 lines GO