@@ -15,85 +15,6 @@ import (
1515 "github.com/flexigpt/llmtools-go/spec"
1616)
1717
18- // ExecutionPolicy provides policy / hardening knobs (host-configured).
19- // All limits are clamped to executil hard maximums (downstream enforcement).
20- type ExecutionPolicy struct {
21- // If true, skip heuristic checks (fork-bomb/backgrounding).
22- // NOTE: hard-blocked commands are ALWAYS blocked.
23- AllowDangerous bool
24-
25- Timeout time.Duration
26- MaxOutputBytes int64
27- MaxCommands int
28- MaxCommandLength int
29- }
30-
31- // Clone returns an independent copy of the ExecutionPolicy.
32- // (All fields are value types, so a plain copy is sufficient.)
33- func (p * ExecutionPolicy ) Clone () * ExecutionPolicy {
34- if p == nil {
35- return nil
36- }
37- cp := new (ExecutionPolicy )
38- * cp = * p
39- return cp
40- }
41-
42- func DefaultExecutionPolicy () ExecutionPolicy {
43- return ExecutionPolicy {
44- AllowDangerous : false ,
45- Timeout : executil .DefaultTimeout ,
46- MaxOutputBytes : executil .DefaultMaxOutputBytes ,
47- MaxCommands : executil .DefaultMaxCommands ,
48- MaxCommandLength : executil .DefaultMaxCommandLength ,
49- }
50- }
51-
52- type execToolConfig struct {
53- allowedRoots []string
54- workBaseDir string
55- blockSymlinks bool
56- blockedCommands map [string ]struct {}
57-
58- executionPolicy ExecutionPolicy
59- runScriptPolicy RunScriptPolicy
60- }
61-
62- type execToolPolicy struct {
63- fsPolicy fspolicy.FSPolicy
64- blockedCommands map [string ]struct {}
65-
66- executionPolicy ExecutionPolicy
67- runScriptPolicy RunScriptPolicy
68- }
69-
70- // Clone returns an independent copy of the policy snapshot.
71- func (p * execToolPolicy ) Clone () * execToolPolicy {
72- if p == nil {
73- return nil
74- }
75-
76- cp := new (execToolPolicy )
77- * cp = * p // copy all value fields (and slice/map headers)
78-
79- if p .blockedCommands != nil {
80- cp .blockedCommands = make (map [string ]struct {}, len (p .blockedCommands ))
81- maps .Copy (cp .blockedCommands , p .blockedCommands )
82- } else {
83- cp .blockedCommands = nil
84- }
85-
86- if c := p .executionPolicy .Clone (); c != nil {
87- cp .executionPolicy = * c
88- }
89-
90- if c := p .runScriptPolicy .Clone (); c != nil {
91- cp .runScriptPolicy = * c
92- }
93-
94- return cp
95- }
96-
9718// ExecTool is an instance-owned execution tool runner.
9819// It centralizes:
9920// - path sandboxing (workBaseDir, allowedRoots, blockSymlinks)
@@ -273,3 +194,13 @@ func (et *ExecTool) snapshotPolicy() *execToolPolicy {
273194 }
274195 return p .Clone ()
275196}
197+
198+ func DefaultExecutionPolicy () ExecutionPolicy {
199+ return ExecutionPolicy {
200+ AllowDangerous : false ,
201+ Timeout : executil .DefaultTimeout ,
202+ MaxOutputBytes : executil .DefaultMaxOutputBytes ,
203+ MaxCommands : executil .DefaultMaxCommands ,
204+ MaxCommandLength : executil .DefaultMaxCommandLength ,
205+ }
206+ }
0 commit comments