| 1 | package tool |
| 2 | |
| 3 | import "context" |
| 4 | |
| 5 | // ConfigWriteRequest describes a file-tool write that targets a |
| 6 | // Reasonix-managed configuration file outside the workspace write roots. |
| 7 | type ConfigWriteRequest struct { |
| 8 | // Path is the resolved absolute target the tool wants to write. |
| 9 | Path string |
| 10 | } |
| 11 | |
| 12 | // ConfigWriteApprover asks the user whether one write to a Reasonix-managed |
| 13 | // config file may proceed. It is a fresh human decision: YOLO/auto approval |
| 14 | // must not answer it, and a nil approver (headless runs, sub-agent loops with |
| 15 | // no interactive parent) fails closed. |
| 16 | type ConfigWriteApprover interface { |
| 17 | ApproveManagedConfigWrite(ctx context.Context, req ConfigWriteRequest) (allow bool, reason string, err error) |
| 18 | } |
| 19 | |
| 20 | // ConfigWriteSessionChecker reports whether a managed-config write has already |
| 21 | // been approved for the current session without prompting the user again. |
| 22 | type ConfigWriteSessionChecker interface { |
| 23 | ManagedConfigWriteSessionAllowed(ctx context.Context, req ConfigWriteRequest) bool |
| 24 | } |
| 25 | |
| 26 | type configWriteApproverContextKey struct{} |
| 27 | |
| 28 | // WithConfigWriteApprover stamps an interactive managed-config write approver |
| 29 | // onto a tool execution context. |
| 30 | func WithConfigWriteApprover(ctx context.Context, approver ConfigWriteApprover) context.Context { |
| 31 | if approver == nil { |
| 32 | return ctx |
| 33 | } |
| 34 | return context.WithValue(ctx, configWriteApproverContextKey{}, approver) |
| 35 | } |
| 36 | |
| 37 | // ConfigWriteApproverFrom returns the managed-config write approver carried by |
| 38 | // ctx. |
| 39 | func ConfigWriteApproverFrom(ctx context.Context) (ConfigWriteApprover, bool) { |
| 40 | if ctx == nil { |
| 41 | return nil, false |
| 42 | } |
| 43 | approver, ok := ctx.Value(configWriteApproverContextKey{}).(ConfigWriteApprover) |
| 44 | return approver, ok && approver != nil |
| 45 | } |
| 46 |