返回 DeepSeek-Reasonix
context.go
根目录 / internal / runtimepolicy / context.go
1 package runtimepolicy
2
3 import (
4 "context"
5 )
6
7 type contextKey struct{}
8
9 // InheritedExecutionContext is what a child agent may inherit from its parent.
10 // It is host-only and never enters a provider schema.
11 type InheritedExecutionContext struct {
12 Constraints Constraints
13 PlanReadOnly bool
14 GoalScopeID string
15 }
16
17 // WithContext stores host execution constraints for the turn.
18 func WithContext(ctx context.Context, constraints Constraints) context.Context {
19 if ctx == nil {
20 ctx = context.Background()
21 }
22 return context.WithValue(ctx, contextKey{}, constraints)
23 }
24
25 // FromContext returns host constraints when the controller published them.
26 func FromContext(ctx context.Context) (Constraints, bool) {
27 if ctx == nil {
28 return Constraints{}, false
29 }
30 c, ok := ctx.Value(contextKey{}).(Constraints)
31 return c, ok
32 }
33
34 type inheritKey struct{}
35
36 // WithInherited stores the parent execution context for a writer child.
37 func WithInherited(ctx context.Context, in InheritedExecutionContext) context.Context {
38 if ctx == nil {
39 ctx = context.Background()
40 }
41 return context.WithValue(ctx, inheritKey{}, in)
42 }
43
44 // InheritedFromContext returns the parent execution context, if any.
45 func InheritedFromContext(ctx context.Context) (InheritedExecutionContext, bool) {
46 if ctx == nil {
47 return InheritedExecutionContext{}, false
48 }
49 in, ok := ctx.Value(inheritKey{}).(InheritedExecutionContext)
50 return in, ok
51 }
52
52 lines GO