| 1 | package tool |
| 2 | |
| 3 | import "errors" |
| 4 | |
| 5 | // BlockedError is a host refusal raised by a tool that enforces its own |
| 6 | // execution policy — the call never ran. The agent renders it as a blocked |
| 7 | // outcome (the shape permission and plan-mode blocks already produce) rather |
| 8 | // than an execution failure, so loop guards count it and frontends can tell a |
| 9 | // refusal apart from a completed call. |
| 10 | type BlockedError struct{ Message string } |
| 11 | |
| 12 | func (e *BlockedError) Error() string { return e.Message } |
| 13 | |
| 14 | // Blocked returns a host refusal carrying the model-facing message. |
| 15 | func Blocked(msg string) error { return &BlockedError{Message: msg} } |
| 16 | |
| 17 | // BlockedMessage reports whether err is a host refusal, and its message. |
| 18 | func BlockedMessage(err error) (string, bool) { |
| 19 | var blocked *BlockedError |
| 20 | if errors.As(err, &blocked) { |
| 21 | return blocked.Message, true |
| 22 | } |
| 23 | return "", false |
| 24 | } |
| 25 |